Commit de7fa071 authored by Stefan Marr's avatar Stefan Marr

Add more of the missing functionality in Universe

Signed-off-by: default avatarStefan Marr <>
parent a17e2429
from __future__ import print_function
from som.interpreter.interpreter import Interpreter
from som.vm.symbol_table import SymbolTable
from som.vmobjects.object import Object
from som.vmobjects.clazz import Class
from som.vmobjects.array import Array
from som.vmobjects.symbol import Symbol
from som.vmobjects.method import Method
import som.compiler.sourcecode_compiler as sourcecode_compiler
......@@ -228,6 +231,107 @@ class Universe(object):
# Return the allocated and initialized array
return result
def new_block(self, method, context_frame, arguments):
# Allocate a new block and set its class to be the block class
result = Block(self._nilObject)
# Set the method and context of block
# Return the freshly allocated block
return result
def new_class(self, class_class):
# Allocate a new class and set its class to be the given class class
result = Class(class_class.get_number_of_instance_fields(), self)
# Return the freshly allocated class
return result
def new_frame(self, previous_frame, method):
# Allocate a new frame and set its class to be the frame class
result = Frame(self._nilObject)
# Compute the maximum number of stack locations (including arguments,
# locals and extra buffer to support doesNotUnderstand) and set the
# number of indexable fields accordingly
length = (method.get_number_of_arguments() +
method.get_number_of_locals().get_embedded_integer() +
method.get_maximum_number_of_stack_elements().get_embedded_integer() + 2)
result.set_number_of_indexable_fields_and_clear(length, self._nilObject)
# Set the method of the frame and the previous frame
if previous_frame:
# Reset the stack pointer and the bytecode index
# Return the freshly allocated frame
return result
def new_method(self, signature, num_bytecodes, num_literals):
# Allocate a new method and set its class to be the method class
result = Method(self._nilObject)
# Set the signature and the number of bytecodes
result.set_number_of_indexable_fields_and_clear(num_literals, self._nilObject)
# Return the freshly allocated method
return result
def new_instance(self, instance_class):
# Allocate a new instance and set its class to be the given class
result = Object(instance_class.get_number_of_instance_fields(), self._nilObject)
# Return the freshly allocated instance
return result
def new_integer(self, value):
# Allocate a new integer and set its class to be the integer class
result = Integer(self._nilObject)
# Set the embedded integer of the newly allocated integer
# Return the freshly allocated integer
return result
def new_big_integer(self, value):
# Allocate a new integer and set its class to be the integer class
result = BigInteger(self._nilObject)
# Set the embedded integer of the newly allocated integer
# Return the freshly allocated integer
return result
def new_double(self, value):
# Allocate a new integer and set its class to be the double class
result = Double(self._nilObject)
# Set the embedded double of the newly allocated double
# Return the freshly allocated double
return result
def new_metaclass_class(self):
# Allocate the metaclass classes
result = Class(self)
......@@ -238,6 +342,17 @@ class Universe(object):
# Return the freshly allocated metaclass class
return result
def new_string(self, embedded_string):
# Allocate a new string and set its class to be the string class
result = String(self._nilObject)
# Put the embedded string into the new string
# Return the freshly allocated string
return result
def new_symbol(self, string):
# Allocate a new symbol and set its class to be the symbol class
......@@ -306,7 +421,7 @@ class Universe(object):
# Returns if the universe has a value for the global of the given name
return name in self._globals
def get_block_class(self, number_of_arguments = None):
def _get_block_class(self, number_of_arguments = None):
if not number_of_arguments:
# Get the generic block class
return self._blockClass
......@@ -371,7 +486,29 @@ class Universe(object):
# The class could not be found.
return None
def load_shell_class(self, stmt):
# Load the class from a stream and return the loaded class
result = sourcecode_compiler.compile_class_from_string(stmt, None, self)
if self._dumpBytecodes:
return result
def error_print(cls, msg):
print(msg, file=sys.stderr, end="")
def error_println(cls, msg = ""):
print(msg, file=sys.stderr)
def print(cls, msg):
print(msg, end="")
def println(cls, msg=""):
def main(args):
u = Universe()
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment