Commit 81bb9103 authored by Tobias Pape's avatar Tobias Pape Committed by Stefan Marr

add the Byecode/Symbol names at load/translate time

parent 6690c630
......@@ -32,41 +32,18 @@ class Symbol(object):
Keyword = 28
KeywordSequence = 29
OperatorSequence = 30
_names = ["Integer",
"Not",
"And",
"Or",
"Star",
"Div",
"Mod",
"Plus",
"Minus",
"Equal",
"More",
"Less",
"Comma",
"At",
"Per",
"NewBlock",
"EndBlock",
"Colon",
"Period",
"Exit",
"Assign",
"NewTerm",
"EndTerm",
"Pound",
"Primitive",
"Separator",
"STString",
"Identifier",
"Keyword",
"KeywordSequence",
"OperatorSequence"]
def _sorted_symbols(cls):
"NOT_RPYTHON"
return [key for value, key in \
sorted([(value, key) for key, value in cls.__dict__.items()]) \
if isinstance(value, int)
]
_symbols = _sorted_symbols(Symbol)
def symbol_as_str(symbol):
if symbol == -1:
return "NONE"
index = symbol + 1
if index > len(_symbols):
raise ValueError('No Symbol defined for the value %d.' % symbol)
else:
return Symbol._names[symbol]
return _symbols[index]
from rpython.rlib.unroll import unrolling_iterable
class Bytecodes(object):
# Bytecodes used by the Simple Object Machine (SOM)
......@@ -56,23 +58,7 @@ class Bytecodes(object):
0, # return_local
0 ] # return_non_local
_bytecode_names = ["HALT",
"DUP",
"PUSH_LOCAL",
"PUSH_ARGUMENT",
"PUSH_FIELD",
"PUSH_BLOCK",
"PUSH_CONSTANT",
"PUSH_GLOBAL",
"POP",
"POP_LOCAL",
"POP_ARGUMENT",
"POP_FIELD",
"SEND",
"SUPER_SEND",
"RETURN_LOCAL",
"RETURN_NON_LOCAL"]
def bytecode_length(bytecode):
return Bytecodes._bytecode_length[bytecode]
......@@ -92,5 +78,16 @@ def bytecode_stack_effect_depends_on_send(bytecode):
def bytecode_as_str(bytecode):
if not isinstance(bytecode, int):
raise ValueError('bytecode is expected to be an integer.')
assert bytecode >= 0 and bytecode <= Bytecodes._num_bytecodes
return Bytecodes._bytecode_names[bytecode]
if bytecode > len(_bytecode_names):
raise ValueError('No Bytecode defined for the value %d.' % bytecode)
else:
return _bytecode_names[bytecode]
def _sorted_bytecode_names(cls):
"NOT_RPYTHON"
return [key.upper() for value, key in \
sorted([(value, key) for key, value in cls.__dict__.items()]) \
if isinstance(value, int) and key[0] != "_"
]
_bytecode_names = _sorted_bytecode_names(Bytecodes)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment