Commit fde1d988 authored by Carl Friedrich Bolz's avatar Carl Friedrich Bolz

put the Block classes into an array

the computation of the key and the global lookup was reaaaaally
parent a47c9c23
......@@ -51,6 +51,7 @@ class Universe(object):
self.primitiveClass = None
self.systemClass = None
self.blockClass = None
self.blockClasses = None
self.stringClass = None
self.doubleClass = None
......@@ -279,7 +280,10 @@ class Universe(object):
self.set_global( trueClassName, trueClass)
self.set_global(falseClassName, falseClass)
self.blockClasses = [self.blockClass] + \
[self._make_block_class(i) for i in [1, 2, 3]]
return system_object
def symbol_for(self, string):
......@@ -488,21 +492,15 @@ class Universe(object):
def has_global(self, name):
# 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):
if not number_of_arguments:
# Get the generic block class
return self.blockClass
def _get_block_class(self, number_of_arguments):
return self.blockClasses[number_of_arguments]
def _make_block_class(self, number_of_arguments):
# Compute the name of the block class with the given number of
# arguments
name = self.symbol_for("Block" + str(number_of_arguments))
# Lookup the specific block class in the dictionary of globals and
# return it
if self.has_global(name):
return self.get_global(name)
# Get the block class for blocks with the given number of arguments
result = self._load_class(name, None)
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