[pypy-commit] lang-smalltalk rbitblt: automatically round fractions to ints directly in our bitblt

2014-01-09 Thread timfel
Author: Tim Felgentreff 
Branch: rbitblt
Changeset: r563:c22d170b585b
Date: 2014-01-09 16:55 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/c22d170b585b/

Log:automatically round fractions to ints directly in our bitblt

diff --git a/spyvm/plugins/bitblt.py b/spyvm/plugins/bitblt.py
--- a/spyvm/plugins/bitblt.py
+++ b/spyvm/plugins/bitblt.py
@@ -37,6 +37,15 @@
 return w_rcvr
 
 
+def intOrIfNil(space, w_int, i):
+if w_int is space.w_nil:
+return i
+elif isinstance(w_int, model.W_Float):
+return intmask(int(space.unwrap_float(w_int)))
+else:
+return space.unwrap_int(w_int)
+
+
 class BitBltShadow(AbstractCachingShadow):
 WordSize = 32
 MaskTable = [r_uint(0)]
@@ -48,10 +57,7 @@
 pass
 
 def intOrIfNil(self, w_int, i):
-if w_int is self.space.w_nil:
-return i
-else:
-return self.space.unwrap_int(w_int)
+return intOrIfNil(self.space, w_int, i)
 
 def loadForm(self, w_form):
 if not isinstance(w_form, model.W_PointersObject):
@@ -716,6 +722,9 @@
 AbstractCachingShadow.__init__(self, space, w_self)
 self.invalid = False
 
+def intOrIfNil(self, w_int, i):
+return intOrIfNil(self.space, w_int, i)
+
 def sync_cache(self):
 self.invalid = True
 if self.size() < 5:
@@ -725,9 +734,9 @@
 return
 if not (isinstance(self.w_bits, model.W_WordsObject) or 
isinstance(self.w_bits, model.W_DisplayBitmap)):
 return
-self.width = self.space.unwrap_int(self.fetch(1))
-self.height = self.space.unwrap_int(self.fetch(2))
-self.depth = self.space.unwrap_int(self.fetch(3))
+self.width = self.intOrIfNil(self.fetch(1), 0)
+self.height = self.intOrIfNil(self.fetch(2), 0)
+self.depth = self.intOrIfNil(self.fetch(3), 0)
 if self.width < 0 or self.height < 0:
 return
 self.msb = self.depth > 0
@@ -738,8 +747,8 @@
 w_offset = self.fetch(4)
 assert isinstance(w_offset, model.W_PointersObject)
 if not w_offset is self.space.w_nil:
-self.offsetX = self.space.unwrap_int(w_offset._fetch(0))
-self.offsetY = self.space.unwrap_int(w_offset._fetch(1))
+self.offsetX = self.intOrIfNil(w_offset._fetch(0), 0)
+self.offsetY = self.intOrIfNil(w_offset._fetch(1), 0)
 self.pixPerWord = 32 / self.depth
 self.pitch = (self.width + (self.pixPerWord - 1)) / self.pixPerWord | 0
 if self.w_bits.size() != (self.pitch * self.height):
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk rbitblt: fix drawing of miniimage

2014-01-09 Thread timfel
Author: Tim Felgentreff 
Branch: rbitblt
Changeset: r564:55bea8ee8fbb
Date: 2014-01-09 17:33 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/55bea8ee8fbb/

Log:fix drawing of miniimage

diff --git a/spyvm/plugins/bitblt.py b/spyvm/plugins/bitblt.py
--- a/spyvm/plugins/bitblt.py
+++ b/spyvm/plugins/bitblt.py
@@ -751,6 +751,6 @@
 self.offsetY = self.intOrIfNil(w_offset._fetch(1), 0)
 self.pixPerWord = 32 / self.depth
 self.pitch = (self.width + (self.pixPerWord - 1)) / self.pixPerWord | 0
-if self.w_bits.size() != (self.pitch * self.height):
+if self.w_bits.size() < (self.pitch * self.height):
 return
 self.invalid = False
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk rbitblt: add WITH_ARGS_EXECUTE_METHOD prim, as it doesn't work in Smalltalk

2014-01-09 Thread timfel
Author: Tim Felgentreff 
Branch: rbitblt
Changeset: r562:151ff8db1a76
Date: 2014-01-09 16:22 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/151ff8db1a76/

Log:add WITH_ARGS_EXECUTE_METHOD prim, as it doesn't work in Smalltalk

diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -1230,6 +1230,7 @@
 RESUME = 87
 SUSPEND = 88
 FLUSH_CACHE = 89
