To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

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
from som.vmobjects.array import Array
from som.vmobjects.symbol import Symbol
import som.compiler.sourcecode_compiler as sourcecode_compiler
import os
class Universe(object):
......@@ -353,10 +355,10 @@ class Universe(object):
for cpEntry in self._classpath:
try:
# 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:
Disassembler.dump(result.get_class())
Disassembler.dump(result)
Disassembler.dump(result.get_class())
Disassembler.dump(result)
return result
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