Skip to content

Commit

Permalink
Rename opcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Nov 12, 2022
1 parent 5cfbf51 commit 497c6bd
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 25 deletions.
10 changes: 5 additions & 5 deletions compiler/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions compiler/compiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func TestCompile(t *testing.T) {
},
},
Bytecode: []vm.Opcode{
vm.OpEnvField,
vm.OpLoadField,
},
Arguments: []int{0},
},
Expand All @@ -178,7 +178,7 @@ func TestCompile(t *testing.T) {
},
},
Bytecode: []vm.Opcode{
vm.OpEnvField,
vm.OpLoadField,
vm.OpJumpIfNil,
vm.OpFetchField,
},
Expand All @@ -199,7 +199,7 @@ func TestCompile(t *testing.T) {
},
},
Bytecode: []vm.Opcode{
vm.OpEnvField,
vm.OpLoadField,
vm.OpJumpIfNil,
vm.OpFetchField,
},
Expand All @@ -221,7 +221,7 @@ func TestCompile(t *testing.T) {
},
},
Bytecode: []vm.Opcode{
vm.OpEnvField,
vm.OpLoadField,
vm.OpPush,
vm.OpFetch,
vm.OpFetchField,
Expand Down
8 changes: 4 additions & 4 deletions vm/opcodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const (
OpPushInt
OpPop
OpRot
OpEnvConst
OpEnvField
OpEnvFast
OpEnvMethod
OpLoadConst
OpLoadField
OpLoadFast
OpLoadMethod
OpFetch
OpFetchField
OpMethod
Expand Down
16 changes: 8 additions & 8 deletions vm/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions vm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 497c6bd

Please sign in to comment.