|
@@ -160,7 +160,8 @@ func NewDefinedValue(name string, params []*Parameter, body *BlockValue) *Define
|
|
|
}
|
|
|
|
|
|
func (defined *DefinedValue) Call(vm *VM, arguments ...Value) []Value {
|
|
|
- for i , arg := range arguments {
|
|
|
+ // vm.Logf("Call defined value: %v", defined)
|
|
|
+ for i , arg := range arguments {
|
|
|
if i >= len(defined.Parameters) {
|
|
|
break
|
|
|
}
|
|
@@ -569,8 +570,18 @@ func (vm *VM) PopScope() *Scope {
|
|
|
}
|
|
|
|
|
|
func (block * BlockValue) Call(vm *VM, arguments ...Value) []Value {
|
|
|
- ast := block.Ast
|
|
|
- arr := vm.RunAst(*ast, arguments...)
|
|
|
+ ast := block.Ast
|
|
|
+ // Now, don't run the bloc itself but the Statements node
|
|
|
+ // that should be in it.
|
|
|
+ children := ast.Children()
|
|
|
+ if len(children) < 1 {
|
|
|
+ return Fail(fmt.Errorf("Block has no statements."))
|
|
|
+ }
|
|
|
+ if len(children) > 1 {
|
|
|
+ return Fail(fmt.Errorf("Block has too many statements."))
|
|
|
+ }
|
|
|
+ statements := children[0]
|
|
|
+ arr := vm.RunAst(*statements, arguments...)
|
|
|
return arr
|
|
|
}
|
|
|
|
|
@@ -636,22 +647,6 @@ func (vm *VM) CallNamed(name string, arguments ...Value) []Value {
|
|
|
} else {
|
|
|
return ReturnError(vm.AddTrace(NewErrorValuef("Cannot call %s: %v. Not callable", name, value)))
|
|
|
}
|
|
|
-
|
|
|
- /*
|
|
|
- value := vm.Lookup(name)
|
|
|
- switch toCall := value.(type) {
|
|
|
- case *BuiltinValue:
|
|
|
- return vm.CallBuiltin(toCall.Handler, arguments...)
|
|
|
- case *DefinedValue:
|
|
|
- return vm.CallDefined(toCall.Body.Ast, arguments...)
|
|
|
- case *CoverValue:
|
|
|
- return vm.CallCover(toCall, arguments...)
|
|
|
- case *BlockValue:
|
|
|
- return vm.CallBlock(toCall.Ast, arguments...)
|
|
|
- default:
|
|
|
- return ReturnError(vm.AddTrace(NewErrorValuef("Cannot call %s: %v. Not callable", name, value)))
|
|
|
- }
|
|
|
- */
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -809,9 +804,11 @@ func (vm *VM) RunChildrenFirstResult(ast Ast, args ...Value) Value {
|
|
|
|
|
|
func (vm *VM) RunAst(ast Ast, args ...Value) []Value {
|
|
|
var result []Value
|
|
|
- pos := ast.Token().Position
|
|
|
+ /*pos := ast.Token().Position
|
|
|
vm.PushNewFrame(&pos)
|
|
|
defer vm.PopFrame()
|
|
|
+ */
|
|
|
+ // vm.Logf("RunAst: %s\n", ast.Kind().String())
|
|
|
// Leaf nodes, both declared and in practice are self evaluating.
|
|
|
if ast.Kind().IsLeaf() || ast.CountChildren() < 1 {
|
|
|
result = ast.Eval(vm)
|
|
@@ -837,8 +834,10 @@ func (vm *VM) RunAst(ast Ast, args ...Value) []Value {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
+ // vm.Logf("RunAst subResult: %v\n", subResult)
|
|
|
result = ast.Eval(vm, subResult...)
|
|
|
}
|
|
|
+ // vm.Logf("RunAst result: %v\n", result)
|
|
|
return result
|
|
|
}
|
|
|
|