WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

Commit 3a4962cf authored by Stefan Marr's avatar Stefan Marr
Browse files

Change lookup of Symbol and Bytecode names to use constants



- they used metaprogramming before, but that does not seem to work.
- RPython gives me 'operation cannot succeed' and conflicting types for variables if I try to change the code slightly
-> will just use simple constants instead, less maintainable but it works
Signed-off-by: default avatarStefan Marr <git@stefan-marr.de>
parent 2e275146
from rpython.rlib.unroll import unrolling_iterable
# Symbol is a 'lightweight' enum, in Python 3.4, we could use Enum as superclass
class Symbol(object):
NONE = -1
......@@ -34,17 +32,41 @@ 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 symbol_as_str(symbol):
symbols = unrolling_iterable(int_constants_of(Symbol))
for (key, val) in symbols:
if val == symbol:
return key
raise ValueError('No Symbol defined for the value %d.' % symbol)
def int_constants_of(cls):
out = {}
for key, value in cls.__dict__.items():
if isinstance(value, int):
out[key] = value
return out
if symbol == -1:
return "NONE"
else:
return Symbol._names[symbol]
from rpython.rlib.unroll import unrolling_iterable
class Bytecodes(object):
# Bytecodes used by the Simple Object Machine (SOM)
......@@ -58,7 +56,23 @@ 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]
......@@ -77,17 +91,5 @@ 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.')
bytecodes = unrolling_iterable(int_constants_of(Bytecodes))
for key, val in bytecodes:
if val == bytecode:
return key.upper()
raise ValueError('No defined defined for the value %d.' % bytecode)
def int_constants_of(cls):
out = {}
for key, value in cls.__dict__.items():
if isinstance(value, int):
out[key] = value
return out
assert bytecode >= 0 and bytecode <= Bytecodes._num_bytecodes
return Bytecodes._bytecode_names[bytecode]
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