+WITH_ARGS_EXECUTE_METHOD = 188
 
 @expose_primitive(BLOCK_COPY, unwrap_spec=[object, int])
 def func(interp, s_frame, w_context, argcnt):
@@ -1341,6 +1342,20 @@
 s_frame.pop()
 return interp.stack_frame(s_new_frame)
 
+@expose_primitive(WITH_ARGS_EXECUTE_METHOD, unwrap_spec=[object, list, 
object], no_result=True)
+def func(interp, s_frame, w_rcvr, args_w, w_cm):
+if not isinstance(w_cm, model.W_CompiledMethod):
+raise PrimitiveFailedError()
+
+s_method = w_cm.as_compiledmethod_get_shadow(interp.space)
+code = s_method.primitive()
+if code:
+raise PrimitiveFailedError("withArgs:executeMethod: not support with 
primitive method")
+s_new_frame = s_method.create_frame(interp.space, w_rcvr, args_w, s_frame)
+if interp.trace:
+print interp.padding() + s_new_frame.short_str()
+return interp.stack_frame(s_new_frame)
+
 @expose_primitive(SIGNAL, unwrap_spec=[object], clean_stack=False, 
no_result=True)
 def func(interp, s_frame, w_rcvr):
 # XXX we might want to disable this check
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk rbitblt: should fix the sources not found issue i had

2014-01-09 Thread timfel
Author: Tim Felgentreff 
Branch: rbitblt
Changeset: r565:b8c725eb9faf
Date: 2014-01-09 18:23 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/b8c725eb9faf/

Log:should fix the sources not found issue i had

diff --git a/targetimageloadingsmalltalk.py b/targetimageloadingsmalltalk.py
--- a/targetimageloadingsmalltalk.py
+++ b/targetimageloadingsmalltalk.py
@@ -191,7 +191,7 @@
 if path is None:
 path = "Squeak.image"
 
-path = os.path.join(os.getcwd(), path)
+path = os.path.abspath(path)
 try:
 f = open_file_as_stream(path, mode="rb", buffering=0)
 except OSError as e:
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk rbitblt: fix translation with jit, add some crazy jit hints in bitblt (needs work)

2014-01-09 Thread timfel
Author: Tim Felgentreff 
Branch: rbitblt
Changeset: r566:08464f06251d
Date: 2014-01-09 18:53 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/08464f06251d/

Log:fix translation with jit, add some crazy jit hints in bitblt (needs
work)

diff --git a/spyvm/plugins/bitblt.py b/spyvm/plugins/bitblt.py
--- a/spyvm/plugins/bitblt.py
+++ b/spyvm/plugins/bitblt.py
@@ -3,7 +3,7 @@
 from spyvm.shadow import AbstractCachingShadow
 from spyvm.plugins.plugin import Plugin
 
-from rpython.rlib import jit
+from rpython.rlib import jit, objectmodel
 from rpython.rlib.rarithmetic import r_uint, intmask
 
 
@@ -61,10 +61,10 @@
 
 def loadForm(self, w_form):
 if not isinstance(w_form, model.W_PointersObject):
-raise PrimitiveFailedError("cannot load form from %s" % 
w_form.as_repr_string())
+raise PrimitiveFailedError("cannot load form")
 s_form = w_form.as_special_get_shadow(self.space, FormShadow)
 if s_form.invalid:
-raise PrimitiveFailedError("Could not create form shadow for %s" % 
w_form.as_repr_string())
+raise PrimitiveFailedError("Could not create form shadow")
 return s_form
 
 def loadHalftone(self, w_halftone_form):
@@ -253,6 +253,7 @@
 self.destIndex = (self.dy * self.dest.pitch) + (self.dx / 
self.dest.pixPerWord | 0)
 self.destDelta = (self.dest.pitch * self.vDir) - (self.nWords * 
self.hDir)
 
+@jit.unroll_safe
 def copyLoopNoSource(self):
 halftoneWord = BitBltShadow.AllOnes
 for i in range(self.bbH):
@@ -287,6 +288,7 @@
 self.destIndex += 1
 self.destIndex += self.destDelta
 
+@jit.unroll_safe
 def copyLoopPixMap(self):
 # This version of the inner loop maps source pixels
 # to a destination form with different depth.  Because it is already
@@ -362,6 +364,7 @@
 self.sourceIndex += self.sourceDelta
 self.destIndex += self.destDelta
 
+@jit.unroll_safe
 def pickSourcePixels(self, nPixels, srcMask, dstMask, srcShiftInc, 
dstShiftInc):
 # Pick nPix pixels starting at srcBitIndex from the source, map by the
 # color map, and justify them according to dstBitIndex in the 
resulting destWord.
@@ -403,6 +406,7 @@
 rotated = rotated | (thisWord & skewMask) << self.skew
 return rotated
 
+@jit.unroll_safe
 def copyLoop(self):
 # self version of the inner loop assumes we do have a source
 sourceLimit = self.source.w_bits.size()
@@ -511,56 +515,58 @@
 def mergeFn(self, src, dest):
 return r_uint(self.merge(
 r_uint(src),
-r_uint(dest)
+r_uint(dest),
+self.combinationRule
 ))
 
-def merge(self, source_word, dest_word):
+@objectmodel.specialize.arg_or_var(3)
+def merge(self, source_word, dest_word, combinationRule):
 assert isinstance(source_word, r_uint) and isinstance(dest_word, 
r_uint)
-if self.combinationRule == 0:
+if combinationRule == 0:
 return 0
-elif self.combinationRule == 1:
+elif combinationRule == 1:
 return source_word & dest_word
-elif self.combinationRule == 2:
+elif combinationRule == 2:
 return source_word & ~dest_word
-elif self.combinationRule == 3:
+elif combinationRule == 3:
 return source_word
-elif self.combinationRule == 4:
+elif combinationRule == 4:
 return ~source_word & dest_word
-elif self.combinationRule == 5:
+elif combinationRule == 5:
 return dest_word
-elif self.combinationRule == 6:
+elif combinationRule == 6:
 return source_word ^ dest_word
-elif self.combinationRule == 7:
+elif combinationRule == 7:
 return source_word | dest_word
-elif self.combinationRule == 8:
+elif combinationRule == 8:
 return ~source_word & ~dest_word
-elif self.combinationRule == 9:
+elif combinationRule == 9:
 return ~source_word ^ dest_word
-elif self.combinationRule == 10:
+elif combinationRule == 10:
 return ~dest_word
-elif self.combinationRule == 11:
+elif combinationRule == 11:
 return source_word | ~dest_word
-elif self.combinationRule == 12:
+elif combinationRule == 12:
 return ~source_word
-elif self.combinationRule == 13:
+elif combinationRule == 13:
 return ~source_word | dest_word
-elif self.combinationRule == 14:
+elif combinationRule == 14:
 return ~source_word | ~dest_word
-elif self.combinationRule >= 15 and self.combinationRule <= 17:
+elif combinationRule >= 15 and combinationRule <= 17:
 return dest_word
-elif self.combinationRule == 18:
+elif combinationRule ==

[pypy-commit] lang-smalltalk rbitblt: implement GET_NEXT_EVENT, DEFER_UPDATES, and FORCE_DISPLAY_UPDATE

2014-01-09 Thread timfel
Author: Tim Felgentreff 
Branch: rbitblt
Changeset: r558:c8495a907803
Date: 2014-01-09 11:34 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/c8495a907803/

Log:implement GET_NEXT_EVENT, DEFER_UPDATES, and FORCE_DISPLAY_UPDATE

diff --git a/spyvm/display.py b/spyvm/display.py
--- a/spyvm/display.py
+++ b/spyvm/display.py
@@ -6,16 +6,40 @@
 from rsdl import RSDL, RSDL_helper
 
 
-MOUSE_BTN_RIGHT = 1
-MOUSE_BTN_MIDDLE = 2
-MOUSE_BTN_LEFT = 4
-MOD_SHIFT  = 1
-MOD_CONTROL = 2
-MOD_ALT_CMD = 16 | 8
+# EventSensorConstants
+RedButtonBit = 4
+BlueButtonBit = 2
+YellowButtonBit = 1
+
+ShiftKeyBit = 1
+CtrlKeyBit = 2
+OptionKeyBit = 4
+CommandKeyBit = 8
+
+EventTypeNone = 0
+EventTypeMouse = 1
+EventTypeKeyboard = 2
+EventTypeDragDropFiles = 3
+EventTypeMenu = 4
+EventTypeWindow = 5
+EventTypeComplex = 6
+
+EventKeyChar = 0
+EventKeyDown = 1
+EventKeyUp = 2
+
+WindowEventMetricChange = 1
+WindowEventClose = 2
+WindowEventIconise = 3
+WindowEventActivated = 4
+WindowEventPaint = 5
+WindowEventStinks = 6
+
 
 class SDLDisplay(object):
 _attrs_ = ["screen", "width", "height", "depth", "surface", "has_surface",
-   "mouse_position", "button", "key", "interrupt_key"]
+   "mouse_position", "button", "key", "interrupt_key", 
"_defer_updates",
+   "_deferred_event"]
 
 def __init__(self, title):
 assert RSDL.Init(RSDL.INIT_VIDEO) >= 0
@@ -27,6 +51,8 @@
 self.interrupt_key = 15 << 8 # pushing all four meta keys, of which we 
support three...
 self.button = 0
 self.key = 0
+self._deferred_event = None
+self._defer_updates = False
 
 def set_video_mode(self, w, h, d):
 assert w > 0 and h > 0
@@ -47,8 +73,12 @@
 def get_pixelbuffer(self):
 return rffi.cast(rffi.ULONGP, self.screen.c_pixels)
 
-def flip(self):
-RSDL.Flip(self.screen)
+def defer_updates(self, flag):
+self._defer_updates = flag
+
+def flip(self, force=False):
+if (not self._defer_updates) or force:
+RSDL.Flip(self.screen)
 
 def set_squeak_colormap(self, screen):
 # TODO: fix this up from the image
@@ -72,11 +102,11 @@
 b = rffi.cast(RSDL.MouseButtonEventPtr, event)
 btn = rffi.getintfield(b, 'c_button')
 if btn == RSDL.BUTTON_RIGHT:
-btn = MOUSE_BTN_RIGHT
+btn = YellowButtonBit
 elif btn == RSDL.BUTTON_MIDDLE:
-btn = MOUSE_BTN_MIDDLE
+btn = BlueButtonBit
 elif btn == RSDL.BUTTON_LEFT:
