WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

Commit f0a645a8 authored by Stefan Marr's avatar Stefan Marr
Browse files

Added missing primitives



- Double>>#round
- Integer class>>#fromString:
- System>>#fullGC:
Signed-off-by: default avatarStefan Marr <git@stefan-marr.de>
parent c16ed981
from rpython.rlib.rfloat import (formatd, DTSF_ADD_DOT_0, DTSF_STR_PRECISION,
NAN, INFINITY, isfinite, round_away)
NAN, INFINITY, isfinite, round_double)
from som.primitives.primitives import Primitives
from som.vmobjects.primitive import Primitive
from som.vmobjects.double import Double
......@@ -72,10 +73,16 @@ def _lessThan(ivkbl, frame, interpreter):
else:
frame.push(interpreter.get_universe().falseObject)
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):
self._install_instance_primitive(Primitive("asString", self._universe, _asString))
self._install_instance_primitive(Primitive("round", self._universe, _round))
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))
......
......@@ -3,6 +3,7 @@ from som.vmobjects.primitive import Primitive
from som.vmobjects.biginteger import BigInteger
from som.vmobjects.integer import integer_value_fits, Integer
from som.vmobjects.double import Double
from som.vmobjects.string import String
import math
......@@ -188,6 +189,17 @@ def _lessThan(ivkbl, frame, interpreter):
else:
frame.push(interpreter.get_universe().falseObject)
def _fromString(ivkbl, frame, interpreter):
param = frame.pop()
frame.pop()
if not isinstance(param, String):
frame.push(interpreter.get_universe().nilObject)
return
int_value = int(param.get_embedded_string())
frame.push(interpreter.get_universe().new_integer(int_value))
class IntegerPrimitives(Primitives):
def install_primitives(self):
......@@ -205,4 +217,5 @@ class IntegerPrimitives(Primitives):
self._install_instance_primitive(Primitive("&", self._universe, _and))
self._install_instance_primitive(Primitive("=", self._universe, _equals))
self._install_instance_primitive(Primitive("<", self._universe, _lessThan))
\ No newline at end of file
self._install_class_primitive(Primitive("fromString:", self._universe, _fromString))
......@@ -3,6 +3,7 @@ from som.vmobjects.primitive import Primitive
from som.vm.universe import std_print, std_println
import gc
import time
def _load(ivkbl, frame, interpreter):
......@@ -44,8 +45,9 @@ def _ticks(ivkbl, frame, interpreter):
frame.push(interpreter.get_universe().new_integer(int(since_start * 1000000)))
def _fullGC(ivkbl, frame, interpreter):
# naught - GC is entirely left to Python
pass
frame.pop()
gc.collect()
frame.push(interpreter.get_universe().trueObject)
class SystemPrimitives(Primitives):
......
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