8000 Name those opcodes · go-python/gpython@6e4d79a · GitHub
[go: up one dir, main page]

Skip to content

Commit 6e4d79a

Browse files
committed
Name those opcodes
1 parent af9a450 commit 6e4d79a

File tree

3 files changed

+117
-3
lines changed

3 files changed

+117
-3
lines changed

py/function.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717

1818
var (
1919
// Function pointer for vm call to avoid circular reference
20-
VmRun func(StringDict, StringDict, *Code) (error)
20+
VmRun func(StringDict, StringDict, *Code) error
2121
)
2222

2323
// A python Function object

vm/eval.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,9 +792,9 @@ func Run(globals, locals py.StringDict, co *py.Code) (err error) {
792792
if vm.extended {
793793
arg += vm.ext << 16
794794
}
795-
fmt.Printf("Opcode %d with arg %d\n", opcode, arg)
795+
fmt.Printf("* %s(%d)\n", OpCodeToName[opcode], arg)
796796
} else {
797-
fmt.Printf("Opcode %d\n", opcode)
797+
fmt.Printf("* %s\n", OpCodeToName[opcode])
798798
}
799799
vm.extended = false
800800
jumpTable[opcode](vm, arg)

vm/opcodes.go

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,120 @@ const (
144144
EXCEPT_HANDLER = 257
145145
)
146146

147+
// Turn a name into an opcode
148+
var NameToOpCode = map[string]byte{
149+
"POP_TOP": 1,
150+
"ROT_TWO": 2,
151+
"ROT_THREE": 3,
152+
"DUP_TOP": 4,
153+
"DUP_TOP_TWO": 5,
154+
"NOP": 9,
155+
"UNARY_POSITIVE": 10,
156+
"UNARY_NEGATIVE": 11,
157+
"UNARY_NOT": 12,
158+
"UNARY_INVERT": 15,
159+
"BINARY_POWER": 19,
160+
"BINARY_MULTIPLY": 20,
161+
"BINARY_MODULO": 22,
162+
"BINARY_ADD": 23,
163+
"BINARY_SUBTRACT": 24,
164+
"BINARY_SUBSCR": 25,
165+
"BINARY_FLOOR_DIVIDE": 26,
166+
"BINARY_TRUE_DIVIDE": 27,
167+
"INPLACE_FLOOR_DIVIDE": 28,
168+
"INPLACE_TRUE_DIVIDE": 29,
169+
"STORE_MAP": 54,
170+
"INPLACE_ADD": 55,
171+
"INPLACE_SUBTRACT": 56,
172+
"INPLACE_MULTIPLY": 57,
173+
"INPLACE_MODULO": 59,
174+
"STORE_SUBSCR": 60,
175+
"DELETE_SUBSCR": 61,
176+
"BINARY_LSHIFT": 62,
177+
"BINARY_RSHIFT": 63,
178+
"BINARY_AND": 64,
179+
"BINARY_XOR": 65,
180+
"BINARY_OR": 66,
181+
"INPLACE_POWER": 67,
182+
"GET_ITER": 68,
183+
"PRINT_EXPR": 70,
184+
"LOAD_BUILD_CLASS": 71,
185+
"YIELD_FROM": 72,
186+
"INPLACE_LSHIFT": 75,
187+
"INPLACE_RSHIFT": 76,
188+
"INPLACE_AND": 77,
189+
"INPLACE_XOR": 78,
190+
"INPLACE_OR": 79,
191+
"BREAK_LOOP": 80,
192+
"WITH_CLEANUP": 81,
193+
"RETURN_VALUE": 83,
194+
"IMPORT_STAR": 84,
195+
"YIELD_VALUE": 86,
196+
"POP_BLOCK": 87,
197+
"END_FINALLY": 88,
198+
"POP_EXCEPT": 89,
199+
"STORE_NAME": 90,
200+
"DELETE_NAME": 91,
201+
"UNPACK_SEQUENCE": 92,
202+
"FOR_ITER": 93,
203+
"UNPACK_EX": 94,
204+
"STORE_ATTR": 95,
205+
"DELETE_ATTR": 96,
206+
"STORE_GLOBAL": 97,
207+
"DELETE_GLOBAL": 98,
208+
"LOAD_CONST": 100,
209+
"LOAD_NAME": 101,
210+
"BUILD_TUPLE": 102,
211+
"BUILD_LIST": 103,
212+
"BUILD_SET": 104,
213+
"BUILD_MAP": 105,
214+
"LOAD_ATTR": 106,
215+
"COMPARE_OP": 107,
216+
"IMPORT_NAME": 108,
217+
"IMPORT_FROM": 109,
218+
"JUMP_FORWARD": 110,
219+
"JUMP_IF_FALSE_OR_POP": 111,
220+
"JUMP_IF_TRUE_OR_POP": 112,
221+
"JUMP_ABSOLUTE": 113,
222+
"POP_JUMP_IF_FALSE": 114,
223+
"POP_JUMP_IF_TRUE": 115,
224+
"LOAD_GLOBAL": 116,
225+
"CONTINUE_LOOP": 119,
226+
"SETUP_LOOP": 120,
227+
"SETUP_EXCEPT": 121,
228+
"SETUP_FINALLY": 122,
229+
"LOAD_FAST": 124,
230+
"STORE_FAST": 125,
231+
"DELETE_FAST": 126,
232+
"RAISE_VARARGS": 130,
233+
"CALL_FUNCTION": 131,
234+
"MAKE_FUNCTION": 132,
235+
"BUILD_SLICE": 133,
236+
"MAKE_CLOSURE": 134,
237+
"LOAD_CLOSURE": 135,
238+
"LOAD_DEREF": 136,
239+
"STORE_DEREF": 137,
240+
"DELETE_DEREF": 138,
241+
"CALL_FUNCTION_VAR": 140,
242+
"CALL_FUNCTION_KW": 141,
243+
"CALL_FUNCTION_VAR_KW": 142,
244+
"SETUP_WITH": 143,
245+
"EXTENDED_ARG": 144,
246+
"LIST_APPEND": 145,
247+
"SET_ADD": 146,
248+
"MAP_ADD": 147,
249+
"LOAD_CLASSDEREF": 148,
250+
}
251+
252+
var OpCodeToName map[byte]string
253+
254+
func init() {
255+
OpCodeToName = make(map[byte]string, len(NameToOpCode))
256+
for name, opcode := range NameToOpCode {
257+
OpCodeToName[opcode] = name
258+
}
259+
}
260+
147261
// Rich comparison opcodes
148262
const (
149263
PyCmp_LT = iota

0 commit comments

Comments
 (0)
0