-btn = MOUSE_BTN_LEFT
+btn = RedButtonBit
 
 if c_type == RSDL.MOUSEBUTTONDOWN:
 self.button |= btn
@@ -114,7 +144,75 @@
 if (interrupt & 0xFF == self.key and interrupt >> 8 == 
self.get_modifier_mask(0)):
 raise KeyboardInterrupt
 
-def get_next_event(self):
+def get_next_mouse_event(self, time):
+mods = self.get_modifier_mask(3)
+btn = self.button
+if btn == RedButtonBit:
+if mods & CtrlKeyBit:
+btn = BlueButtonBit
+elif mods & CommandKeyBit:
+btn = YellowButtonBit
+return [EventTypeMouse,
+time,
+int(self.mouse_position[0]),
+int(self.mouse_position[1]),
+btn,
+mods,
+0,
+0]
+
+def get_next_key_event(self, t, time):
+mods = self.get_modifier_mask(3)
+btn = self.button
+return [EventTypeKeyboard,
+time,
+self.key,
+t,
+mods,
+self.key,
+0,
+0]
+
+def get_next_event(self, time=0):
+if self._deferred_event:
+deferred = self._deferred_event
+self._deferred_event = None
+return deferred
+
+event = lltype.malloc(RSDL.Event, flavor="raw")
+try:
+if rffi.cast(lltype.Signed, RSDL.PollEvent(event)) == 1:
+c_type = rffi.getintfield(event, 'c_type')
+if c_type in [RSDL.MOUSEBUTTONDOWN, RSDL.MOUSEBUTTONUP]:
+self.handle_mouse_button(c_type, event)
+return self.get_next_mouse_event(time)
+elif c_type == RSDL.MOUSEMOTION:
+self.handle_mouse_move(c_type, event)
+return self.get_next_mouse_event(time)
+elif c_type == RSDL.KEYDOWN:
+self.handle_keypress(c_type, event)
+return self.get_next_key_event(EventKeyDown, time)
+elif c_type == RSDL.KEYUP:
+self._deferred_event = self.get_next_key_event(EventKeyUp, 
time)
+return self.get_next_key_event(EventKeyChar, time)
+elif c_type == RSDL.VIDEORESIZE:
+self.screen = RSDL.GetVideoSurface()
+self._deferred_event =

[pypy-commit] lang-smalltalk rbitblt: detach form shadow on sync_cache failure

2014-01-09 Thread timfel
Author: Tim Felgentreff 
Branch: rbitblt
Changeset: r556:03b60ed307da
Date: 2014-01-08 10:37 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/03b60ed307da/

Log:detach form shadow on sync_cache failure

diff --git a/spyvm/plugins/bitblt.py b/spyvm/plugins/bitblt.py
--- a/spyvm/plugins/bitblt.py
+++ b/spyvm/plugins/bitblt.py
@@ -752,5 +752,6 @@
 self.pixPerWord = 32 / self.depth
 self.pitch = (self.width + (self.pixPerWord - 1)) / self.pixPerWord | 0
 if self.w_bits.size() != (self.pitch * self.height):
-# raise error.PrimitiveFailedError()
-pass # - we'll be updated again
+w_self = self.w_self()
+assert isinstance(w_self, model.W_PointersObject)
+w_self._shadow = None
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk rbitblt: don't raise in sync_cache of BitBlt and Forms

2014-01-09 Thread timfel
Author: Tim Felgentreff 
Branch: rbitblt
Changeset: r560:9f779d03110f
Date: 2014-01-09 16:20 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/9f779d03110f/

Log:don't raise in sync_cache of BitBlt and Forms

diff --git a/spyvm/plugins/bitblt.py b/spyvm/plugins/bitblt.py
--- a/spyvm/plugins/bitblt.py
+++ b/spyvm/plugins/bitblt.py
@@ -9,6 +9,7 @@
 
 BitBltPlugin = Plugin()
 
+
 @BitBltPlugin.expose_primitive(unwrap_spec=[object], clean_stack=True)
 def primitiveCopyBits(interp, s_frame, w_rcvr):
 from spyvm.interpreter import Return
@@ -22,6 +23,7 @@
 
 space = interp.space
 s_bitblt = w_rcvr.as_special_get_shadow(space, BitBltShadow)
+s_bitblt.loadBitBlt()
 s_bitblt.copyBits()
 
 w_dest_form = w_rcvr.fetch(space, 0)
@@ -34,9 +36,6 @@
 w_bitmap.flush_to_screen()
 return w_rcvr
 
-def as_bitblt_get_shadow(self, space):
-return
-
 
 class BitBltShadow(AbstractCachingShadow):
 WordSize = 32
@@ -46,7 +45,7 @@
 AllOnes = r_uint(0x)
 
 def sync_cache(self):
-self.loadBitBlt()
+pass
 
 def intOrIfNil(self, w_int, i):
 if w_int is self.space.w_nil:
@@ -55,18 +54,12 @@
 return self.space.unwrap_int(w_int)
 
 def loadForm(self, w_form):
-try:
-if not isinstance(w_form, model.W_PointersObject):
-raise PrimitiveFailedError("cannot load form from %s" % 
w_form.as_repr_string())
-s_form = w_form.as_special_get_shadow(self.space, FormShadow)
-if not isinstance(s_form, FormShadow):
-raise PrimitiveFailedError("Could not create form shadow for 
%s" % w_form.as_repr_string())
-return s_form
-except PrimitiveFailedError, e:
-w_self = self.w_self()
-assert isinstance(w_self, model.W_PointersObject)
-w_self._shadow = None
-raise e
+if not isinstance(w_form, model.W_PointersObject):
+raise PrimitiveFailedError("cannot load form from %s" % 
w_form.as_repr_string())
+s_form = w_form.as_special_get_shadow(self.space, FormShadow)
+if s_form.invalid:
+raise PrimitiveFailedError("Could not create form shadow for %s" % 
w_form.as_repr_string())
+return s_form
 
 def loadHalftone(self, w_halftone_form):
 if w_halftone_form is self.space.w_nil:
@@ -76,7 +69,10 @@
 return w_halftone_form.words
 else:
 assert isinstance(w_halftone_form, model.W_PointersObject)
-w_bits = w_halftone_form.as_special_get_shadow(self.space, 
FormShadow).w_bits
+s_form = w_halftone_form.as_special_get_shadow(self.space, 
FormShadow)
+if s_form.invalid:
+raise PrimitiveFailedError("Halftone form is invalid")
+w_bits = s_form.w_bits
 assert isinstance(w_bits, model.W_WordsObject)
 return w_bits.words
 
@@ -334,9 +330,8 @@
 self.dstBitShift = dstShift
 self.destMask = self.mask1
 nPix = startBits
-words = self.nWords
 # Here is the horizontal loop...
-for word in range(words):
+for word in range(self.nWords):
 skewWord = self.pickSourcePixels(nPix, sourcePixMask, 
destPixMask, srcShiftInc, dstShiftInc)
 # align next word to leftmost pixel
 self.dstBitShift = dstShiftLeft
@@ -352,7 +347,7 @@
 self.dest.w_bits.setword(self.destIndex, destWord)
 
 self.destIndex += 1
-if (words == 2): # is the next word the last word?
+if (self.nWords == 2): # is the next word the last word?
 self.destMask = self.mask2
 nPix = endBits
 else: # use fullword mask for inner loop
@@ -715,32 +710,31 @@
 
 class FormShadow(AbstractCachingShadow):
 _attrs_ = ["w_bits", "width", "height", "depth", "offsetX",
-   "offsetY", "msb", "pixPerWord", "pitch"]
+   "offsetY", "msb", "pixPerWord", "pitch", "invalid"]
+
+def __init__(self, space, w_self):
+AbstractCachingShadow.__init__(self, space, w_self)
+self.invalid = False
 
 def sync_cache(self):
+self.invalid = True
 if self.size() < 5:
-w_self = self.w_self()
-assert isinstance(w_self, model.W_PointersObject)
-w_self._shadow = None
-raise PrimitiveFailedError("Form object too small")
+return
 self.w_bits = self.fetch(0)
 if self.w_bits is self.space.w_nil:
 return
 if not (isinstance(self.w_bits, model.W_WordsObject) or 
isinstance(self.w_bits, model.W_DisplayBitmap)):
-w_self = self.w_self()
-assert isinstance(w_self, model.W_PointersObject)
-w_self._shadow = None
-raise PrimitiveFailedError("Bits in are not words or 
displaybitmap")
+   

[pypy-commit] lang-smalltalk rbitblt: add beep prim

2014-01-09 Thread timfel
Author: Tim Felgentreff 
Branch: rbitblt
Changeset: r555:7fcbfe51e7af
Date: 2014-01-08 10:36 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/7fcbfe51e7af/

Log:add beep prim

diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -1009,12 +1009,17 @@
 
 #
 # Misc Primitives (138 - 149)
+BEEP = 140
 VM_PATH = 142
 SHORT_AT = 143
 SHORT_AT_PUT = 144
 FILL = 145
 CLONE = 148
 
+@expose_primitive(BEEP, unwrap_spec=[object])
+def func(interp, s_frame, w_receiver):
+return w_receiver
+
 @expose_primitive(VM_PATH, unwrap_spec=[object])
 def func(interp, s_frame, w_receiver):
 return interp.space.wrap_string("%s%s" % (interp.space.executable_path(), 
os.path.sep))
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk rbitblt: add cache flushing, and store selector strings in methoddict

2014-01-09 Thread timfel
Author: Tim Felgentreff 
Branch: rbitblt
Changeset: r561:b804692b36b8
Date: 2014-01-09 16:22 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/b804692b36b8/

Log:add cache flushing, and store selector strings in methoddict

diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -801,6 +801,7 @@
 QUIT = 113
 EXIT_TO_DEBUGGER = 114
 CHANGE_CLASS = 115  # Blue Book: primitiveOopsLeft
+COMPILED_METHOD_FLUSH_CACHE = 116
 EXTERNAL_CALL = 117
 SYMBOL_FLUSH_CACHE = 119
 
@@ -886,6 +887,17 @@
 return IProxy.call(signature, interp, s_frame, argcount, s_method)
 raise PrimitiveFailedError
 
+@expose_primitive(COMPILED_METHOD_FLUSH_CACHE, unwrap_spec=[object])
+def func(interp, s_frame, w_rcvr):
+if not isinstance(w_rcvr, model.W_CompiledMethod):
+raise PrimitiveFailedError()
+s_cm = w_rcvr.as_compiledmethod_get_shadow(interp.space)
+w_class = s_cm.w_compiledin
+if w_class:
+assert isinstance(w_class, model.W_PointersObject)
+w_class.as_class_get_shadow(interp.space).flush_caches()
+return w_rcvr
+
 @expose_primitive(SYMBOL_FLUSH_CACHE, unwrap_spec=[object])
 def func(interp, s_frame, w_rcvr):
 raise PrimitiveFailedError()
@@ -1367,8 +1379,10 @@
 
 @expose_primitive(FLUSH_CACHE, unwrap_spec=[object])
 def func(interp, s_frame, w_rcvr):
-# XXX we currently don't care about bad flushes :) XXX
-# raise PrimitiveNotYetWrittenError()
+if not isinstance(w_rcvr, model.W_PointersObject):
+raise PrimitiveFailedError()
+s_class = w_rcvr.as_class_get_shadow(interp.space)
+s_class.flush_caches()
 return w_rcvr
 
 # ___
diff --git a/spyvm/shadow.py b/spyvm/shadow.py
--- a/spyvm/shadow.py
+++ b/spyvm/shadow.py
@@ -169,6 +169,13 @@
 self.store_w_superclass(w_superclass)
 self.changed()
 
+@jit.unroll_safe
+def flush_caches(self):
+look_in_shadow = self
+while look_in_shadow is not None:
+s_method = look_in_shadow.s_methoddict().sync_cache()
+look_in_shadow = look_in_shadow._s_superclass
+
 def guess_class_name(self):
 if self.name != '':
 return self.name
@@ -355,8 +362,8 @@
 
 def find_selector(self, w_selector):
 if self.invalid:
-return None
-return self.methoddict.get(w_selector, None)
+return None # we may be invalid if Smalltalk code did not call 
flushCache
+return self.methoddict.get(self._as_md_entry(w_selector), None)
 
 def update(self): return self.sync_cache()
 
@@ -370,6 +377,12 @@
 AbstractShadow.store(self, n0, w_value)
 self.invalid = True
 
+def _as_md_entry(self, w_selector):
+if isinstance(w_selector, model.W_BytesObject):
+return w_selector.as_string()
+else:
+return "%r" % w_selector # use the pointer for this
+
 def sync_cache(self):
 if self.w_self().size() == 0:
 return
@@ -394,11 +407,8 @@
"CompiledMethods only, for now. "
"If the value observed is nil, our "
"invalidating mechanism may be broken.")
-self.methoddict[w_selector] = 
w_compiledmethod.as_compiledmethod_get_shadow(self.space)
-if isinstance(w_selector, model.W_BytesObject):
-selector = w_selector.as_string()
-else:
-selector = w_selector.as_repr_string()
+selector = self._as_md_entry(w_selector)
+self.methoddict[selector] = 
w_compiledmethod.as_compiledmethod_get_shadow(self.space)
 w_compiledmethod._likely_methodname = selector
 if self.s_class:
 self.s_class.changed()
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk rbitblt: make evented code optional

