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.

Commit 114fa2ab authored by Stefan Marr's avatar Stefan Marr
Browse files

Started Object and Class implementation


Signed-off-by: default avatarStefan Marr <git@stefan-marr.de>
parent fdb3be28
from som.interpreter.interpreter import Interpreter from som.interpreter.interpreter import Interpreter
from som.vm.symbol_table import SymbolTable from som.vm.symbol_table import SymbolTable
from som.vmobjects.object import Object from som.vmobjects.object import Object
from som.vmobjects.clazz import Class
import os import os
...@@ -34,7 +35,10 @@ class Universe(object): ...@@ -34,7 +35,10 @@ class Universe(object):
self._last_exit_code = 0 self._last_exit_code = 0
self._classpath = None self._classpath = None
self._dump_bytecodes = False self._dump_bytecodes = False
@property
def nilObject(self):
return self._nilObject
def interpret(self, arguments): def interpret(self, arguments):
...@@ -113,7 +117,7 @@ class Universe(object): ...@@ -113,7 +117,7 @@ class Universe(object):
self._doubleClass = self.new_system_class() self._doubleClass = self.new_system_class()
# Setup the class reference for the nil object # Setup the class reference for the nil object
self._nilObject.setClass(self._nilClass) self._nilObject.set_class(self._nilClass)
# Initialize the system classes # Initialize the system classes
self._initialize_system_class(self._objectClass, None, "Object") self._initialize_system_class(self._objectClass, None, "Object")
...@@ -162,4 +166,15 @@ class Universe(object): ...@@ -162,4 +166,15 @@ class Universe(object):
self.setGlobal(self.symbol_for("false"), self._falseObject) self.setGlobal(self.symbol_for("false"), self._falseObject)
self.setGlobal(self.symbol_for("system"), self._systemObject) self.setGlobal(self.symbol_for("system"), self._systemObject)
self.setGlobal(self.symbol_for("System"), self._systemClass) self.setGlobal(self.symbol_for("System"), self._systemClass)
self.setGlobal(self.symbol_for("Block"), self._blockClass) self.setGlobal(self.symbol_for("Block"), self._blockClass)
\ No newline at end of file
def new_metaclass_class(self):
# Allocate the metaclass classes
result = Class(self)
result.set_class(Class(self))
# Setup the metaclass hierarchy
result.get_class().set_class(result)
# Return the freshly allocated metaclass class
return result
from som.vmobjects.object import Object
class Class(Object):
# Static field indices and number of class fields
SUPER_CLASS_INDEX = 1 + Object.CLASS_INDEX
NAME_INDEX = 1 + SUPER_CLASS_INDEX
INSTANCE_FIELDS_INDEX = 1 + NAME_INDEX
INSTANCE_INVOKABLES_INDEX = 1 + INSTANCE_FIELDS_INDEX
NUMBER_OF_CLASS_FIELDS = 1 + INSTANCE_INVOKABLES_INDEX
def __init__(self, universe, number_of_fields = None):
super(Class, self).__init__(universe.nilObject, number_of_fields)
self._invokables_table = {}
self._universe = universe
def get_super_class(self):
# Get the super class by reading the field with super class index
return self.get_field(self.SUPER_CLASS_INDEX)
def set_super_class(self, value):
# Set the super class by writing to the field with super class index
self.set_field(self.SUPER_CLASS_INDEX, value)
def has_super_class(self):
# 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)
def set_name(self, value):
# Set the name of this class by writing to the field with name index
self.set_field(self.NAME_INDEX, value)
def get_instance_fields(self):
# Get the instance fields by reading the field with the instance fields index
return self.get_field(self.INSTANCE_FIELD_INDEX)
def set_instance_fields(self, value):
# Set the instance fields by writing to the field with the instance fields index
self.set_field(self.INSTANCE_FIELD_INDEX, value)
class Object(object): class Object(object):
# Static field indices and number of object fields
CLASS_INDEX = 0
NUMBER_OF_OBJECT_FIELDS = 1 + CLASS_INDEX
def __init__(self, nilObject): def __init__(self, nilObject, number_of_fields = None):
pass num_fields = number_of_fields if number_of_fields else self._get_default_number_of_fields()
self._fields = None
\ No newline at end of file self.set_number_of_fields_and_clear(num_fields, nilObject)
def get_class(self):
# Get the class of this object by reading the field with class index
return self.get_field(self.CLASS_INDEX)
def set_class(self, value):
# Set the class of this object by writing to the field with class index
self.set_field(self.CLASS_INDEX, value)
def get_field_name(self, index):
# Get the name of the field with the given index
return self.get_class().get_instance_field_name(index)
def get_field_index(self, name):
# Get the index for the field with the given name
return self.get_class().lookup_field_fndex(name)
def get_number_of_fields(self):
# Get the number of fields in this object
return len(self._fields)
def set_number_of_fields_and_clear(self, value, nilObject):
# Allocate a new array of fields
self._fields = [nilObject] * value
def _get_default_number_of_fields(self):
# Return the default number of fields in an object
return self.NUMBER_OF_OBJECT_FIELDS
def get_field(self, index):
# Get the field with the given index
return self._fields[index]
def set_field(self, index, value):
# Set the field with the given index to the given value
self._fields[index] = value
\ No newline at end of file
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