|
@@ -66,7 +66,7 @@ func (astkind AstBasicMetaKind) String() string {
|
|
|
return string(astkind)
|
|
|
}
|
|
|
|
|
|
-func (astkind AstBasicMetaKind) Run(vm *VM, ast Ast, val ListValue) Value {
|
|
|
+func (astkind AstBasicMetaKind) Run(vm *VM, ast Ast, val ...Value) Value {
|
|
|
return EmptyListValue()
|
|
|
}
|
|
|
|
|
@@ -95,99 +95,102 @@ func (astkind AstMetaKindError) String() string { return "AstError "
|
|
|
func (astkind AstMetaKindFlatten) String() string { return "AstFlatten " }
|
|
|
|
|
|
|
|
|
-func (astkind AstMetaKindNone) Run(vm *VM, ast Ast, val ListValue) Value {return EmptyListValue() }
|
|
|
+func (astkind AstMetaKindNone) Run(vm *VM, ast Ast, val ...Value) Value { return EmptyValue{} }
|
|
|
|
|
|
-func (astkind AstMetaKindProgram) Run(vm *VM, ast Ast, val ListValue) Value {
|
|
|
- res := EmptyListValue()
|
|
|
- for _, child := range ast.Children() {
|
|
|
- res.Append(child.Run(vm, val))
|
|
|
- }
|
|
|
- return res
|
|
|
+func (astkind AstMetaKindProgram) Run(vm *VM, ast Ast, val ...Value) Value {
|
|
|
+ return vm.RunChildrenLastResult(ast, val...)
|
|
|
}
|
|
|
|
|
|
-func (astkind AstMetaKindStatements) Run(vm *VM, ast Ast, val ListValue) Value {
|
|
|
- res := EmptyListValue()
|
|
|
- for _, child := range ast.Children() {
|
|
|
- res.Append(child.Run(vm, val))
|
|
|
- }
|
|
|
- return res
|
|
|
+func (astkind AstMetaKindStatements) Run(vm *VM, ast Ast, val ...Value) Value {
|
|
|
+ return vm.RunChildrenLastResult(ast, val...)
|
|
|
}
|
|
|
|
|
|
-func (astkind AstMetaKindStatement) Run(vm *VM, ast Ast, val ListValue) Value {
|
|
|
- return vm.RunChildren(ast, val)
|
|
|
+func (astkind AstMetaKindStatement) Run(vm *VM, ast Ast, val ...Value) Value {
|
|
|
+ panic("AstMetaKindStatement")
|
|
|
+ return vm.RunChildren(ast, val...)
|
|
|
}
|
|
|
|
|
|
-func (astkind AstMetaKindClosed) Run(vm *VM, ast Ast, val ListValue) Value {return EmptyListValue() }
|
|
|
-func (astkind AstMetaKindSet) Run(vm *VM, ast Ast, val ListValue) Value {
|
|
|
+func (astkind AstMetaKindClosed) Run(vm *VM, ast Ast, val ...Value) Value {return EmptyListValue() }
|
|
|
+func (astkind AstMetaKindSet) Run(vm *VM, ast Ast, val ...Value) Value {
|
|
|
varName := ast.Value()
|
|
|
- value := vm.RunChildren(ast, val)
|
|
|
+ value := vm.RunChildren(ast, val...)
|
|
|
vm.Register(varName.String(), value)
|
|
|
return value
|
|
|
}
|
|
|
|
|
|
-func (astkind AstMetaKindGet) Run(vm *VM, ast Ast, val ListValue) Value {
|
|
|
- varName := ast.Value()
|
|
|
- return NewListValue(vm.Lookup(varName.String()))
|
|
|
+func (astkind AstMetaKindGet) Run(vm *VM, ast Ast, val ...Value) Value {
|
|
|
+ target := vm.RunChildrenFirstResult(ast, val...).(ListValue)
|
|
|
+ return vm.Lookup(target.String())
|
|
|
}
|
|
|
|
|
|
-func (astkind AstMetaKindTarget) Run(vm *VM, ast Ast, val ListValue) Value {
|
|
|
- return NewListValue(ast.Value())
|
|
|
+func (astkind AstMetaKindTarget) Run(vm *VM, ast Ast, val ...Value) Value {
|
|
|
+ return ast.Value()
|
|
|
}
|
|
|
-func (astkind AstMetaKindCommand) Run(vm *VM, ast Ast, val ListValue) Value {
|
|
|
+
|
|
|
+func (astkind AstMetaKindCommand) Run(vm *VM, ast Ast, val ...Value) Value {
|
|
|
commandName := ast.Value()
|
|
|
- arglist, _ := vm.RunChildren(ast, val).(ListValue)
|
|
|
- arguments := arglist.First()
|
|
|
- log.Printf("Command execute: %s %v", commandName.String(), arguments)
|
|
|
- return vm.CallNamed(commandName.String(), arguments)
|
|
|
+ arguments := vm.RunChildrenFirstResult(ast, val...)
|
|
|
+ if argList, isList := arguments.(ListValue) ; isList {
|
|
|
+ log.Printf("Command execute: %s %v", commandName.String(), argList)
|
|
|
+ return vm.CallNamed(commandName.String(), argList)
|
|
|
+ } else {
|
|
|
+ return NewErrorValuef("Internal error when calling %s.", commandName.String())
|
|
|
+ }
|
|
|
}
|
|
|
-func (astkind AstMetaKindArguments) Run(vm *VM, ast Ast, val ListValue) Value {
|
|
|
- return vm.RunChildren(ast, val)
|
|
|
+
|
|
|
+func (astkind AstMetaKindArguments) Run(vm *VM, ast Ast, val ...Value) Value {
|
|
|
+ return vm.RunChildren(ast, val...)
|
|
|
}
|
|
|
-func (astkind AstMetaKindArgument) Run(vm *VM, ast Ast, val ListValue) Value {
|
|
|
+
|
|
|
+func (astkind AstMetaKindArgument) Run(vm *VM, ast Ast, val ...Value) Value {
|
|
|
panic("AstMetaKindArgument")
|
|
|
- vm.RunChildren(ast, val)
|
|
|
- reslist, _ := vm.RunChildren(ast, val).(ListValue)
|
|
|
- return reslist.First()
|
|
|
+ return vm.RunChildrenFirstResult(ast, val...)
|
|
|
}
|
|
|
-func (astkind AstMetaKindExpression) Run(vm *VM, ast Ast, val ListValue) Value {
|
|
|
- return vm.RunChildren(ast, val)
|
|
|
+
|
|
|
+func (astkind AstMetaKindExpression) Run(vm *VM, ast Ast, val ...Value) Value {
|
|
|
+ panic("AstMetaKindExpression")
|
|
|
+ return vm.RunChildrenLastResult(ast, val...)
|
|
|
}
|
|
|
-func (astkind AstMetaKindBlock) Run(vm *VM, ast Ast, val ListValue) Value {
|
|
|
- return vm.RunChildren(ast, val)
|
|
|
+
|
|
|
+func (astkind AstMetaKindBlock) Run(vm *VM, ast Ast, val ...Value) Value {
|
|
|
+ return vm.RunChildrenLastResult(ast, val...)
|
|
|
}
|
|
|
-func (astkind AstMetaKindParenthesis) Run(vm *VM, ast Ast, val ListValue) Value {
|
|
|
- return vm.RunChildren(ast, val)
|
|
|
+
|
|
|
+func (astkind AstMetaKindParenthesis) Run(vm *VM, ast Ast, val ...Value) Value {
|
|
|
+ return vm.RunChildrenLastResult(ast, val...)
|
|
|
}
|
|
|
-func (astkind AstMetaKindList) Run(vm *VM, ast Ast, val ListValue) Value {
|
|
|
- return vm.RunChildren(ast, val)
|
|
|
+
|
|
|
+func (astkind AstMetaKindList) Run(vm *VM, ast Ast, val ...Value) Value {
|
|
|
+ return vm.RunChildren(ast, val...)
|
|
|
}
|
|
|
|
|
|
-func (astkind AstMetaKindCapture) Run(vm *VM, ast Ast, val ListValue) Value {
|
|
|
- return vm.RunChildren(ast, val)
|
|
|
+func (astkind AstMetaKindCapture) Run(vm *VM, ast Ast, val ...Value) Value {
|
|
|
+ return vm.RunChildren(ast, val...)
|
|
|
}
|
|
|
-func (astkind AstMetaKindWordValue) Run(vm *VM, ast Ast, val ListValue) Value {
|
|
|
+
|
|
|
+func (astkind AstMetaKindWordValue) Run(vm *VM, ast Ast, val ...Value) Value {
|
|
|
return ast.Value()
|
|
|
}
|
|
|
|
|
|
-func (astkind AstMetaKindWord) Run(vm *VM, ast Ast, val ListValue) Value {
|
|
|
+func (astkind AstMetaKindWord) Run(vm *VM, ast Ast, val ...Value) Value {
|
|
|
return ast.Value()
|
|
|
}
|
|
|
-func (astkind AstMetaKindType) Run(vm *VM, ast Ast, val ListValue) Value {
|
|
|
+func (astkind AstMetaKindType) Run(vm *VM, ast Ast, val ...Value) Value {
|
|
|
return ast.Value()
|
|
|
}
|
|
|
-func (astkind AstMetaKindValue) Run(vm *VM, ast Ast, val ListValue) Value {
|
|
|
+func (astkind AstMetaKindValue) Run(vm *VM, ast Ast, val ...Value) Value {
|
|
|
return ast.Value()
|
|
|
}
|
|
|
|
|
|
-func (astkind AstMetaKindEnd) Run(vm *VM, ast Ast, val ListValue) Value {
|
|
|
- return EmptyListValue()
|
|
|
+func (astkind AstMetaKindEnd) Run(vm *VM, ast Ast, val ...Value) Value {
|
|
|
+ return EmptyValue{}
|
|
|
}
|
|
|
|
|
|
-func (astkind AstMetaKindError) Run(vm *VM, ast Ast, val ListValue) Value {
|
|
|
- return NewListValue(ast.Value())
|
|
|
+func (astkind AstMetaKindError) Run(vm *VM, ast Ast, val ...Value) Value {
|
|
|
+ return ast.Value()
|
|
|
}
|
|
|
|
|
|
-func (astkind AstMetaKindFlatten) Run(vm *VM, ast Ast, val ListValue) Value {
|
|
|
+func (astkind AstMetaKindFlatten) Run(vm *VM, ast Ast, val ...Value) Value {
|
|
|
return EmptyListValue()
|
|
|
}
|
|
|
|
|
@@ -195,7 +198,7 @@ func (astkind AstMetaKindFlatten) Run(vm *VM, ast Ast, val ListValue) Value {
|
|
|
|
|
|
type AstKind interface {
|
|
|
String() string
|
|
|
- Run(vm *VM, ast Ast, val ListValue) Value
|
|
|
+ Run(vm *VM, ast Ast, val ...Value) Value
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -340,11 +343,12 @@ func (ast Ast) Child(index int) *Ast {
|
|
|
return ast.children[index]
|
|
|
}
|
|
|
|
|
|
-func (ast Ast) Run(vm *VM, val ListValue) Value {
|
|
|
+func (ast Ast) Run(vm *VM, val ...Value) Value {
|
|
|
+ res := ast.AstKind.Run(vm, ast, val...)
|
|
|
if vm != nil && vm.Tracer != nil {
|
|
|
- vm.Trace(*vm, ast, val)
|
|
|
+ vm.Trace(*vm, ast, res)
|
|
|
}
|
|
|
- return ast.AstKind.Run(vm, ast, val)
|
|
|
+ return res
|
|
|
}
|
|
|
|
|
|
func (ast *Ast) Walk(walker func(node *Ast) *Ast) *Ast {
|