2014-01-09 Thread timfel
Author: Tim Felgentreff 
Branch: rbitblt
Changeset: r559:43767dcdfe46
Date: 2014-01-09 12:59 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/43767dcdfe46/

Log:make evented code optional

diff --git a/spyvm/interpreter.py b/spyvm/interpreter.py
--- a/spyvm/interpreter.py
+++ b/spyvm/interpreter.py
@@ -25,7 +25,7 @@
 class Interpreter(object):
 _immutable_fields_ = ["space", "image", "image_name",
   "max_stack_depth", "interrupt_counter_size",
-  "startup_time"]
+  "startup_time", "evented"]
 _w_last_active_context = None
 cnt = 0
 _last_indent = ""
@@ -37,7 +37,8 @@
 )
 
 def __init__(self, space, image=None, image_name="", trace=False,
-max_stack_depth=constants.MAX_LOOP_DEPTH):
+ evented=True,
+ max_stack_depth=constants.MAX_LOOP_DEPTH):
 import time
 self.space = space
 self.image = image
@@ -47,6 +48,7 @@
 self.remaining_stack_depth = max_stack_depth
 self._loop = False
 self.next_wakeup_tick = 0
+self.evented = evented
 try:
 self.interrupt_counter_size = int(os.environ["SPY_ICS"])
 except KeyError:
diff --git a/spyvm/primitives.py b/spyvm/primitives.py
--- a/spyvm/primitives.py
+++ b/spyvm/primitives.py
@@ -631,6 +631,8 @@
 @jit.look_inside
 @expose_primitive(GET_NEXT_EVENT, unwrap_spec=[object, object])
 def func(interp, s_frame, w_rcvr, w_into):
+if not interp.evented:
+raise PrimitiveFailedError()
 ary = interp.space.get_display().get_next_event(time=interp.time_now())
 for i in range(8):
 w_into.store(interp.space, i, interp.space.wrap_int(ary[i]))
