functions now capture variables :D
This commit is contained in:
parent
43e450c207
commit
d315a53fbd
5 changed files with 49 additions and 11 deletions
20
core/vm.go
20
core/vm.go
|
|
@ -698,7 +698,13 @@ func (vm *VM) Next() bool {
|
|||
vm.stack.Pop()
|
||||
|
||||
case InstructionConstant:
|
||||
vm.stack.Push(vm.ReadConstant())
|
||||
c := vm.ReadConstant()
|
||||
|
||||
if c, ok := c.(*FunctionValue); ok {
|
||||
c.Scope = vm.scope
|
||||
}
|
||||
|
||||
vm.stack.Push(c)
|
||||
|
||||
case InstructionAddFloat:
|
||||
r := vm.stack.Pop().(*FloatValue).Number
|
||||
|
|
@ -840,6 +846,7 @@ func (vm *VM) Next() bool {
|
|||
scope: vm.scope,
|
||||
})
|
||||
|
||||
vm.scope = f.Scope
|
||||
vm.descend()
|
||||
|
||||
for i := len(f.Params) - 1; i >= 0; i-- {
|
||||
|
|
@ -993,6 +1000,15 @@ func (vm *VM) Next() bool {
|
|||
vm.stack.Push(member)
|
||||
|
||||
case InstructionBreakpoint:
|
||||
/*
|
||||
// I'm keeping this
|
||||
s := vm.scope
|
||||
log.Printf("breakpoint %d", vm.ip)
|
||||
for s != nil {
|
||||
log.Printf("%s", s.current)
|
||||
s = s.parent
|
||||
}
|
||||
*/
|
||||
vm.stack.Push(&NilValue{})
|
||||
|
||||
default:
|
||||
|
|
@ -1122,7 +1138,7 @@ func (vm *VM) HasNext() bool {
|
|||
}
|
||||
|
||||
func (vm *VM) GetConstant(id Bytecode) Value {
|
||||
return vm.chunk.Constants[id]
|
||||
return vm.chunk.Constants[id].Clone()
|
||||
}
|
||||
|
||||
func (vm *VM) ReadConstant() Value {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue