Skip to content

Commit 5cfbf51

Browse files
committed
Rename opcodes
1 parent d4bcbad commit 5cfbf51

File tree

5 files changed

+37
-37
lines changed

5 files changed

+37
-37
lines changed

compiler/compiler.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,19 +196,19 @@ func (c *compiler) NilNode(_ *ast.NilNode) {
196196

197197
func (c *compiler) IdentifierNode(node *ast.IdentifierNode) {
198198
if c.mapEnv {
199-
c.emit(OpFetchEnvFast, c.addConstant(node.Value))
199+
c.emit(OpEnvFast, c.addConstant(node.Value))
200200
} else if len(node.FieldIndex) > 0 {
201-
c.emit(OpFetchEnvField, c.addConstant(&runtime.Field{
201+
c.emit(OpEnvField, c.addConstant(&runtime.Field{
202202
Index: node.FieldIndex,
203203
Path: []string{node.Value},
204204
}))
205205
} else if node.Method {
206-
c.emit(OpMethodEnv, c.addConstant(&runtime.Method{
206+
c.emit(OpEnvMethod, c.addConstant(&runtime.Method{
207207
Name: node.Value,
208208
Index: node.MethodIndex,
209209
}))
210210
} else {
211-
c.emit(OpFetchEnv, c.addConstant(node.Value))
211+
c.emit(OpEnvConst, c.addConstant(node.Value))
212212
}
213213
if node.Deref {
214214
c.emit(OpDeref)
@@ -454,7 +454,7 @@ func (c *compiler) MemberNode(node *ast.MemberNode) {
454454
}
455455
index = append(ident.FieldIndex, index...)
456456
path = append([]string{ident.Value}, path...)
457-
c.emitLocation(ident.Location(), OpFetchEnvField, c.addConstant(
457+
c.emitLocation(ident.Location(), OpEnvField, c.addConstant(
458458
&runtime.Field{Index: index, Path: path},
459459
))
460460
goto deref

compiler/compiler_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func TestCompile(t *testing.T) {
159159
},
160160
},
161161
Bytecode: []vm.Opcode{
162-
vm.OpFetchEnvField,
162+
vm.OpEnvField,
163163
},
164164
Arguments: []int{0},
165165
},
@@ -178,7 +178,7 @@ func TestCompile(t *testing.T) {
178178
},
179179
},
180180
Bytecode: []vm.Opcode{
181-
vm.OpFetchEnvField,
181+
vm.OpEnvField,
182182
vm.OpJumpIfNil,
183183
vm.OpFetchField,
184184
},
@@ -199,7 +199,7 @@ func TestCompile(t *testing.T) {
199199
},
200200
},
201201
Bytecode: []vm.Opcode{
202-
vm.OpFetchEnvField,
202+
vm.OpEnvField,
203203
vm.OpJumpIfNil,
204204
vm.OpFetchField,
205205
},
@@ -221,7 +221,7 @@ func TestCompile(t *testing.T) {
221221
},
222222
},
223223
Bytecode: []vm.Opcode{
224-
vm.OpFetchEnvField,
224+
vm.OpEnvField,
225225
vm.OpPush,
226226
vm.OpFetch,
227227
vm.OpFetchField,

vm/opcodes.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ const (
77
OpPushInt
88
OpPop
99
OpRot
10+
OpEnvConst
11+
OpEnvField
12+
OpEnvFast
13+
OpEnvMethod
1014
OpFetch
1115
OpFetchField
12-
OpFetchEnv
13-
OpFetchEnvField
14-
OpFetchEnvFast
1516
OpMethod
16-
OpMethodEnv
1717
OpTrue
1818
OpFalse
1919
OpNil

vm/program.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,27 +72,27 @@ func (program *Program) Disassemble() string {
7272
case OpRot:
7373
code("OpRot")
7474

75+
case OpEnvConst:
76+
constant("OpEnvConst")
77+
78+
case OpEnvField:
79+
constant("OpEnvField")
80+
81+
case OpEnvFast:
82+
constant("OpEnvFast")
83+
84+
case OpEnvMethod:
85+
constant("OpEnvMethod")
86+
7587
case OpFetch:
7688
code("OpFetch")
7789

7890
case OpFetchField:
7991
constant("OpFetchField")
8092

81-
case OpFetchEnv:
82-
constant("OpFetchEnv")
83-
84-
case OpFetchEnvField:
85-
constant("OpFetchEnvField")
86-
87-
case OpFetchEnvFast:
88-
constant("OpFetchEnvFast")
89-
9093
case OpMethod:
9194
constant("OpMethod")
9295

93-
case OpMethodEnv:
94-
constant("OpMethodEnv")
95-
9696
case OpTrue:
9797
code("OpTrue")
9898

vm/vm.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@ func (vm *VM) Run(program *Program, env interface{}) (out interface{}, err error
100100
vm.push(b)
101101
vm.push(a)
102102

103+
case OpEnvConst:
104+
vm.push(runtime.Fetch(env, program.Constants[arg]))
105+
106+
case OpEnvField:
107+
vm.push(runtime.FetchField(env, program.Constants[arg].(*runtime.Field)))
108+
109+
case OpEnvFast:
110+
vm.push(env.(map[string]interface{})[program.Constants[arg].(string)])
111+
112+
case OpEnvMethod:
113+
vm.push(runtime.FetchMethod(env, program.Constants[arg].(*runtime.Method)))
114+
103115
case OpFetch:
104116
b := vm.pop()
105117
a := vm.pop()
@@ -109,22 +121,10 @@ func (vm *VM) Run(program *Program, env interface{}) (out interface{}, err error
109121
a := vm.pop()
110122
vm.push(runtime.FetchField(a, program.Constants[arg].(*runtime.Field)))
111123

112-
case OpFetchEnv:
113-
vm.push(runtime.Fetch(env, program.Constants[arg]))
114-
115-
case OpFetchEnvField:
116-
vm.push(runtime.FetchField(env, program.Constants[arg].(*runtime.Field)))
117-
118-
case OpFetchEnvFast:
119-
vm.push(env.(map[string]interface{})[program.Constants[arg].(string)])
120-
121124
case OpMethod:
122125
a := vm.pop()
123126
vm.push(runtime.FetchMethod(a, program.Constants[arg].(*runtime.Method)))
124127

125-
case OpMethodEnv:
126-
vm.push(runtime.FetchMethod(env, program.Constants[arg].(*runtime.Method)))
127-
128128
case OpTrue:
129129
vm.push(true)
130130

0 commit comments

Comments
 (0)