diff --git a/targetimageloadingsmalltalk.py b/targetimageloadingsmalltalk.py
--- a/targetimageloadingsmalltalk.py
+++ b/targetimageloadingsmalltalk.py
@@ -124,6 +124,7 @@
   -a|--arg [string argument to #method]
   -r|--run [code string]
   -b|--benchmark [code string]
+  -p|--poll_events
   [image path, default: Squeak.image]
 """ % argv[0]
 
@@ -139,6 +140,7 @@
 number = 0
 benchmark = None
 trace = False
+evented = True
 stringarg = ""
 code = None
 as_benchmark = False
@@ -163,6 +165,8 @@
 idx += 1
 elif arg in ["-t", "--trace"]:
 trace = True
+elif arg in ["-p", "--poll_events"]:
+evented = False
 elif arg in ["-a", "--arg"]:
 _arg_missing(argv, idx, arg)
 stringarg = argv[idx + 1]
@@ -200,7 +204,7 @@
 
 image_reader = squeakimage.reader_for_image(space, 
squeakimage.Stream(data=imagedata))
 image = create_image(space, image_reader)
-interp = interpreter.Interpreter(space, image, image_name=path, 
trace=trace)
+interp = interpreter.Interpreter(space, image, image_name=path, 
trace=trace, evented=evented)
 space.runtime_setup(argv[0])
 if benchmark is not None:
 return _run_benchmark(interp, number, benchmark, stringarg)
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] lang-smalltalk rbitblt: fix a segv, fix translation

2014-01-09 Thread timfel
Author: Tim Felgentreff 
Branch: rbitblt
Changeset: r557:ff0c5aeb1539
Date: 2014-01-08 13:30 +0100
http://bitbucket.org/pypy/lang-smalltalk/changeset/ff0c5aeb1539/

Log:fix a segv, fix translation

diff --git a/spyvm/plugins/bitblt.py b/spyvm/plugins/bitblt.py
--- a/spyvm/plugins/bitblt.py
+++ b/spyvm/plugins/bitblt.py
@@ -9,7 +9,7 @@
 
 BitBltPlugin = Plugin()
 
-@BitBltPlugin.expose_primitive(unwrap_spec=[object], clean_stack=False)
+@BitBltPlugin.expose_primitive(unwrap_spec=[object], clean_stack=True)
 def primitiveCopyBits(interp, s_frame, w_rcvr):
 from spyvm.interpreter import Return
 if not isinstance(w_rcvr, model.W_PointersObject) or w_rcvr.size() < 15:
@@ -730,10 +730,7 @@
 w_self = self.w_self()
 assert isinstance(w_self, model.W_PointersObject)
 w_self._shadow = None
-raise PrimitiveFailedError("Bits (%s) in %s are not words or 
displaybitmap" % (
-self.w_bits.as_repr_string(),
-w_self.as_repr_string()
-))
+raise PrimitiveFailedError("Bits in are not words or 
displaybitmap")
 self.width = self.space.unwrap_int(self.fetch(1))
 self.height = self.space.unwrap_int(self.fetch(2))
 self.depth = self.space.unwrap_int(self.fetch(3))
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit


[pypy-commit] pypy default: Disable SSLv2 except when a user explicity requests it

2014-01-09 Thread alex_gaynor
Author: Alex Gaynor 
Branch: 
Changeset: r68591:1bf39957a7e8
Date: 2014-01-09 10:53 -0800
http://bitbucket.org/pypy/pypy/changeset/1bf39957a7e8/

Log:Disable SSLv2 except when a user explicity requests it

diff --git a/lib-python/2.7/test/test_ssl.py b/lib-python/2.7/test/test_ssl.py
--- a/lib-python/2.7/test/test_ssl.py
+++ b/lib-python/2.7/test/test_ssl.py
@@ -993,7 +993,7 @@
 try_protocol_combo(ssl.PROTOCOL_SSLv2, ssl.PROTOCOL_SSLv2, True)
 try_protocol_combo(ssl.PROTOCOL_SSLv2, ssl.PROTOCOL_SSLv2, True, 
ssl.CERT_OPTIONAL)
 try_protocol_combo(ssl.PROTOCOL_SSLv2, ssl.PROTOCOL_SSLv2, True, 
ssl.CERT_REQUIRED)
-try_protocol_combo(ssl.PROTOCOL_SSLv2, ssl.PROTOCOL_SSLv23, True)
+try_protocol_combo(ssl.PROTOCOL_SSLv2, ssl.PROTOCOL_SSLv23, False)
 try_protocol_combo(ssl.PROTOCOL_SSLv2, ssl.PROTOCOL_SSLv3, False)
 try_protocol_combo(ssl.PROTOCOL_SSLv2, ssl.PROTOCOL_TLSv1, False)
 
diff --git a/pypy/module/_ssl/interp_ssl.py b/pypy/module/_ssl/interp_ssl.py
--- a/pypy/module/_ssl/interp_ssl.py
+++ b/pypy/module/_ssl/interp_ssl.py
@@ -711,8 +711,12 @@
 raise ssl_error(space, "SSL_CTX_use_certificate_chain_file error")
 
 # ssl compatibility
-libssl_SSL_CTX_set_options(ss.ctx, 
-   SSL_OP_ALL & 
~SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS)
+options = SSL_OP_ALL & ~SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS
+if protocol != PY_SSL_VERSION_SSL2:
+# SSLv2 is extremely broken, don't use it unless a user specifically
+# requests it
+options |= SSL_OP_NO_SSLv2
+libssl_SSL_CTX_set_options(ss.ctx, options)
 
 verification_mode = SSL_VERIFY_NONE
 if cert_mode == PY_SSL_CERT_OPTIONAL:
@@ -724,7 +728,7 @@
 libssl_SSL_set_fd(ss.ssl, sock_fd) # set the socket for SSL
 # The ACCEPT_MOVING_WRITE_BUFFER flag is necessary because the address
 # of a str object may be changed by the garbage collector.
-libssl_SSL_set_mode(ss.ssl, 
+libssl_SSL_set_mode(ss.ssl,
 SSL_MODE_AUTO_RETRY | 
SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER)
 
 # If the socket is in non-blocking mode or timeout mode, set the BIO
___
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit