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

niko at codespeak.net niko at codespeak.net
Wed Oct 24 13:31:13 CEST 2007


Author: niko
Date: Wed Oct 24 13:31:12 2007
New Revision: 47816

Modified:
   pypy/dist/pypy/lang/smalltalk/classtable.py
   pypy/dist/pypy/lang/smalltalk/primitives.py
   pypy/dist/pypy/lang/smalltalk/test/test_primitives.py
Log:
implemnt NEW and NEW_WITH_ARG



Modified: pypy/dist/pypy/lang/smalltalk/classtable.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/classtable.py	(original)
+++ pypy/dist/pypy/lang/smalltalk/classtable.py	Wed Oct 24 13:31:12 2007
@@ -26,9 +26,9 @@
         meta_nm = cls_nm + "Class"
         meta_super_nm = super_cls_nm + "Class"
         metacls = define_core_cls(
-            meta_nm, W_MetaClass(None, classtable[meta_super_nm], meta_nm))
+            meta_nm, W_MetaClass(None, classtable[meta_super_nm], name=meta_nm))
         define_core_cls(
-            cls_nm, W_Class(metacls, classtable[super_cls_nm], cls_nm))
+            cls_nm, W_Class(metacls, classtable[super_cls_nm], name=cls_nm))
     w_ProtoObjectClass.w_superclass = w_Class
     for nm, w_cls_obj in classtable.items():
         if w_cls_obj.ismetaclass():

Modified: pypy/dist/pypy/lang/smalltalk/primitives.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/primitives.py	(original)
+++ pypy/dist/pypy/lang/smalltalk/primitives.py	Wed Oct 24 13:31:12 2007
@@ -114,6 +114,8 @@
 STRING_AT_PUT = 64
 OBJECT_AT = 68
 OBJECT_AT_PUT = 69
+NEW = 70
+NEW_WITH_ARG = 71
 
 def common_at(stack):
     [w_idx, w_obj] = stack
@@ -185,6 +187,23 @@
     w_rcvr.setnamedvar(idx, w_val)
     return w_val
 
+ at primitive(NEW)
+ at stack(1)
+def func(stack):
+    [w_cls] = stack
+    if not isinstance(w_cls, model.W_Class) or w_cls.isindexable():
+        raise PrimitiveFailedError()
+    return w_cls.new()
+
+ at primitive(NEW_WITH_ARG)
+ at stack(2)
+def func(stack):
+    [w_size, w_cls] = stack
+    if not isinstance(w_cls, model.W_Class) or not w_cls.isindexable():
+        raise PrimitiveFailedError()
+    size = unwrap_int(w_size)
+    return w_cls.new(size)
+
 # ___________________________________________________________________________
 # Boolean Primitives
 

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	Wed Oct 24 13:31:12 2007
@@ -102,6 +102,21 @@
     for i in range(len(exp)):
         assert prim(p.STRING_AT, [test_str, i]) == wrap(exp[i])
 
+def test_new():
+    w_res = prim(p.NEW, [ct.w_Object])
+    assert w_res.w_class == ct.w_Object
+    
+def test_invalid_new():
+    prim_fails(p.NEW, [ct.w_ByteString])
+
+def test_new_with_arg():
+    w_res = prim(p.NEW_WITH_ARG, [ct.w_ByteString, 20])
+    assert w_res.w_class == ct.w_ByteString
+    assert w_res.size() == 20    
+
+def test_invalid_new_with_arg():
+    prim_fails(p.NEW_WITH_ARG, [ct.w_Object, 20])
+
 def test_boolean():
     assert prim(p.LESSTHAN, [1,2]) == fimg.w_true
     assert prim(p.GREATERTHAN, [3,4]) == fimg.w_false



More information about the Pypy-commit mailing list