|
@@ -65,7 +65,7 @@ func (astkind AstBasicMetaKind) String() string {
|
|
return string(astkind)
|
|
return string(astkind)
|
|
}
|
|
}
|
|
|
|
|
|
-func (astkind AstBasicMetaKind) Run(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
|
|
+func (astkind AstBasicMetaKind) Eval(vm *VM, ast Ast, val ...Value) []Value {
|
|
return []Value{}
|
|
return []Value{}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -93,24 +93,63 @@ func (astkind AstMetaKindEnd) String() string { return "AstEnd "
|
|
func (astkind AstMetaKindError) String() string { return "AstError " }
|
|
func (astkind AstMetaKindError) String() string { return "AstError " }
|
|
func (astkind AstMetaKindFlatten) String() string { return "AstFlatten " }
|
|
func (astkind AstMetaKindFlatten) String() string { return "AstFlatten " }
|
|
|
|
|
|
|
|
+func (astkind AstMetaKindNone) IsLeaf() bool { return false }
|
|
|
|
+func (astkind AstMetaKindProgram) IsLeaf() bool { return false }
|
|
|
|
+func (astkind AstMetaKindStatements) IsLeaf() bool { return false }
|
|
|
|
+func (astkind AstMetaKindStatement) IsLeaf() bool { return false }
|
|
|
|
+func (astkind AstMetaKindClosed) IsLeaf() bool { return false }
|
|
|
|
+func (astkind AstMetaKindSet) IsLeaf() bool { return false }
|
|
|
|
+func (astkind AstMetaKindGet) IsLeaf() bool { return false }
|
|
|
|
+func (astkind AstMetaKindTarget) IsLeaf() bool { return false }
|
|
|
|
+func (astkind AstMetaKindCommand) IsLeaf() bool { return false }
|
|
|
|
+func (astkind AstMetaKindArguments) IsLeaf() bool { return false }
|
|
|
|
+func (astkind AstMetaKindArgument) IsLeaf() bool { return false }
|
|
|
|
+func (astkind AstMetaKindExpression) IsLeaf() bool { return false }
|
|
|
|
+func (astkind AstMetaKindBlock) IsLeaf() bool { return true }
|
|
|
|
+func (astkind AstMetaKindParenthesis) IsLeaf() bool { return false }
|
|
|
|
+func (astkind AstMetaKindList) IsLeaf() bool { return false }
|
|
|
|
+func (astkind AstMetaKindCapture) IsLeaf() bool { return false }
|
|
|
|
+func (astkind AstMetaKindWordValue) IsLeaf() bool { return true }
|
|
|
|
+func (astkind AstMetaKindWord) IsLeaf() bool { return true }
|
|
|
|
+func (astkind AstMetaKindType) IsLeaf() bool { return true }
|
|
|
|
+func (astkind AstMetaKindValue) IsLeaf() bool { return true }
|
|
|
|
+func (astkind AstMetaKindEnd) IsLeaf() bool { return true }
|
|
|
|
+func (astkind AstMetaKindError) IsLeaf() bool { return true }
|
|
|
|
+func (astkind AstMetaKindFlatten) IsLeaf() bool { return false }
|
|
|
|
|
|
-func (astkind AstMetaKindNone) Run(vm *VM, ast Ast, val ...Value) []Value { return ReturnEmpty() }
|
|
|
|
|
|
|
|
-func (astkind AstMetaKindProgram) Run(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
- return []Value{vm.RunChildrenLastResult(ast, val...)}
|
|
|
|
|
|
+func lastValue(val []Value) []Value {
|
|
|
|
+ if len(val) < 1 {
|
|
|
|
+ return ReturnEmpty()
|
|
|
|
+ }
|
|
|
|
+ return []Value{val[len(val) - 1]}
|
|
}
|
|
}
|
|
|
|
|
|
-func (astkind AstMetaKindStatements) Run(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
- return []Value{vm.RunChildrenLastResult(ast, val...)}
|
|
|
|
|
|
+func firstValue(val []Value) []Value {
|
|
|
|
+ if len(val) < 1 {
|
|
|
|
+ return ReturnEmpty()
|
|
|
|
+ }
|
|
|
|
+ return []Value{val[0]}
|
|
}
|
|
}
|
|
|
|
|
|
-func (astkind AstMetaKindStatement) Run(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
- return vm.RunChildren(ast, val...)
|
|
|
|
|
|
+
|
|
|
|
+func (astkind AstMetaKindNone) Eval(vm *VM, ast Ast, val ...Value) []Value { return ReturnEmpty() }
|
|
|
|
+
|
|
|
|
+func (astkind AstMetaKindProgram) Eval(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
+ return lastValue(val)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (astkind AstMetaKindStatements) Eval(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
+ return lastValue(val)
|
|
}
|
|
}
|
|
|
|
|
|
-func (astkind AstMetaKindClosed) Run(vm *VM, ast Ast, val ...Value) []Value {return ReturnEmpty() }
|
|
|
|
-func (astkind AstMetaKindSet) Run(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
- values := vm.RunChildren(ast, val...)
|
|
|
|
|
|
+func (astkind AstMetaKindStatement) Eval(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
+ return val
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (astkind AstMetaKindClosed) Eval(vm *VM, ast Ast, val ...Value) []Value {return ReturnEmpty() }
|
|
|
|
+func (astkind AstMetaKindSet) Eval(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
+ values := val
|
|
if len(values) < 2 {
|
|
if len(values) < 2 {
|
|
return Fail(fmt.Errorf("set needs at least 2 arguments: received %v", values))
|
|
return Fail(fmt.Errorf("set needs at least 2 arguments: received %v", values))
|
|
}
|
|
}
|
|
@@ -128,8 +167,8 @@ func (astkind AstMetaKindSet) Run(vm *VM, ast Ast, val ...Value) []Value {
|
|
return Ok(value)
|
|
return Ok(value)
|
|
}
|
|
}
|
|
|
|
|
|
-func (astkind AstMetaKindGet) Run(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
- targets := vm.RunChildren(ast, val...)
|
|
|
|
|
|
+func (astkind AstMetaKindGet) Eval(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
+ targets := val
|
|
target := targets[0].String()
|
|
target := targets[0].String()
|
|
if target == "(" || target == "$" {
|
|
if target == "(" || target == "$" {
|
|
if len(targets) < 2 {
|
|
if len(targets) < 2 {
|
|
@@ -141,76 +180,75 @@ func (astkind AstMetaKindGet) Run(vm *VM, ast Ast, val ...Value) []Value {
|
|
return Ok(vm.Lookup(target))
|
|
return Ok(vm.Lookup(target))
|
|
}
|
|
}
|
|
|
|
|
|
-func (astkind AstMetaKindTarget) Run(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
- values := vm.RunChildren(ast, val...)
|
|
|
|
|
|
+func (astkind AstMetaKindTarget) Eval(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
+ values := val
|
|
values = append([]Value{ast.Value()}, values...)
|
|
values = append([]Value{ast.Value()}, values...)
|
|
return values
|
|
return values
|
|
}
|
|
}
|
|
|
|
|
|
-func (astkind AstMetaKindCommand) Run(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
|
|
+func (astkind AstMetaKindCommand) Eval(vm *VM, ast Ast, val ...Value) []Value {
|
|
commandName := ast.Value()
|
|
commandName := ast.Value()
|
|
- arguments := vm.RunChildren(ast, val...)
|
|
|
|
|
|
+ arguments := val
|
|
// log.Printf("Command execute: %s %v", commandName.String(), arguments)
|
|
// log.Printf("Command execute: %s %v", commandName.String(), arguments)
|
|
return vm.CallNamed(commandName.String(), arguments...)
|
|
return vm.CallNamed(commandName.String(), arguments...)
|
|
}
|
|
}
|
|
|
|
|
|
-func (astkind AstMetaKindArguments) Run(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
- return vm.RunChildren(ast, val...)
|
|
|
|
|
|
+func (astkind AstMetaKindArguments) Eval(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
+ return val
|
|
}
|
|
}
|
|
|
|
|
|
-func (astkind AstMetaKindArgument) Run(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
|
|
+func (astkind AstMetaKindArgument) Eval(vm *VM, ast Ast, val ...Value) []Value {
|
|
panic("AstMetaKindArgument")
|
|
panic("AstMetaKindArgument")
|
|
- return []Value{vm.RunChildrenFirstResult(ast, val...)}
|
|
|
|
|
|
+ return ReturnEmpty()
|
|
}
|
|
}
|
|
|
|
|
|
-func (astkind AstMetaKindExpression) Run(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
|
|
+func (astkind AstMetaKindExpression) Eval(vm *VM, ast Ast, val ...Value) []Value {
|
|
panic("AstMetaKindExpression")
|
|
panic("AstMetaKindExpression")
|
|
- return []Value{vm.RunChildrenLastResult(ast, val...)}
|
|
|
|
|
|
+ return ReturnEmpty()
|
|
}
|
|
}
|
|
|
|
|
|
-func (astkind AstMetaKindBlock) Run(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
|
|
+func (astkind AstMetaKindBlock) Eval(vm *VM, ast Ast, val ...Value) []Value {
|
|
// A block encountered in the AST is not executed.
|
|
// A block encountered in the AST is not executed.
|
|
// It results in an anonymous runnable with a clone of the AST embedded.
|
|
// It results in an anonymous runnable with a clone of the AST embedded.
|
|
return Ok(NewBlockValue(&ast))
|
|
return Ok(NewBlockValue(&ast))
|
|
}
|
|
}
|
|
|
|
|
|
-func (astkind AstMetaKindParenthesis) Run(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
- return []Value{vm.RunChildrenLastResult(ast, val...)}
|
|
|
|
|
|
+func (astkind AstMetaKindParenthesis) Eval(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
+ return lastValue(val)
|
|
}
|
|
}
|
|
|
|
|
|
-func (astkind AstMetaKindList) Run(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
- result := vm.RunChildren(ast, val...)
|
|
|
|
- list := &ListValue{List:result}
|
|
|
|
|
|
+func (astkind AstMetaKindList) Eval(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
+ list := &ListValue{List:val}
|
|
return []Value{list}
|
|
return []Value{list}
|
|
}
|
|
}
|
|
|
|
|
|
-func (astkind AstMetaKindCapture) Run(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
- return vm.RunChildren(ast, val...)
|
|
|
|
|
|
+func (astkind AstMetaKindCapture) Eval(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
+ return val
|
|
}
|
|
}
|
|
|
|
|
|
-func (astkind AstMetaKindWordValue) Run(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
|
|
+func (astkind AstMetaKindWordValue) Eval(vm *VM, ast Ast, val ...Value) []Value {
|
|
return []Value{ast.Value()}
|
|
return []Value{ast.Value()}
|
|
}
|
|
}
|
|
|
|
|
|
-func (astkind AstMetaKindWord) Run(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
|
|
+func (astkind AstMetaKindWord) Eval(vm *VM, ast Ast, val ...Value) []Value {
|
|
return []Value{ast.Value()}
|
|
return []Value{ast.Value()}
|
|
}
|
|
}
|
|
-func (astkind AstMetaKindType) Run(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
|
|
+func (astkind AstMetaKindType) Eval(vm *VM, ast Ast, val ...Value) []Value {
|
|
return []Value{ast.Value()}
|
|
return []Value{ast.Value()}
|
|
}
|
|
}
|
|
-func (astkind AstMetaKindValue) Run(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
|
|
+func (astkind AstMetaKindValue) Eval(vm *VM, ast Ast, val ...Value) []Value {
|
|
return []Value{ast.Value()}
|
|
return []Value{ast.Value()}
|
|
}
|
|
}
|
|
|
|
|
|
-func (astkind AstMetaKindEnd) Run(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
|
|
+func (astkind AstMetaKindEnd) Eval(vm *VM, ast Ast, val ...Value) []Value {
|
|
return []Value{EmptyValue{}}
|
|
return []Value{EmptyValue{}}
|
|
}
|
|
}
|
|
|
|
|
|
-func (astkind AstMetaKindError) Run(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
|
|
+func (astkind AstMetaKindError) Eval(vm *VM, ast Ast, val ...Value) []Value {
|
|
return []Value{ast.Value()}
|
|
return []Value{ast.Value()}
|
|
}
|
|
}
|
|
|
|
|
|
-func (astkind AstMetaKindFlatten) Run(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
|
|
+func (astkind AstMetaKindFlatten) Eval(vm *VM, ast Ast, val ...Value) []Value {
|
|
return ReturnEmpty()
|
|
return ReturnEmpty()
|
|
}
|
|
}
|
|
|
|
|
|
@@ -218,7 +256,9 @@ func (astkind AstMetaKindFlatten) Run(vm *VM, ast Ast, val ...Value) []Value {
|
|
|
|
|
|
type AstKind interface {
|
|
type AstKind interface {
|
|
String() string
|
|
String() string
|
|
- Run(vm *VM, ast Ast, val ...Value) []Value
|
|
|
|
|
|
+ Eval(vm *VM, ast Ast, val ...Value) []Value
|
|
|
|
+ IsLeaf() bool
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
/*
|
|
@@ -363,8 +403,8 @@ func (ast Ast) Child(index int) *Ast {
|
|
return ast.children[index]
|
|
return ast.children[index]
|
|
}
|
|
}
|
|
|
|
|
|
-func (ast Ast) Run(vm *VM, val ...Value) []Value {
|
|
|
|
- res := ast.AstKind.Run(vm, ast, val...)
|
|
|
|
|
|
+func (ast Ast) Eval(vm *VM, val ...Value) []Value {
|
|
|
|
+ res := ast.AstKind.Eval(vm, ast, val...)
|
|
if vm != nil && vm.Tracer != nil {
|
|
if vm != nil && vm.Tracer != nil {
|
|
vm.Trace(*vm, ast, res...)
|
|
vm.Trace(*vm, ast, res...)
|
|
}
|
|
}
|