Commit 94e260e1 authored by Stefan Marr's avatar Stefan Marr

Moving the class field to the VM-level object and make its getter a primitive

Signed-off-by: 's avatarStefan Marr <git@stefan-marr.de>
parent eb282e9a
Subproject commit b05a5737bfd6e06f44ddd5884a351e3df3859bea
Subproject commit 52ca605afc001e0f774871d027550ff2491422c3
......@@ -68,6 +68,10 @@ def _instVarAtPut(ivkbl, frame, interpreter):
def _halt(ivkbl, frame, interpreter):
# noop
print "BREAKPOINT"
def _class(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(rcvr.get_class())
......@@ -84,4 +88,5 @@ class ObjectPrimitives(Primitives):
self._install_instance_primitive(Primitive("instVarAt:put:", self._universe, _instVarAtPut))
self._install_instance_primitive(Primitive("halt", self._universe, _halt))
self._install_instance_primitive(Primitive("class", self._universe, _class))
......@@ -3,7 +3,7 @@ from som.vmobjects.primitive import Primitive
class Block(Object):
METHOD_INDEX = 1 + Object.CLASS_INDEX
METHOD_INDEX = Object.NUMBER_OF_OBJECT_FIELDS
CONTEXT_INDEX = 1 + METHOD_INDEX
NUMBER_OF_BLOCK_FIELDS = 1 + CONTEXT_INDEX
......
......@@ -4,7 +4,7 @@ from som.primitives.primitives import Primitives
class Class(Object):
# Static field indices and number of class fields
SUPER_CLASS_INDEX = 1 + Object.CLASS_INDEX
SUPER_CLASS_INDEX = Object.NUMBER_OF_OBJECT_FIELDS
NAME_INDEX = 1 + SUPER_CLASS_INDEX
INSTANCE_FIELDS_INDEX = 1 + NAME_INDEX
INSTANCE_INVOKABLES_INDEX = 1 + INSTANCE_FIELDS_INDEX
......
......@@ -14,7 +14,7 @@ from som.vmobjects.array import Array
class Frame(Array):
# Static field indices and number of frame fields
PREVIOUS_FRAME_INDEX = 1 + Array.CLASS_INDEX
PREVIOUS_FRAME_INDEX = Array.NUMBER_OF_OBJECT_FIELDS
CONTEXT_INDEX = 1 + PREVIOUS_FRAME_INDEX
METHOD_INDEX = 1 + CONTEXT_INDEX
NUMBER_OF_FRAME_FIELDS = 1 + METHOD_INDEX
......
......@@ -7,7 +7,7 @@ from som.interpreter.bytecodes import bytecode_length
class Method(Array):
# Static field indices and number of method fields
SIGNATURE_INDEX = 1 + Array.CLASS_INDEX
SIGNATURE_INDEX = Array.NUMBER_OF_OBJECT_FIELDS
HOLDER_INDEX = 1 + SIGNATURE_INDEX
NUMBER_OF_METHOD_FIELDS = 1 + HOLDER_INDEX
......
class Object(object):
# Static field indices and number of object fields
CLASS_INDEX = 0
NUMBER_OF_OBJECT_FIELDS = 1 + CLASS_INDEX
NUMBER_OF_OBJECT_FIELDS = 0
def __init__(self, nilObject, number_of_fields = -1):
num_fields = number_of_fields if number_of_fields != -1 else self._get_default_number_of_fields()
self._fields = [nilObject] * num_fields
self._class = 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)
return self._class
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)
self._class = value
def get_field_name(self, index):
# Get the name of the field with the given index
......
......@@ -3,7 +3,7 @@ from som.vmobjects.object import Object
class Primitive(Object):
# Static field indices and number of primitive fields
SIGNATURE_INDEX = 1 + Object.CLASS_INDEX
SIGNATURE_INDEX = Object.NUMBER_OF_OBJECT_FIELDS
HOLDER_INDEX = 1 + SIGNATURE_INDEX
NUMBER_OF_PRIMITIVE_FIELDS = 1 + HOLDER_INDEX
......
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