GitLab will be upgraded to the 12.10.14-ce.0 on 28 Sept 2020 at 2.00pm (AEDT) to 2.30pm (AEDT). During the update, GitLab and Mattermost services will not be available. If you have any concerns with this, please talk to us at N110 (b) CSIT building.

Commit aa5e2d0d authored by Stefan Marr's avatar Stefan Marr

Move primitives to top level and make sure they are not closures

Signed-off-by: default avatarStefan Marr <git@stefan-marr.de>
parent d3108714
......@@ -6,6 +6,9 @@ class Interpreter(object):
self._universe = universe
self._frame = None
def get_universe(self):
return self._universe
def _do_dup(self):
# Handle the dup bytecode
self.get_frame().push(self.get_frame().get_stack_element(0))
......
from som.vmobjects.primitive import Primitive
from som.primitives.primitives import Primitives
def _at(ivkbl, frame, interpreter):
i = frame.pop()
rcvr = frame.pop()
frame.push(rcvr.get_indexable_field(i.get_embedded_integer() - 1))
def _atPut(ivkbl, frame, interpreter):
value = frame.pop()
index = frame.pop()
rcvr = frame.get_stack_element(0)
rcvr.set_indexable_field(index.get_embedded_integer() - 1, value)
def _length(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(interpreter.get_universe().new_integer(rcvr.get_number_of_indexable_fields()))
def _new(ivkbl, frame, interpreter):
length = frame.pop()
frame.pop() # not required
frame.push(interpreter.get_universe().new_array_with_length(length.get_embedded_integer()))
class ArrayPrimitives(Primitives):
def install_primitives(self):
def _at(ivkbl, frame, interpreter):
i = frame.pop()
rcvr = frame.pop()
frame.push(rcvr.get_indexable_field(i.get_embedded_integer() - 1))
self._install_instance_primitive(Primitive("at:", self._universe, _at))
def _atPut(ivkbl, frame, interpreter):
value = frame.pop()
index = frame.pop()
rcvr = frame.get_stack_element(0)
rcvr.set_indexable_field(index.get_embedded_integer() - 1, value)
self._install_instance_primitive(Primitive("at:put:", self._universe, _atPut))
def _length(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(self._universe.new_integer(rcvr.get_number_of_indexable_fields()))
self._install_instance_primitive(Primitive("length", self._universe, _length))
def _new(ivkbl, frame, interpreter):
length = frame.pop()
frame.pop() # not required
frame.push(self._universe.new_array_with_length(length.get_embedded_integer()))
self._install_class_primitive(Primitive("new:", self._universe, _new))
......@@ -4,102 +4,104 @@ from som.vmobjects.integer import integer_value_fits
import math
def _asString(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(interpreter.get_universe().new_string(str(rcvr.get_embedded_biginteger())))
def _sqrt(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(interpreter.get_universe().new_double(
math.sqrt(rcvr.get_embedded_biginteger())))
def _plus(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
# Do operation and perform conversion to Integer if required
result = left.get_embedded_biginteger() + right_obj.get_embedded_value()
if integer_value_fits(result):
frame.push(interpreter.get_universe().new_integer(result))
else:
frame.push(interpreter.get_universe().new_biginteger(result))
def _minus(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
# Do operation and perform conversion to Integer if required
result = left.get_embedded_biginteger() - right_obj.get_embedded_value()
if integer_value_fits(result):
frame.push(interpreter.get_universe().new_integer(result))
else:
frame.push(interpreter.get_universe().new_biginteger(result))
def _mult(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
# Do operation and perform conversion to Integer if required
result = left.get_embedded_biginteger() * right_obj.get_embedded_value()
if integer_value_fits(result):
frame.push(interpreter.get_universe().new_integer(result))
else:
frame.push(interpreter.get_universe().new_biginteger(result))
def _div(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
# Do operation and perform conversion to Integer if required
result = left.get_embedded_biginteger() / right_obj.get_embedded_value()
if integer_value_fits(result):
frame.push(interpreter.get_universe().new_integer(result))
else:
frame.push(interpreter.get_universe().new_biginteger(result))
def _mod(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
# Do operation:
frame.push(interpreter.get_universe().new_biginteger(left.get_embedded_biginteger() % right_obj.get_embedded_value()))
def _and(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
# Do operation:
frame.push(interpreter.get_universe().new_biginteger(left.get_embedded_biginteger() & right_obj.get_embedded_value()))
def _equals(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
# Do operation:
if left.get_embedded_biginteger() == right_obj.get_embedded_value():
frame.push(interpreter.get_universe().trueObject)
else:
frame.push(interpreter.get_universe().falseObject)
def _lessThan(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
# Do operation:
if left.get_embedded_biginteger() < right_obj.get_embedded_value():
frame.push(interpreter.get_universe().trueObject)
else:
frame.push(interpreter.get_universe().falseObject)
class BigIntegerPrimitives(Primitives):
def install_primitives(self):
def _asString(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(self._universe.new_string(str(rcvr.get_embedded_biginteger())))
self._install_instance_primitive(Primitive("asString", self._universe, _asString))
def _sqrt(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(self._universe.new_double(
math.sqrt(rcvr.get_embedded_biginteger())))
self._install_instance_primitive(Primitive("sqrt", self._universe, _sqrt))
def _plus(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
# Do operation and perform conversion to Integer if required
result = left.get_embedded_biginteger() + right_obj.get_embedded_value()
if integer_value_fits(result):
frame.push(self._universe.new_integer(result))
else:
frame.push(self._universe.new_biginteger(result))
self._install_instance_primitive(Primitive("+", self._universe, _plus))
def _minus(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
# Do operation and perform conversion to Integer if required
result = left.get_embedded_biginteger() - right_obj.get_embedded_value()
if integer_value_fits(result):
frame.push(self._universe.new_integer(result))
else:
frame.push(self._universe.new_biginteger(result))
self._install_instance_primitive(Primitive("-", self._universe, _minus))
def _mult(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
# Do operation and perform conversion to Integer if required
result = left.get_embedded_biginteger() * right_obj.get_embedded_value()
if integer_value_fits(result):
frame.push(self._universe.new_integer(result))
else:
frame.push(self._universe.new_biginteger(result))
self._install_instance_primitive(Primitive("*", self._universe, _mult))
def _div(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
# Do operation and perform conversion to Integer if required
result = left.get_embedded_biginteger() / right_obj.get_embedded_value()
if integer_value_fits(result):
frame.push(self._universe.new_integer(result))
else:
frame.push(self._universe.new_biginteger(result))
self._install_instance_primitive(Primitive("/", self._universe, _div))
def _mod(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
# Do operation:
frame.push(self._universe.new_biginteger(left.get_embedded_biginteger() % right_obj.get_embedded_value()))
self._install_instance_primitive(Primitive("%", self._universe, _mod))
def _and(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
# Do operation:
frame.push(self._universe.new_biginteger(left.get_embedded_biginteger() & right_obj.get_embedded_value()))
self._install_instance_primitive(Primitive("&", self._universe, _and))
def _equals(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
# Do operation:
if left.get_embedded_biginteger() == right_obj.get_embedded_value():
frame.push(self._universe.trueObject)
else:
frame.push(self._universe.falseObject)
self._install_instance_primitive(Primitive("=", self._universe, _equals))
def _lessThan(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
# Do operation:
if left.get_embedded_biginteger() < right_obj.get_embedded_value():
frame.push(self._universe.trueObject)
else:
frame.push(self._universe.falseObject)
self._install_instance_primitive(Primitive("<", self._universe, _lessThan))
self._install_instance_primitive(Primitive("sqrt", self._universe, _sqrt))
self._install_instance_primitive(Primitive("+", self._universe, _plus))
self._install_instance_primitive(Primitive("-", self._universe, _minus))
self._install_instance_primitive(Primitive("*", self._universe, _mult))
self._install_instance_primitive(Primitive("/", self._universe, _div))
self._install_instance_primitive(Primitive("%", self._universe, _mod))
self._install_instance_primitive(Primitive("&", self._universe, _and))
self._install_instance_primitive(Primitive("=", self._universe, _equals))
self._install_instance_primitive(Primitive("<", self._universe, _lessThan))
from som.primitives.primitives import Primitives
from som.vmobjects.primitive import Primitive
def _restart(ivkbl, frame, interpreter):
frame.set_bytecode_index(0)
frame.reset_stack_pointer()
class BlockPrimitives(Primitives):
def install_primitives(self):
def _restart(ivkbl, frame, interpreter):
frame.set_bytecode_index(0)
frame.reset_stack_pointer()
def install_primitives(self):
self._install_instance_primitive(Primitive("restart", self._universe, _restart))
......@@ -2,9 +2,10 @@ from som.primitives.primitives import Primitives
from som.vmobjects.primitive import Primitive
def _new(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(interpreter.get_universe().new_instance(rcvr))
class ClassPrimitives(Primitives):
def install_primitives(self):
def _new(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(self._universe.new_instance(rcvr))
self._install_instance_primitive(Primitive("new", self._universe, _new))
\ No newline at end of file
......@@ -5,75 +5,75 @@ from som.vmobjects.integer import Integer
import math
class DoublePrimitives(Primitives):
def _coerce_to_double(obj, universe):
if isinstance(obj, Double):
return obj
if isinstance(obj, Integer):
return universe.new_double(obj.get_embedded_integer())
raise ValueError("Cannot coerce %s to Double!" % obj)
def _coerce_to_double(self, obj):
if isinstance(obj, Double):
return obj
if isinstance(obj, Integer):
return self._universe.new_double(obj.get_embedded_integer())
raise ValueError("Cannot coerce %s to Double!" % obj)
def _asString(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(interpreter.get_universe().new_string(str(rcvr.get_embedded_double())))
def install_primitives(self):
def _asString(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(self._universe.new_string(str(rcvr.get_embedded_double())))
self._install_instance_primitive(Primitive("asString", self._universe, _asString))
def _sqrt(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(interpreter.get_universe().new_double(math.sqrt(rcvr.get_embedded_double())))
def _sqrt(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(self._universe.new_double(math.sqrt(rcvr.get_embedded_double())))
self._install_instance_primitive(Primitive("sqrt", self._universe, _sqrt))
def _plus(ivkbl, frame, interpreter):
op1 = _coerce_to_double(frame.pop(), interpreter.get_universe())
op2 = frame.pop()
frame.push(interpreter.get_universe().new_double(op1.get_embedded_double()
+ op2.get_embedded_double()))
def _plus(ivkbl, frame, interpreter):
op1 = self._coerce_to_double(frame.pop())
op2 = frame.pop()
frame.push(self._universe.new_double(op1.get_embedded_double()
+ op2.get_embedded_double()))
self._install_instance_primitive(Primitive("+", self._universe, _plus))
def _minus(ivkbl, frame, interpreter):
op1 = _coerce_to_double(frame.pop(), interpreter.get_universe())
op2 = frame.pop()
frame.push(interpreter.get_universe().new_double(op2.get_embedded_double()
- op1.get_embedded_double()))
def _mult(ivkbl, frame, interpreter):
op1 = _coerce_to_double(frame.pop(), interpreter.get_universe())
op2 = frame.pop()
frame.push(interpreter.get_universe().new_double(op2.get_embedded_double()
* op1.get_embedded_double()))
def _minus(ivkbl, frame, interpreter):
op1 = self._coerce_to_double(frame.pop())
op2 = frame.pop()
frame.push(self._universe.new_double(op2.get_embedded_double()
- op1.get_embedded_double()))
self._install_instance_primitive(Primitive("-", self._universe, _minus))
def _doubleDiv(ivkbl, frame, interpreter):
op1 = _coerce_to_double(frame.pop(), interpreter.get_universe())
op2 = frame.pop()
frame.push(interpreter.get_universe().new_double(op2.get_embedded_double()
/ op1.get_embedded_double()))
def _mult(ivkbl, frame, interpreter):
op1 = self._coerce_to_double(frame.pop())
op2 = frame.pop()
frame.push(self._universe.new_double(op2.get_embedded_double()
* op1.get_embedded_double()))
self._install_instance_primitive(Primitive("*", self._universe, _mult))
def _mod(ivkbl, frame, interpreter):
op1 = _coerce_to_double(frame.pop(), interpreter.get_universe())
op2 = frame.pop()
frame.push(interpreter.get_universe().new_double(op2.get_embedded_double()
% op1.get_embedded_double()))
def _doubleDiv(ivkbl, frame, interpreter):
op1 = self._coerce_to_double(frame.pop())
op2 = frame.pop()
frame.push(self._universe.new_double(op2.get_embedded_double()
/ op1.get_embedded_double()))
self._install_instance_primitive(Primitive("//", self._universe, _doubleDiv))
def _equals(ivkbl, frame, interpreter):
op1 = _coerce_to_double(frame.pop(), interpreter.get_universe())
op2 = frame.pop()
if op1.get_embedded_double() == op2.get_embedded_double():
frame.push(interpreter.get_universe().trueObject)
else:
frame.push(interpreter.get_universe().falseObject)
def _mod(ivkbl, frame, interpreter):
op1 = self._coerce_to_double(frame.pop())
op2 = frame.pop()
frame.push(self._universe.new_double(op2.get_embedded_double()
% op1.get_embedded_double()))
self._install_instance_primitive(Primitive("%", self._universe, _mod))
def _lessThan(ivkbl, frame, interpreter):
op1 = _coerce_to_double(frame.pop(), interpreter.get_universe())
op2 = frame.pop()
if op2.get_embedded_double() < op1.get_embedded_double():
frame.push(interpreter.get_universe().trueObject)
else:
frame.push(interpreter.get_universe().falseObject)
def _equals(ivkbl, frame, interpreter):
op1 = self._coerce_to_double(frame.pop())
op2 = frame.pop()
if op1.get_embedded_double() == op2.get_embedded_double():
frame.push(self._universe.trueObject)
else:
frame.push(self._universe.falseObject)
self._install_instance_primitive(Primitive("=", self._universe, _equals))
class DoublePrimitives(Primitives):
def _lessThan(ivkbl, frame, interpreter):
op1 = self._coerce_to_double(frame.pop())
op2 = frame.pop()
if op2.get_embedded_double() < op1.get_embedded_double():
frame.push(self._universe.trueObject)
else:
frame.push(self._universe.falseObject)
self._install_instance_primitive(Primitive("<", self._universe, _lessThan))
def install_primitives(self):
self._install_instance_primitive(Primitive("asString", self._universe, _asString))
self._install_instance_primitive(Primitive("sqrt", self._universe, _sqrt))
self._install_instance_primitive(Primitive("+", self._universe, _plus))
self._install_instance_primitive(Primitive("-", self._universe, _minus))
self._install_instance_primitive(Primitive("*", self._universe, _mult))
self._install_instance_primitive(Primitive("//", self._universe, _doubleDiv))
self._install_instance_primitive(Primitive("%", self._universe, _mod))
self._install_instance_primitive(Primitive("=", self._universe, _equals))
self._install_instance_primitive(Primitive("<", self._universe, _lessThan))
This diff is collapsed.
......@@ -3,73 +3,73 @@ from som.primitives.primitives import Primitives
from som.vmobjects.primitive import Primitive
from som.vmobjects.array import Array
class ObjectPrimitives(Primitives):
def install_primitives(self):
def _equals(ivkbl, frame, interpreter):
op1 = frame.pop()
op2 = frame.pop()
if op1 is op2:
frame.push(self._universe.trueObject)
else:
frame.push(self._universe.falseObject)
self._install_instance_primitive(Primitive("==", self._universe, _equals))
def _hashcode(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(self._universe.new_integer(hash(rcvr)))
self._install_instance_primitive(Primitive("hashcode", self._universe, _hashcode))
def _equals(ivkbl, frame, interpreter):
op1 = frame.pop()
op2 = frame.pop()
if op1 is op2:
frame.push(interpreter.get_universe().trueObject)
else:
frame.push(interpreter.get_universe().falseObject)
def _hashcode(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(interpreter.get_universe().new_integer(hash(rcvr)))
def _objectSize(ivkbl, frame, interpreter):
rcvr = frame.pop()
size = rcvr.get_number_of_fields()
if isinstance(rcvr, Array):
size += rcvr.get_number_of_indexable_fields()
frame.push(self._universe.new_integer(size))
self._install_instance_primitive(Primitive("objectSize", self._universe, _objectSize))
def _objectSize(ivkbl, frame, interpreter):
rcvr = frame.pop()
size = rcvr.get_number_of_fields()
if isinstance(rcvr, Array):
size += rcvr.get_number_of_indexable_fields()
def _perform(ivkbl, frame, interpreter):
selector = frame.pop()
rcvr = frame.get_stack_element(0)
frame.push(interpreter.get_universe().new_integer(size))
invokable = rcvr.get_class().lookup_invokable(selector)
invokable.invoke(frame, interpreter)
self._install_instance_primitive(Primitive("perform:", self._universe, _perform))
def _perform(ivkbl, frame, interpreter):
selector = frame.pop()
rcvr = frame.get_stack_element(0)
def _performInSuperclass(ivkbl, frame, interpreter):
clazz = frame.pop()
selector = frame.pop()
rcvr = frame.get_stack_element(0)
invokable = rcvr.get_class().lookup_invokable(selector)
invokable.invoke(frame, interpreter)
invokable = clazz.lookup_invokable(selector)
invokable.invoke(frame, interpreter)
self._install_instance_primitive(Primitive("perform:inSuperclass:", self._universe, _performInSuperclass))
def _performInSuperclass(ivkbl, frame, interpreter):
clazz = frame.pop()
selector = frame.pop()
rcvr = frame.get_stack_element(0)
def _performWithArguments(ivkbl, frame, interpreter):
args = frame.pop()
selector = frame.pop()
rcvr = frame.get_stack_element(0)
invokable = clazz.lookup_invokable(selector)
invokable.invoke(frame, interpreter)
for i in range(0, args.get_number_of_indexable_fields()):
frame.push(args.get_indexable_field(i))
def _performWithArguments(ivkbl, frame, interpreter):
args = frame.pop()
selector = frame.pop()
rcvr = frame.get_stack_element(0)
invokable = rcvr.get_class().lookup_invokable(selector)
invokable.invoke(frame, interpreter)
self._install_instance_primitive(Primitive("perform:withArguments:", self._universe, _performWithArguments))
for i in range(0, args.get_number_of_indexable_fields()):
frame.push(args.get_indexable_field(i))
def _instVarAt(ivkbl, frame, interpreter):
idx = frame.pop()
rcvr = frame.pop()
invokable = rcvr.get_class().lookup_invokable(selector)
invokable.invoke(frame, interpreter)
frame.push(rcvr.get_field(idx.get_embedded_integer() - 1))
self._install_instance_primitive(Primitive("instVarAt:", self._universe, _instVarAt))
def _instVarAt(ivkbl, frame, interpreter):
idx = frame.pop()
rcvr = frame.pop()
frame.push(rcvr.get_field(idx.get_embedded_integer() - 1))
def _instVarAtPut(ivkbl, frame, interpreter):
val = frame.pop()
idx = frame.pop()
rcvr = frame.get_stack_element(0)
def _instVarAtPut(ivkbl, frame, interpreter):
val = frame.pop()
idx = frame.pop()
rcvr = frame.get_stack_element(0)
rcvr.set_field(idx.get_embedded_integer() - 1, val)
rcvr.set_field(idx.get_embedded_integer() - 1, val)
class ObjectPrimitives(Primitives):
def install_primitives(self):
self._install_instance_primitive(Primitive("==", self._universe, _equals))
self._install_instance_primitive(Primitive("hashcode", self._universe, _hashcode))
self._install_instance_primitive(Primitive("objectSize", self._universe, _objectSize))
self._install_instance_primitive(Primitive("perform:", self._universe, _perform))
self._install_instance_primitive(Primitive("perform:inSuperclass:", self._universe, _performInSuperclass))
self._install_instance_primitive(Primitive("perform:withArguments:", self._universe, _performWithArguments))
self._install_instance_primitive(Primitive("instVarAt:", self._universe, _instVarAt))
self._install_instance_primitive(Primitive("instVarAt:put:", self._universe, _instVarAtPut))
from som.primitives.primitives import Primitives
from som.vmobjects.primitive import Primitive
def _concat(ivkbl, frame, interpreter):
argument = frame.pop()
rcvr = frame.pop()
frame.push(interpreter.get_universe().new_string(rcvr.get_embedded_string()
+ argument.get_embedded_string()))
def _asSymbol(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(interpreter.get_universe().symbol_for(rcvr.get_embedded_string()))
def _length(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(interpreter.get_universe().new_integer(rcvr.get_embedded_string().length()))
def _equals(ivkbl, frame, interpreter):
op1 = frame.pop()
op2 = frame.pop() # rcvr
if op1.get_class() == interpreter.get_universe().stringClass:
if op1.get_embedded_string() == op2.get_embedded_string():
frame.push(interpreter.get_universe().trueObject)
return
frame.push(interpreter.get_universe().falseObject)
def _substring(ivkbl, frame, interpreter):
end = frame.pop()
start = frame.pop()
rcvr = frame.pop()
try:
frame.push(interpreter.get_universe().new_string(rcvr.get_embedded_string()[
start.get_embedded_integer():end.get_embedded_integer() + 1]))
except IndexError, e:
frame.push(interpreter.get_universe().new_string("Error - index out of bounds: %s" % e))
def _hashcode(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(interpreter.get_universe().new_integer(hash(rcvr.get_embedded_string())))
class StringPrimitives(Primitives):
def install_primitives(self):
def _concat(ivkbl, frame, interpreter):
argument = frame.pop()
rcvr = frame.pop()
frame.push(self._universe.new_string(rcvr.get_embedded_string()
+ argument.get_embedded_string()))
self._install_instance_primitive(Primitive("concatenate:", self._universe, _concat))
def _asSymbol(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(self._universe.symbol_for(rcvr.get_embedded_string()))
self._install_instance_primitive(Primitive("asSymbol", self._universe, _asSymbol))
def _length(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(self._universe.new_integer(rcvr.get_embedded_string().length()))
self._install_instance_primitive(Primitive("length", self._universe, _length))
def _equals(ivkbl, frame, interpreter):
op1 = frame.pop()
op2 = frame.pop() # rcvr
if op1.get_class() == self._universe.stringClass:
if op1.get_embedded_string() == op2.get_embedded_string():
frame.push(self._universe.trueObject)
return
frame.push(self._universe.falseObject)
self._install_instance_primitive(Primitive("=", self._universe, _equals))
def _substring(ivkbl, frame, interpreter):
end = frame.pop()
start = frame.pop()
rcvr = frame.pop()
try:
frame.push(self._universe.new_string(rcvr.get_embedded_string()[
start.get_embedded_integer():end.get_embedded_integer() + 1]))
except IndexError, e:
frame.push(self._universe.new_string("Error - index out of bounds: %s" % e))
def install_primitives(self):
self._install_instance_primitive(Primitive("concatenate:", self._universe, _concat))
self._install_instance_primitive(Primitive("asSymbol", self._universe, _asSymbol))
self._install_instance_primitive(Primitive("length", self._universe, _length))
self._install_instance_primitive(Primitive("=", self._universe, _equals))
self._install_instance_primitive(Primitive("primSubstringFrom:to:", self._universe, _substring))
def _hashcode(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(self._universe.new_integer(hash(rcvr.get_embedded_string())))
self._install_instance_primitive(Primitive("hashcode", self._universe, _hashcode))
self._install_instance_primitive(Primitive("hashcode", self._universe, _hashcode))
from som.primitives.primitives import Primitives
from som.vmobjects.primitive import Primitive
def _asString(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(interpreter.get_universe().new_string(rcvr.get_string()))
class SymbolPrimitives(Primitives):
def install_primitives(self):
def _asString(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(self._universe.new_string(rcvr.get_string()))
self._install_instance_primitive(Primitive("asString", self._universe, _asString))