[pypy-svn] r48014 - pypy/dist/pypy/lang/smalltalk/test
akuhn at codespeak.net
akuhn at codespeak.net
Fri Oct 26 01:13:28 CEST 2007
Author: akuhn
Date: Fri Oct 26 01:13:28 2007
New Revision: 48014
Modified:
pypy/dist/pypy/lang/smalltalk/test/test_miniimage.py
Log:
(akuhn, tverwaes)
trying to perform(w(10).getclass(), "compile:classified:notifying:", w(sourcecode), w('pypy'), w(None))
Modified: pypy/dist/pypy/lang/smalltalk/test/test_miniimage.py
==============================================================================
--- pypy/dist/pypy/lang/smalltalk/test/test_miniimage.py (original)
+++ pypy/dist/pypy/lang/smalltalk/test/test_miniimage.py Fri Oct 26 01:13:28 2007
@@ -224,3 +224,45 @@
assert w_true is objtable.w_true
w_false = image.special(constants.SO_FALSE)
assert w_false is objtable.w_false
+
+def test_compile_method():
+ py.test.skip("Todo, make compiling of methods in mini.image work.")
+ sourcecode = """fib
+ ^self < 2
+ ifTrue: [ 1 ]
+ ifFalse: [ (self - 1) fib + (self - 2) fib ]"""
+ perform(w(10).getclass(), "compile:classified:notifying:", w(sourcecode), w('pypy'), w(None))
+ assert perform(w(10), "fib") == w(89)
+
+def w(any):
+ if any is None:
+ return objtable.w_nil
+ if isinstance(any, str):
+ # assume never have strings of length 1
+ if len(any) == 1:
+ return objtable.wrap_chr(any)
+ else:
+ return objtable.wrap_string(any)
+ if isinstance(any, int):
+ return objtable.wrap_int(any)
+ if isinstance(any, bool):
+ return objtable.wrap_bool(any)
+ if isinstance(any, float):
+ return objtable.wrap_float(any)
+ else:
+ raise Exception
+
+def perform(w_receiver, selector, *arguments_w):
+ interp = interpreter.Interpreter()
+ s_class = w_receiver.shadow_of_my_class()
+ w_method = s_class.lookup(selector)
+ assert w_method
+ w_frame = w_method.create_frame(w_receiver, list(arguments_w))
+ interp.w_active_context = w_frame
+ while True:
+ try:
+ interp.step()
+ #print interp.w_active_context.stack
+ except interpreter.ReturnFromTopLevel, e:
+ return e.object.value
+
\ No newline at end of file
More information about the pypy-svn
mailing list