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

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):
......@@ -13,4 +15,8 @@ class Integer(Object):
self._embedded_integer = value
def __str__(self):
return str(self._embedded_integer)
\ No newline at end of file
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