Commit 5d001264 authored by Stefan Marr's avatar Stefan Marr

Sync whitespace in primitives

Signed-off-by: 's avatarStefan Marr <git@stefan-marr.de>
parent 4a9f0d81
......@@ -6,16 +6,19 @@ def _at(ivkbl, frame, interpreter):
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
......
......@@ -8,11 +8,13 @@ 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()
......@@ -24,6 +26,7 @@ def _plus(ivkbl, frame, interpreter):
else:
frame.push(interpreter.get_universe().new_biginteger(result))
def _minus(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
......@@ -35,6 +38,7 @@ def _minus(ivkbl, frame, interpreter):
else:
frame.push(interpreter.get_universe().new_biginteger(result))
def _mult(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
......@@ -46,6 +50,7 @@ def _mult(ivkbl, frame, interpreter):
else:
frame.push(interpreter.get_universe().new_biginteger(result))
def _div(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
......@@ -57,6 +62,7 @@ def _div(ivkbl, frame, interpreter):
else:
frame.push(interpreter.get_universe().new_biginteger(result))
def _mod(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
......@@ -71,6 +77,7 @@ def _and(ivkbl, frame, interpreter):
# 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()
......@@ -81,6 +88,7 @@ def _equals(ivkbl, frame, interpreter):
else:
frame.push(interpreter.get_universe().falseObject)
def _lessThan(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
......
......@@ -23,8 +23,6 @@ jitdriver = jit.JitDriver(
get_printable_location=get_printable_location)
def _execute_block(frame, block, block_method, interpreter, universe):
b = universe.new_block(block_method, block.get_context())
frame.push(b)
......@@ -32,6 +30,7 @@ def _execute_block(frame, block, block_method, interpreter, universe):
block_evaluate(b, interpreter, frame)
return frame.pop()
def _whileLoop(frame, interpreter, while_type):
loop_body = frame.pop()
loop_condition = frame.pop()
......@@ -55,9 +54,11 @@ def _whileLoop(frame, interpreter, while_type):
frame.push(universe.nilObject)
def _whileFalse(ivkbl, frame, interpreter):
_whileLoop(frame, interpreter, interpreter.get_universe().falseObject)
def _whileTrue(ivkbl, frame, interpreter):
_whileLoop(frame, interpreter, interpreter.get_universe().trueObject)
......
......@@ -2,22 +2,27 @@ 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))
def _name(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(rcvr.get_name())
def _super_class(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(rcvr.get_super_class())
def _methods(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(rcvr.get_instance_invokables())
def _fields(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(rcvr.get_instance_fields())
......
......@@ -8,6 +8,7 @@ from som.vmobjects.integer import Integer
import math
def _coerce_to_double(obj, universe):
if isinstance(obj, Double):
return obj
......@@ -15,39 +16,47 @@ def _coerce_to_double(obj, universe):
return universe.new_double(float(obj.get_embedded_integer()))
raise ValueError("Cannot coerce %s to Double!" % obj)
def _asString(ivkbl, frame, interpreter):
rcvr = frame.pop()
d = rcvr.get_embedded_double()
s = formatd(d, "g", DTSF_STR_PRECISION, DTSF_ADD_DOT_0)
frame.push(interpreter.get_universe().new_string(s))
def _sqrt(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(interpreter.get_universe().new_double(math.sqrt(rcvr.get_embedded_double())))
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 _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 _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 _mod(ivkbl, frame, interpreter):
op1 = _coerce_to_double(frame.pop(), interpreter.get_universe())
op2 = frame.pop()
......@@ -57,6 +66,7 @@ def _mod(ivkbl, frame, interpreter):
r = math.fmod(o1, o2)
frame.push(interpreter.get_universe().new_double(r))
def _equals(ivkbl, frame, interpreter):
op1 = _coerce_to_double(frame.pop(), interpreter.get_universe())
op2 = frame.pop()
......@@ -65,6 +75,7 @@ def _equals(ivkbl, frame, interpreter):
else:
frame.push(interpreter.get_universe().falseObject)
def _lessThan(ivkbl, frame, interpreter):
op1 = _coerce_to_double(frame.pop(), interpreter.get_universe())
op2 = frame.pop()
......@@ -73,6 +84,7 @@ def _lessThan(ivkbl, frame, interpreter):
else:
frame.push(interpreter.get_universe().falseObject)
def _and(ivkbl, frame, interpreter):
op1 = _coerce_to_double(frame.pop(), interpreter.get_universe())
op2 = frame.pop()
......@@ -82,6 +94,7 @@ def _and(ivkbl, frame, interpreter):
result = float(left & right)
frame.push(interpreter.get_universe().new_double(result))
def _bitXor(ivkbl, frame, interpreter):
op1 = _coerce_to_double(frame.pop(), interpreter.get_universe())
op2 = frame.pop()
......@@ -91,11 +104,13 @@ def _bitXor(ivkbl, frame, interpreter):
result = float(left ^ right)
frame.push(interpreter.get_universe().new_double(result))
def _round(ivkbl, frame, interpreter):
rcvr = frame.pop()
int_value = int(round_double(rcvr.get_embedded_double(), 0))
frame.push(interpreter.get_universe().new_integer(int_value))
class DoublePrimitives(Primitives):
def install_primitives(self):
......
......@@ -8,6 +8,7 @@ from som.vmobjects.block import block_evaluate
import math
def _push_long_result(frame, result, universe):
# Check with integer bounds and push:
if integer_value_fits(result):
......@@ -15,20 +16,24 @@ def _push_long_result(frame, result, universe):
else:
frame.push(universe.new_biginteger(result))
def _resend_as_biginteger(frame, operator, left, right, universe):
left_biginteger = universe.new_biginteger(left.get_embedded_integer())
operands = [right]
left_biginteger.send(frame, operator, operands, universe, universe.get_interpreter())
def _resend_as_double(frame, operator, left, right, universe):
left_double = universe.new_double(left.get_embedded_integer())
operands = [right]
left_double.send(frame, operator, operands, universe, universe.get_interpreter())
def _asString(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(interpreter.get_universe().new_string(str(rcvr.get_embedded_integer())))
def _sqrt(ivkbl, frame, interpreter):
rcvr = frame.pop()
res = math.sqrt(rcvr.get_embedded_integer())
......@@ -37,11 +42,13 @@ def _sqrt(ivkbl, frame, interpreter):
else:
frame.push(interpreter.get_universe().new_double(res))
def _atRandom(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(interpreter.get_universe().new_integer(int(
rcvr.get_embedded_integer() * interpreter.get_universe().random.random())))
def _plus(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
......@@ -58,6 +65,7 @@ def _plus(ivkbl, frame, interpreter):
result = left.get_embedded_integer() + right.get_embedded_integer()
_push_long_result(frame, result, interpreter.get_universe())
def _minus(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
......@@ -74,6 +82,7 @@ def _minus(ivkbl, frame, interpreter):
result = left.get_embedded_integer() - right.get_embedded_integer()
_push_long_result(frame, result, interpreter.get_universe())
def _mult(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
......@@ -90,6 +99,7 @@ def _mult(ivkbl, frame, interpreter):
result = left.get_embedded_integer() * right.get_embedded_integer()
_push_long_result(frame, result, interpreter.get_universe())
def _doubleDiv(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
......@@ -106,6 +116,7 @@ def _doubleDiv(ivkbl, frame, interpreter):
result = float(left.get_embedded_integer()) / float(right.get_embedded_integer())
frame.push(interpreter.get_universe().new_double(result))
def _intDiv(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
......@@ -122,6 +133,7 @@ def _intDiv(ivkbl, frame, interpreter):
result = left.get_embedded_integer() / right.get_embedded_integer()
_push_long_result(frame, result, interpreter.get_universe())
def _mod(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
......@@ -136,6 +148,7 @@ def _mod(ivkbl, frame, interpreter):
# Do operation:
_push_long_result(frame, left.get_embedded_integer() % right_obj.get_embedded_integer(), interpreter.get_universe())
def _and(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
......@@ -174,6 +187,7 @@ def _equals(ivkbl, frame, interpreter):
else:
frame.push(interpreter.get_universe().falseObject)
def _lessThan(ivkbl, frame, interpreter):
right_obj = frame.pop()
left = frame.pop()
......@@ -190,6 +204,7 @@ def _lessThan(ivkbl, frame, interpreter):
else:
frame.push(interpreter.get_universe().falseObject)
def _fromString(ivkbl, frame, interpreter):
param = frame.pop()
frame.pop()
......@@ -219,8 +234,10 @@ def _bitXor(ivkbl, frame, interpreter):
frame.push(interpreter.get_universe().new_integer(result))
from rpython.rlib import jit
def get_printable_location(interpreter, block_method):
from som.vmobjects.method import Method
assert isinstance(block_method, Method)
......
from som.primitives.primitives import Primitives
from som.vmobjects.primitive import Primitive
def _holder(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(rcvr.get_holder())
def _signature(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(rcvr.get_signature())
......
......@@ -6,6 +6,7 @@ from som.vmobjects.object import Object
from som.vmobjects.primitive import Primitive
from som.vmobjects.array import Array
def _equals(ivkbl, frame, interpreter):
op1 = frame.pop()
op2 = frame.pop()
......@@ -14,11 +15,13 @@ def _equals(ivkbl, frame, interpreter):
else:
frame.push(interpreter.get_universe().falseObject)
def _hashcode(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(interpreter.get_universe().new_integer(
compute_identity_hash(rcvr)))
def _objectSize(ivkbl, frame, interpreter):
rcvr = frame.pop()
size = 0
......@@ -30,6 +33,7 @@ def _objectSize(ivkbl, frame, interpreter):
frame.push(interpreter.get_universe().new_integer(size))
def _perform(ivkbl, frame, interpreter):
selector = frame.pop()
rcvr = frame.get_stack_element(0)
......@@ -37,6 +41,7 @@ def _perform(ivkbl, frame, interpreter):
invokable = rcvr.get_class(interpreter.get_universe()).lookup_invokable(selector)
invokable.invoke(frame, interpreter)
def _performInSuperclass(ivkbl, frame, interpreter):
clazz = frame.pop()
selector = frame.pop()
......@@ -45,6 +50,7 @@ def _performInSuperclass(ivkbl, frame, interpreter):
invokable = clazz.lookup_invokable(selector)
invokable.invoke(frame, interpreter)
def _performWithArguments(ivkbl, frame, interpreter):
args = frame.pop()
selector = frame.pop()
......@@ -56,12 +62,14 @@ def _performWithArguments(ivkbl, frame, interpreter):
invokable = rcvr.get_class(interpreter.get_universe()).lookup_invokable(selector)
invokable.invoke(frame, interpreter)
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()
......@@ -69,6 +77,7 @@ def _instVarAtPut(ivkbl, frame, interpreter):
rcvr.set_field(idx.get_embedded_integer() - 1, val)
def _halt(ivkbl, frame, interpreter):
# noop
print "BREAKPOINT"
......
from som.primitives.primitives import Primitives
from som.vmobjects.primitive import Primitive
def _holder(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(rcvr.get_holder())
def _signature(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(rcvr.get_signature())
class PrimitivePrimitives(Primitives):
def install_primitives(self):
self._install_instance_primitive(Primitive("holder", self._universe, _holder))
......
......@@ -3,20 +3,24 @@ from rpython.rlib.objectmodel import compute_identity_hash
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(len(rcvr.get_embedded_string())))
def _equals(ivkbl, frame, interpreter):
op1 = frame.pop()
op2 = frame.pop() # rcvr
......@@ -27,6 +31,7 @@ def _equals(ivkbl, frame, interpreter):
return
frame.push(universe.falseObject)
def _substring(ivkbl, frame, interpreter):
end = frame.pop()
start = frame.pop()
......@@ -41,11 +46,13 @@ def _substring(ivkbl, frame, interpreter):
else:
frame.push(interpreter.get_universe().new_string(string[s:e]))
def _hashcode(ivkbl, frame, interpreter):
rcvr = frame.pop()
frame.push(interpreter.get_universe().new_integer(
compute_identity_hash(rcvr.get_embedded_string())))
class StringPrimitives(Primitives):
def install_primitives(self):
......
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):
......
......@@ -6,50 +6,60 @@ from som.vm.universe import std_print, std_println
from rpython.rlib import rgc, jit
import time
def _load(ivkbl, frame, interpreter):
argument = frame.pop()
frame.pop() # not required
result = interpreter.get_universe().load_class(argument)
frame.push(result if result else interpreter.get_universe().nilObject)
def _exit(ivkbl, frame, interpreter):
error = frame.pop()
interpreter.get_universe().exit(error.get_embedded_integer())
def _global(ivkbl, frame, interpreter):
argument = frame.pop()
frame.pop() # not required
result = interpreter.get_universe().get_global(argument)
frame.push(result if result else interpreter.get_universe().nilObject)
def _global_put(ivkbl, frame, interpreter):
value = frame.pop()
argument = frame.pop()
interpreter.get_universe().set_global(argument, value)
def _print_string(ivkbl, frame, interpreter):
argument = frame.pop()
std_print(argument.get_embedded_string())
def _print_newline(ivkbl, frame, interpreter):
std_println()
def _time(ivkbl, frame, interpreter):
frame.pop() # ignore
since_start = time.time() - interpreter.get_universe().start_time
frame.push(interpreter.get_universe().new_integer(int(since_start * 1000)))
def _ticks(ivkbl, frame, interpreter):
frame.pop() # ignore
since_start = time.time() - interpreter.get_universe().start_time
frame.push(interpreter.get_universe().new_integer(int(since_start * 1000000)))
@jit.dont_look_inside
def _fullGC(ivkbl, frame, interpreter):
frame.pop()
rgc.collect()
frame.push(interpreter.get_universe().trueObject)
class SystemPrimitives(Primitives):
def install_primitives(self):
......
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