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 86d632ba authored by Tobias Pape's avatar Tobias Pape Committed by Stefan Marr
Browse files

Make prmitive loading semi-dynamic

parent f0a645a8
# Captures the known primitives
class PrimitivesNotFound(Exception): pass
def _is_primitives_class(e):
from som.primitives.primitives import Primitives
import inspect
_, entry = e
return (inspect.isclass(entry) and
issubclass(entry, Primitives)
and entry is not Primitives)
def _setup_primitives():
from importlib import import_module
import inspect
import py
from pprint import pformat
directory = py.path.local(__file__).dirpath()
files = filter(lambda ent: ent.basename.endswith("_primitives.py"),
mods = map(lambda mod: import_module("som.primitives." + mod.purebasename),
all_members = map(lambda module: inspect.getmembers(module),
all_members = reduce(lambda all, each: all + each, all_members)
all_prims = filter(_is_primitives_class, all_members)
prim_pairs = map(lambda (name, cls):
(name[:name.find("Primitives")], cls),
return dict(prim_pairs)
_primitives = _setup_primitives()
def primitives_for_class(cls):
key = cls.get_name().get_string()
res = _primitives.get(key, None)
if res is None:
raise PrimitivesNotFound
return res
\ No newline at end of file
from som.vmobjects.object import Object
from som.primitives.primitives import Primitives
from importlib import import_module
import inspect
class Class(Object):
# Static field indices and number of class fields
......@@ -31,7 +28,6 @@ class Class(Object):
# Check whether or not this class has a super class
return self.get_field(self.SUPER_CLASS_INDEX) != self._universe.nilObject
def get_name(self):
# Get the name of this class by reading the field with name index
return self.get_field(self.NAME_INDEX)
......@@ -172,47 +168,18 @@ class Class(Object):
# Get the next invokable in the instance invokable array
if self.get_instance_invokable(i).is_primitive():
return True
return False
def load_primitives(self):
## We currently do not support dynamic loading of primitives.
## Dynamic loading might come later, based on the SPy solution of Lars.
# TODO: add support for dynamic loading!
# The hack for now hard codes the primitives for the classes of the
# standard library.
if self.get_name().get_string() == "Array":
from som.primitives.array_primitives import ArrayPrimitives
elif self.get_name().get_string() == "BigInteger":
from som.primitives.biginteger_primitives import BigIntegerPrimitives
elif self.get_name().get_string() == "Block":
from som.primitives.block_primitives import BlockPrimitives
elif self.get_name().get_string() == "Class":
from som.primitives.class_primitives import ClassPrimitives
elif self.get_name().get_string() == "Double":
from som.primitives.double_primitives import DoublePrimitives
elif self.get_name().get_string() == "Integer":
from som.primitives.integer_primitives import IntegerPrimitives
elif self.get_name().get_string() == "Object":
from som.primitives.object_primitives import ObjectPrimitives
elif self.get_name().get_string() == "String":
from som.primitives.string_primitives import StringPrimitives
elif self.get_name().get_string() == "Symbol":
from som.primitives.symbol_primitives import SymbolPrimitives
elif self.get_name().get_string() == "System":
from som.primitives.system_primitives import SystemPrimitives
from som.primitives.known import (primitives_for_class,
prims = primitives_for_class(self)
except PrimitivesNotFound:
prims = None
assert prims is not None, "We yet only support prims for known classes"
def replace_bytecodes(self):
cnt = self.get_number_of_instance_invokables()
for i in range(0, cnt):
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