[pypy-svn] r48040 - in pypy/dist/pypy/lang/smalltalk: . test

oscar at codespeak.net oscar at codespeak.net
Fri Oct 26 13:36:50 CEST 2007


Author: oscar
Date: Fri Oct 26 13:36:49 2007
New Revision: 48040

Modified:
   pypy/dist/pypy/lang/smalltalk/objtable.py
   pypy/dist/pypy/lang/smalltalk/squeakimage.py
   pypy/dist/pypy/lang/smalltalk/test/test_primitives.py
Log:
(arigo, oscar) translation fixes to objtable and squeakimage


Modified: pypy/dist/pypy/lang/smalltalk/objtable.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/objtable.py	(original)
+++ pypy/dist/pypy/lang/smalltalk/objtable.py	Fri Oct 26 13:36:49 2007
@@ -1,5 +1,5 @@
 import pypy.lang.smalltalk.classtable as ct
-from pypy.lang.smalltalk.constants import CHARACTER_VALUE_INDEX
+from pypy.lang.smalltalk import constants
 from pypy.lang.smalltalk import model
 
 # ___________________________________________________________________________
@@ -24,7 +24,7 @@
 
 def ord_w_char(w_c):
     assert w_c.getclass() is ct.w_Character
-    w_ord = w_c.fetch(CHARACTER_VALUE_INDEX)
+    w_ord = w_c.fetch(constants.CHARACTER_VALUE_INDEX)
     assert w_ord.getclass() is ct.w_SmallInteger
     assert isinstance(w_ord, model.W_SmallInteger)
     return w_ord.value
@@ -42,7 +42,7 @@
     global CharacterTable
     def bld_char(i):
         w_cinst = ct.w_Character.as_class_get_shadow().new()
-        w_cinst.store(CHARACTER_VALUE_INDEX, wrap_int(i))
+        w_cinst.store(constants.CHARACTER_VALUE_INDEX, wrap_int(i))
         return w_cinst
     CharacterTable = [bld_char(i) for i in range(256)]
 wrap_char_table()
@@ -54,3 +54,8 @@
 w_zero = wrap_int(0)
 w_one = wrap_int(1)
 w_two = wrap_int(2)
+
+objtable = {}
+
+for name in constants.objects_in_special_object_table:
+    objtable["w_" + name] = globals()["w_" + name]

Modified: pypy/dist/pypy/lang/smalltalk/squeakimage.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/squeakimage.py	(original)
+++ pypy/dist/pypy/lang/smalltalk/squeakimage.py	Fri Oct 26 13:36:49 2007
@@ -1,4 +1,5 @@
 import py
+import os
 from pypy.lang.smalltalk import model 
 from pypy.lang.smalltalk import objtable 
 from pypy.rlib import objectmodel
@@ -19,11 +20,13 @@
 
 def splitbits(integer, lengths):
     #XXX we can later let the tool chain mask and unroll this
-    assert sum(lengths) <= 32
     result = []
+    sum = 0
     for length in lengths:
+        sum += length
         result.append(integer & (2**length - 1))
         integer = integer >> length
+    assert sum <= 32
     return result
 
 
@@ -95,7 +98,7 @@
             self.stream.swap = True
             version = self.stream.peek()
             if version != 0x1966:
-                raise CorrupImageError
+                raise CorruptImageError
         version = self.stream.next()        
         #------        
         headersize = self.stream.next()
@@ -113,7 +116,7 @@
         self.stream.reset_count()
         while self.stream.count < self.endofmemory:
             chunk, pos = self.read_object()
-            if len(self.chunklist) % 1000 == 0: sys.stderr.write('#')
+            if len(self.chunklist) % 1000 == 0: os.write(2,'#')
             self.chunklist.append(chunk)
             self.chunks[pos + self.oldbaseaddress] = chunk
         self.stream.close()    
@@ -134,11 +137,13 @@
         from pypy.lang.smalltalk import classtable, constants, objtable
         # assign w_objects for objects that are already in classtable
         for name, so_index in constants.classes_in_special_object_table.items():
-            w_object = getattr(classtable, "w_" + name)
+            # w_object = getattr(classtable, "w_" + name)
+            w_object = classtable.classtable["w_" + name]
             self.special_object(so_index).w_object = w_object
         # assign w_objects for objects that are already in objtable
         for name, so_index in constants.objects_in_special_object_table.items():
-            w_object = getattr(objtable, "w_" + name)
+            # w_object = getattr(objtable, "w_" + name)
+            w_object = objtable.objtable["w_" + name]
             self.special_object(so_index).w_object = w_object
 
     def special_object(self, index):

Modified: pypy/dist/pypy/lang/smalltalk/test/test_primitives.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/test/test_primitives.py	(original)
+++ pypy/dist/pypy/lang/smalltalk/test/test_primitives.py	Fri Oct 26 13:36:49 2007
@@ -5,6 +5,7 @@
 from pypy.lang.smalltalk import interpreter
 from pypy.lang.smalltalk import classtable
 from pypy.lang.smalltalk import objtable
+from pypy.lang.smalltalk import constants
 from pypy.rlib.rarithmetic import INFINITY, NAN, isinf, isnan
 
 # Violates the guideline, but we use it A LOT to reference the primitive codes:
@@ -195,11 +196,11 @@
         assert prim(primitives.STRING_AT, [test_str, i]) == wrap(exp[i])
 
 def test_object_at():
-    w_v = prim(primitives.OBJECT_AT, ["q", objtable.CHARACTER_VALUE_INDEX+1])
+    w_v = prim(primitives.OBJECT_AT, ["q", constants.CHARACTER_VALUE_INDEX+1])
     assert w_v.value == ord("q")
 
 def test_invalid_object_at():
-    prim_fails(primitives.OBJECT_AT, ["q", objtable.CHARACTER_VALUE_INDEX+2])
+    prim_fails(primitives.OBJECT_AT, ["q", constants.CHARACTER_VALUE_INDEX+2])
     
 def test_object_at_put():
     w_obj = mockclass(1).as_class_get_shadow().new()
@@ -237,7 +238,7 @@
 def test_inst_var_at():
     # I am not entirely sure if this is what this primitive is
     # supposed to do, so the test may be bogus:
-    w_v = prim(primitives.INST_VAR_AT, ["q", objtable.CHARACTER_VALUE_INDEX])
+    w_v = prim(primitives.INST_VAR_AT, ["q", constants.CHARACTER_VALUE_INDEX])
     assert w_v.value == ord("q")
     w_v = prim(primitives.INST_VAR_AT, ["abc", 1])
     assert w_v.value == ord("b")



More information about the Pypy-commit mailing list