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.2% of users enabled 2FA.

Commit 80c4423a authored by Stefan Marr's avatar Stefan Marr
Browse files

Added SourcecodeCompiler and Symbol 'enum'


Signed-off-by: default avatarStefan Marr <git@stefan-marr.de>
parent 7167ddf5
import os
def compile_class_from_file(path, filename, system_class, universe):
return _SourcecodeCompiler().compile(path, filename, system_class, universe)
def compile_class_from_string(stmt, system_class, universe):
return _SourcecodeCompiler().compile_class_string(stmt, system_class, universe)
class _SourcecodeCompiler(object):
def __init__(self):
self._parser = None
def compile(self, path, filename, system_class, universe):
result = system_class
fname = path + os.pathsep + filename + ".som"
self._parser = Parser(FileReader(fname), universe)
result = self._compile(system_class, universe)
cname = result.get_name()
cnameC = cname.get_string()
if filename != cnameC:
raise ValueError("File name " + filename + " does not match class name " + cnameC)
return result
def compile_class_string(self, stream, system_class, universe):
self._parser = Parser(StringReader(stream), universe)
result = self._compile(system_class, universe)
return result
def _compile(self, system_class, universe):
cgc = ClassGenerationContext(universe)
result = system_class
self._parser.classdef(cgc)
if not system_class:
result = cgc.assemble()
else:
cgc.assemble_system_class(result)
return result
# Symbol is a 'lightweight' enum, in Python 3.4, we could use Enum as superclass
class Symbol(object):
NONE = -1
Integer = 0
Not = 1
And = 2
Or = 3
Star = 4
Div = 5
Mod = 6
Plus = 7
Minus = 8
Equal = 9
More = 10
Less = 11
Comma = 12
At = 13
Per = 14
NewBlock = 15
EndBlock = 16
Colon = 17
Period = 18
Exit = 19
Assign = 20
NewTerm = 21
EndTerm = 22
Pound = 23
Primitive = 24
Separator = 25
STString = 26
Identifier = 27
Keyword = 28
KeywordSequence = 29
OperatorSequence = 30
...@@ -5,6 +5,8 @@ from som.vmobjects.clazz import Class ...@@ -5,6 +5,8 @@ from som.vmobjects.clazz import Class
from som.vmobjects.array import Array from som.vmobjects.array import Array
from som.vmobjects.symbol import Symbol from som.vmobjects.symbol import Symbol
import som.compiler.sourcecode_compiler as sourcecode_compiler
import os import os
class Universe(object): class Universe(object):
...@@ -353,10 +355,10 @@ class Universe(object): ...@@ -353,10 +355,10 @@ class Universe(object):
for cpEntry in self._classpath: for cpEntry in self._classpath:
try: try:
# Load the class from a file and return the loaded class # Load the class from a file and return the loaded class
result = SourcecodeCompiler.compile_class(cpEntry, name.getString(), system_class, self) result = sourcecode_compiler.compile_class_from_file(cpEntry, name.get_string(), system_class, self)
if self._dump_bytecodes: if self._dump_bytecodes:
Disassembler.dump(result.get_class()) Disassembler.dump(result.get_class())
Disassembler.dump(result) Disassembler.dump(result)
return result return result
except IOError: except IOError:
......
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