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 adb9a138 authored by Stefan Marr's avatar Stefan Marr
Browse files

With Python, the whole Integer vs. BigInteger is slightly useless



- for the moment lets use sys.maxint as a limit, will see whether we need to use the more traditional 31-bit boundaries for compatibility
Signed-off-by: default avatarStefan Marr <git@stefan-marr.de>
parent 40003443
......@@ -3,6 +3,8 @@ from som.compiler.lexer import Lexer
from som.compiler.bytecode_generator import BytecodeGenerator
from som.compiler.method_generation_context import MethodGenerationContext
from som.vmobjects.integer import Integer
class Parser(object):
_single_op_syms = (Symbol.Not, Symbol.And, Symbol.Or, Symbol.Star,
......@@ -457,10 +459,11 @@ class Parser(object):
else:
val = self._literal_decimal()
if isinstance(val, long):
lit = self._universe.new_biginteger(val)
else:
if Integer.value_fits(val):
lit = self._universe.new_integer(val)
else:
lit = self._universe.new_biginteger(val)
mgenc.add_literal_if_absent(lit)
self._bc_gen.emitPUSHCONSTANT(mgenc, lit)
......
......@@ -12,10 +12,10 @@ class IntegerPrimitives(Primitives):
def _push_long_result(self, frame, result):
# Check with integer bounds and push:
if isinstance(result, long):
frame.push(self._universe.new_biginteger(result))
else:
if Integer.value_fits(result):
frame.push(self._universe.new_integer(result))
else:
frame.push(self._universe.new_biginteger(result))
def _resend_as_biginteger(self, operator, left, right):
left_biginteger = self._universe.new_biginteger(left.get_embedded_integer())
......
from som.vmobjects.object import Object
import sys
class Integer(Object):
def __init__(self, nilObject):
......@@ -14,3 +16,7 @@ class Integer(Object):
def __str__(self):
return str(self._embedded_integer)
@classmethod
def value_fits(cls, value):
return value < sys.maxint and value > (-sys.maxint - 1)
\ No newline at end of file
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