mirror of
https://github.com/hanzoai/expr.git
synced 2026-09-24 16:58:58 +00:00
Rename opcodes
This commit is contained in:
@@ -196,19 +196,19 @@ func (c *compiler) NilNode(_ *ast.NilNode) {
|
||||
|
||||
func (c *compiler) IdentifierNode(node *ast.IdentifierNode) {
|
||||
if c.mapEnv {
|
||||
c.emit(OpEnvFast, c.addConstant(node.Value))
|
||||
c.emit(OpLoadFast, c.addConstant(node.Value))
|
||||
} else if len(node.FieldIndex) > 0 {
|
||||
c.emit(OpEnvField, c.addConstant(&runtime.Field{
|
||||
c.emit(OpLoadField, c.addConstant(&runtime.Field{
|
||||
Index: node.FieldIndex,
|
||||
Path: []string{node.Value},
|
||||
}))
|
||||
} else if node.Method {
|
||||
c.emit(OpEnvMethod, c.addConstant(&runtime.Method{
|
||||
c.emit(OpLoadMethod, c.addConstant(&runtime.Method{
|
||||
Name: node.Value,
|
||||
Index: node.MethodIndex,
|
||||
}))
|
||||
} else {
|
||||
c.emit(OpEnvConst, c.addConstant(node.Value))
|
||||
c.emit(OpLoadConst, c.addConstant(node.Value))
|
||||
}
|
||||
if node.Deref {
|
||||
c.emit(OpDeref)
|
||||
@@ -454,7 +454,7 @@ func (c *compiler) MemberNode(node *ast.MemberNode) {
|
||||
}
|
||||
index = append(ident.FieldIndex, index...)
|
||||
path = append([]string{ident.Value}, path...)
|
||||
c.emitLocation(ident.Location(), OpEnvField, c.addConstant(
|
||||
c.emitLocation(ident.Location(), OpLoadField, c.addConstant(
|
||||
&runtime.Field{Index: index, Path: path},
|
||||
))
|
||||
goto deref
|
||||
|
||||
@@ -159,7 +159,7 @@ func TestCompile(t *testing.T) {
|
||||
},
|
||||
},
|
||||
Bytecode: []vm.Opcode{
|
||||
vm.OpEnvField,
|
||||
vm.OpLoadField,
|
||||
},
|
||||
Arguments: []int{0},
|
||||
},
|
||||
@@ -178,7 +178,7 @@ func TestCompile(t *testing.T) {
|
||||
},
|
||||
},
|
||||
Bytecode: []vm.Opcode{
|
||||
vm.OpEnvField,
|
||||
vm.OpLoadField,
|
||||
vm.OpJumpIfNil,
|
||||
vm.OpFetchField,
|
||||
},
|
||||
@@ -199,7 +199,7 @@ func TestCompile(t *testing.T) {
|
||||
},
|
||||
},
|
||||
Bytecode: []vm.Opcode{
|
||||
vm.OpEnvField,
|
||||
vm.OpLoadField,
|
||||
vm.OpJumpIfNil,
|
||||
vm.OpFetchField,
|
||||
},
|
||||
@@ -221,7 +221,7 @@ func TestCompile(t *testing.T) {
|
||||
},
|
||||
},
|
||||
Bytecode: []vm.Opcode{
|
||||
vm.OpEnvField,
|
||||
vm.OpLoadField,
|
||||
vm.OpPush,
|
||||
vm.OpFetch,
|
||||
vm.OpFetchField,
|
||||
|
||||
+4
-4
@@ -7,10 +7,10 @@ const (
|
||||
OpPushInt
|
||||
OpPop
|
||||
OpRot
|
||||
OpEnvConst
|
||||
OpEnvField
|
||||
OpEnvFast
|
||||
OpEnvMethod
|
||||
OpLoadConst
|
||||
OpLoadField
|
||||
OpLoadFast
|
||||
OpLoadMethod
|
||||
OpFetch
|
||||
OpFetchField
|
||||
OpMethod
|
||||
|
||||
+8
-8
@@ -72,17 +72,17 @@ func (program *Program) Disassemble() string {
|
||||
case OpRot:
|
||||
code("OpRot")
|
||||
|
||||
case OpEnvConst:
|
||||
constant("OpEnvConst")
|
||||
case OpLoadConst:
|
||||
constant("OpLoadConst")
|
||||
|
||||
case OpEnvField:
|
||||
constant("OpEnvField")
|
||||
case OpLoadField:
|
||||
constant("OpLoadField")
|
||||
|
||||
case OpEnvFast:
|
||||
constant("OpEnvFast")
|
||||
case OpLoadFast:
|
||||
constant("OpLoadFast")
|
||||
|
||||
case OpEnvMethod:
|
||||
constant("OpEnvMethod")
|
||||
case OpLoadMethod:
|
||||
constant("OpLoadMethod")
|
||||
|
||||
case OpFetch:
|
||||
code("OpFetch")
|
||||
|
||||
@@ -100,16 +100,16 @@ func (vm *VM) Run(program *Program, env interface{}) (out interface{}, err error
|
||||
vm.push(b)
|
||||
vm.push(a)
|
||||
|
||||
case OpEnvConst:
|
||||
case OpLoadConst:
|
||||
vm.push(runtime.Fetch(env, program.Constants[arg]))
|
||||
|
||||
case OpEnvField:
|
||||
case OpLoadField:
|
||||
vm.push(runtime.FetchField(env, program.Constants[arg].(*runtime.Field)))
|
||||
|
||||
case OpEnvFast:
|
||||
case OpLoadFast:
|
||||
vm.push(env.(map[string]interface{})[program.Constants[arg].(string)])
|
||||
|
||||
case OpEnvMethod:
|
||||
case OpLoadMethod:
|
||||
vm.push(runtime.FetchMethod(env, program.Constants[arg].(*runtime.Method)))
|
||||
|
||||
case OpFetch:
|
||||
|
||||
Reference in New Issue
Block a user