8000 Cheap and nasty BINARY_ADD, fix LOAD_GLOBAL and vm.call() · go-python/gpython@21cd9f2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 21cd9f2

Browse files
committed
Cheap and nasty BINARY_ADD, fix LOAD_GLOBAL and vm.call()
1 parent 51c26cc commit 21cd9f2

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

vm/eval.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ func do_BINARY_MODULO(vm *Vm, arg int32) {
141141

142142
// Implements TOS = TOS1 + TOS.
143143
func do_BINARY_ADD(vm *Vm, arg int32) {
144+
// FIXME not a very good implementation ;-)
145+
b := vm.POP().(py.Int64)
146+
a := vm.POP().(py.Int64)
147+
c := a + b
148+
vm.PUSH(py.Int64(c))
144149
vm.NotImplemented("BINARY_ADD", arg)
145150
}
146151

@@ -533,8 +538,8 @@ func do_FOR_ITER(vm *Vm, delta int32) {
533538

534539
// Loads the global named co_names[namei] onto the stack.
535540
func do_LOAD_GLOBAL(vm *Vm, namei int32) {
536-
// FIXME what if global doesn't exist?
537-
vm.PUSH(vm.globals[vm.co.Names[namei]])
541+
// FIXME this is looking in local scope too - is that correct?
542+
vm.PUSH(vm.lookup(vm.co.Names[namei]))
538543
}
539544

540545
// Pushes a block for a loop onto the block stack. The block spans

vm/lookup.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,17 @@ func (vm *Vm) lookupMethod(name string) py.Callable {
5050

5151
// Calls function fn with args and kwargs
5252
//
53+
// fn can be a string in which case it will be looked up or something
54+
// which satisfies the py.Callable interface
55+
//
5356
// kwargs is a sequence of name, value pairs
5457
func (vm *Vm) call(fn py.Object, args []py.Object, kwargs []py.Object) py.Object {
5558
fmt.Printf("Call %v with args = %v, kwargs = %v\n", fn, args, kwargs)
56-
fn_name := string(fn.(py.String))
57-
method := vm.lookupMethod(fn_name)
59+
method, ok := fn.(py.Callable)
60+
if !ok {
61+
fn_name := string(fn.(py.String))
62+
method = vm.lookupMethod(fn_name)
63+
}
5864
self := py.None // FIXME should be the module
5965
if len(kwargs) > 0 {
6066
// Convert kwargs into dictionary

0 commit comments

Comments
 (0)
0