Author: Tim Felgentreff <[email protected]>
Branch:
Changeset: r540:182c667e14ff
Date: 2013-12-18 16:10 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/182c667e14ff/
Log: (hopefully) fix the millisecond clock issue for now
diff --git a/spyvm/constants.py b/spyvm/constants.py
--- a/spyvm/constants.py
+++ b/spyvm/constants.py
@@ -146,6 +146,8 @@
TAGGED_MAXINT = 2 ** (LONG_BIT - 2) - 1
TAGGED_MININT = -2 ** (LONG_BIT - 2)
+TAGGED_MASK = int(2 ** (LONG_BIT - 1) - 1)
+
# Entries into SO_SPECIAL_SELECTORS_ARRAY:
#(#+ 1 #- 1 #< 1 #> 1 #<= 1 #>= 1 #= 1 #~= 1 #* 1 #/ 1 #\\ 1 #@ 1 #bitShift: 1
#// 1 #bitAnd: 1 #bitOr: 1 #at: 1 #at:put: 2 #size 0 #next 0 #nextPut: 1 #atEnd
0 #== 1 #class 0 #blockCopy: 1 #value 0 #value: 1 #do: 1 #new 0 #new: 1 #x 0 #y
0)
diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -5,7 +5,7 @@
from spyvm.tool.bitmanipulation import splitter
from rpython.rlib import jit
-from rpython.rlib import objectmodel, unroll, rarithmetic
+from rpython.rlib import objectmodel, unroll
class MissingBytecode(Exception):
"""Bytecode not implemented yet."""
@@ -23,7 +23,9 @@
class Interpreter(object):
-
+ _immutable_fields_ = ["space", "image", "image_name",
+ "max_stack_depth", "interrupt_counter_size",
+ "startup_time"]
_w_last_active_context = None
cnt = 0
_last_indent = ""
@@ -36,9 +38,11 @@
def __init__(self, space, image=None, image_name="", trace=False,
max_stack_depth=constants.MAX_LOOP_DEPTH):
+ import time
self.space = space
self.image = image
self.image_name = image_name
+ self.startup_time = time.time()
self.max_stack_depth = max_stack_depth
self.remaining_stack_depth = max_stack_depth
self._loop = False
@@ -176,16 +180,12 @@
def check_for_interrupts(self, s_frame):
# parallel to Interpreter>>#checkForInterrupts
- import time, math
# Profiling is skipped
# We don't adjust the check counter size
# use the same time value as the primitive MILLISECOND_CLOCK
- now = rarithmetic.intmask(
- int(time.time()*1000) & (constants.TAGGED_MAXINT/2 - 1)
- )
- # now = int(math.fmod(time.time()*1000, constants.TAGGED_MAXINT/2))
+ now = self.time_now()
# XXX the low space semaphore may be signaled here
# Process inputs
@@ -199,6 +199,11 @@
# We do not support external semaphores.
# In cog, the method to add such a semaphore is only called in GC.
+ def time_now(self):
+ import time
+ from rpython.rlib.rarithmetic import intmask
+ return intmask(int((time.time() - self.startup_time) * 1000) &
constants.TAGGED_MASK)
+
def padding(self, symbol=' '):
return symbol * (self.max_stack_depth - self.remaining_stack_depth)
diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -1016,10 +1016,7 @@
@expose_primitive(MILLISECOND_CLOCK, unwrap_spec=[object])
def func(interp, s_frame, w_arg):
- import time, math
- return interp.space.wrap_int(rarithmetic.intmask(
- int(time.time()*1000) & (constants.TAGGED_MAXINT/2 - 1)
- ))
+ return interp.space.wrap_int(interp.time_now())
@expose_primitive(SIGNAL_AT_MILLISECONDS, unwrap_spec=[object, object, int])
def func(interp, s_frame, w_delay, w_semaphore, timestamp):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit