From cfbolz at codespeak.net Sun Jul 1 13:33:00 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Sun, 1 Jul 2007 13:33:00 +0200 (CEST) Subject: [pypy-svn] r44647 - pypy/extradoc/talk/badhonnef2007 Message-ID: <20070701113300.549C480C0@code0.codespeak.net> Author: cfbolz Date: Sun Jul 1 13:32:58 2007 New Revision: 44647 Added: pypy/extradoc/talk/badhonnef2007/Makefile pypy/extradoc/talk/badhonnef2007/badhonnef.tex pypy/extradoc/talk/badhonnef2007/dyla.bib - copied unchanged from r44646, pypy/extradoc/talk/dyla2007/dyla.bib pypy/extradoc/talk/badhonnef2007/llncs.cls - copied unchanged from r44646, pypy/extradoc/talk/dyla2007/llncs.cls Log: beginnig of the bad honnef paper Added: pypy/extradoc/talk/badhonnef2007/Makefile ============================================================================== --- (empty file) +++ pypy/extradoc/talk/badhonnef2007/Makefile Sun Jul 1 13:32:58 2007 @@ -0,0 +1,15 @@ +badhonnef.pdf: badhonnef.tex badhonnef.bib + pdflatex badhonnef + bibtex badhonnef + pdflatex badhonnef + pdflatex badhonnef + +%.pdf: %.eps + epstopdf $< + +view: badhonnef.pdf + xpdf badhonnef.pdf & + +clean: + rm badhonnef.pdf + Added: pypy/extradoc/talk/badhonnef2007/badhonnef.tex ============================================================================== --- (empty file) +++ pypy/extradoc/talk/badhonnef2007/badhonnef.tex Sun Jul 1 13:32:58 2007 @@ -0,0 +1,84 @@ +\documentclass{llncs} + +\usepackage{makeidx} +\usepackage{graphicx} + +\begin{document} + +\pagestyle{headings} + +\title{A Flexible Prolog Interpreter in Python} + +%\titlerunning{XXX} % abbreviated title (for running head) +% also used for the TOC unless +% \toctitle is used + +\author{Carl Friedrich Bolz} + +\authorrunning{Bolz} % abbreviated author list (for running head) + +%%%% modified list of authors for the TOC (add the affiliations) +\tocauthor{Bolz (D\"usseldorf)} + +\institute{ Lehrstuhl Softwaretechnik und Programmiersprachen\\ +Institut f\"{u}r Informatik, Universit\"at D\"usseldorf, Germany\\ + \email{ cfbolz at gmx.de}} + +\maketitle + +\begin{abstract} + +Efficient virtual machines for the Prolog programming language (and also for +other dynamic highlevel languages) are usually large and intricate pieces of +software implemented in a low-level language such as C that are extensively +optimized over many years and are therefore difficult to change in many +respects. Due to their inherent complexity it is hard to develop them further, +to maintain them or to use them to experiment with language extensions or new +built-ins. + +Early implementation decisions, such as choice of garbage collector, are +extremely hard to change afterwards. In addition, it is also much harder to +perform advanced optimizations or transformations (such as partial evaluation) +on the virtual machine itself due to the low level of the implementation +language. Furthermore it is (by definition) impossible to port them to a non-C +platform such as the Java Virtual Machine or the .NET framework Therefore the +numerous implementations of a Prolog virtual machine integrated into one of +these environments are all new implementations which have to be maintained +themselves and therefore all have different levels of maturity and slightly +different sets of built-ins available. + +Using a higher-level language than C addresses many of these problems. It +allows the language implementor to work at a higher level of abstraction, which +eases implementation, maintenance and extensions of the virtual machine and +reduces the size of the code base. Furthermore, advanced optimizations and +transformations can be performed. To regain usable performance the +implementation needs then to be translated to a low-level language again. + +The goal of the PyPy project is to support the implementation of interpreters +in the high-level language Python. Python is an object oriented dynamic +language which is becoming more and more popular for scripting use as well as +for ?real? applications. PyPy provides a translation toolchain that helps to +translate interpreters written in Python to a low-level language such as C and +the .NET Intermediate Language. To make this translation work, these +interpreters have to be written in RPython, which is a proper subset of Python +chosen in such a way that it is amenable to analysis. + +In this talk we give an quick overview of the PyPy project and present a Prolog +interpreter written in RPython, exploring the possibilities of implementing a +well-known declarative language in a high-level language (as opposed to C). One +of the main goals of the implementation was to keep it as simple and as +extensible as possible (even at the cost of performance). The PyPy tool suite +is used to reach a reasonable level of performance and to ensure portability to +various platforms.\footnote{This research was partially supported by the EU funded + project: IST 004779 PyPy (PyPy: Implementing Python in Python).} \\ + +\end{abstract} + + +% ---- Bibliography ---- +%\begin{small} +\bibliographystyle{abbrv} +\bibliography{badhonnef} +%\end{small} + +\end{document} From cfbolz at codespeak.net Mon Jul 2 01:02:48 2007 From: cfbolz at codespeak.net (cfbolz at codespeak.net) Date: Mon, 2 Jul 2007 01:02:48 +0200 (CEST) Subject: [pypy-svn] r44657 - pypy/extradoc/talk/badhonnef2007 Message-ID: <20070701230248.ABC5880A9@code0.codespeak.net> Author: cfbolz Date: Mon Jul 2 01:02:47 2007 New Revision: 44657 Added: pypy/extradoc/talk/badhonnef2007/badhonnef.bib - copied unchanged from r44655, pypy/extradoc/talk/badhonnef2007/dyla.bib Removed: pypy/extradoc/talk/badhonnef2007/dyla.bib Log: rename bib file From bea at codespeak.net Mon Jul 2 17:59:12 2007 From: bea at codespeak.net (bea at codespeak.net) Date: Mon, 2 Jul 2007 17:59:12 +0200 (CEST) Subject: [pypy-svn] r44674 - pypy/extradoc/sprintinfo/post-ep2007 Message-ID: <20070702155912.8A08680A5@code0.codespeak.net> Author: bea Date: Mon Jul 2 17:59:11 2007 New Revision: 44674 Modified: pypy/extradoc/sprintinfo/post-ep2007/people.txt Log: my dates for ep2007 Modified: pypy/extradoc/sprintinfo/post-ep2007/people.txt ============================================================================== --- pypy/extradoc/sprintinfo/post-ep2007/people.txt (original) +++ pypy/extradoc/sprintinfo/post-ep2007/people.txt Mon Jul 2 17:59:11 2007 @@ -20,6 +20,7 @@ Christian Tismer 8/16th Ratonda Centrum Hotels Simon Burton 8/15th Armin Rigo 8/16th Comfort Vilnius +Bea D?ring 8/13th Comfort Vilnius ==================== ============== ======================= People on the following list were present at previous sprints: From jlg at codespeak.net Tue Jul 3 11:23:47 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Tue, 3 Jul 2007 11:23:47 +0200 (CEST) Subject: [pypy-svn] r44689 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070703092347.3484980BA@code0.codespeak.net> Author: jlg Date: Tue Jul 3 11:23:46 2007 New Revision: 44689 Modified: pypy/dist/pypy/lang/scheme/object.py pypy/dist/pypy/lang/scheme/test/test_eval.py pypy/dist/pypy/lang/scheme/test/test_object.py pypy/dist/pypy/lang/scheme/test/test_parser.py Log: procedure identifier evals to W_Procedure; W_procedure refactoring Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Tue Jul 3 11:23:46 2007 @@ -33,7 +33,7 @@ w_obj = ctx.get(self.name) if w_obj is not None: - return w_obj.eval(ctx) + return w_obj #.eval(ctx) else: #reference to undefined identifier #unbound @@ -117,7 +117,7 @@ def eval(self, ctx): oper = self.car.eval(ctx) - return oper(ctx, self.cdr) + return oper.eval(ctx, self.cdr) class W_Nil(W_Root): def to_string(self): @@ -129,7 +129,6 @@ #it its very similar to operation.add ############################# class W_Procedure(W_Root): - def __init__(self, pname=""): self.pname = pname @@ -137,19 +136,10 @@ return "#" % (self.pname,) def eval(self, ctx, lst=None): - raise NotImplementedError - -def add_lst(ctx, lst): - def adder(x, y): - return x + y - - return apply_lst(ctx, adder, lst) - -def mul_lst(ctx, lst): - def multiplier(x, y): - return x * y + return self.oper(ctx, lst) - return apply_lst(ctx, multiplier, lst) + def oper(self, ctx, lst): + raise NotImplementedError def apply_lst(ctx, fun, lst): acc = None @@ -172,67 +162,59 @@ return W_Float(acc) class Add(W_Procedure): - def eval(self, ctx): - return add_lst + def adder(self, x, y): + return x + y + + def oper(self, ctx, lst): + return apply_lst(ctx, self.adder, lst) class Mul(W_Procedure): - def eval(self, ctx): - return mul_lst + def multiplier(self, x, y): + return x * y -def define(ctx, lst): - w_identifier = lst.car - assert isinstance(w_identifier, W_Identifier) - - w_val = lst.cdr.car.eval(ctx) - ctx.put(w_identifier.name, w_val) - return w_val + def oper(self, ctx, lst): + return apply_lst(ctx, self.multiplier, lst) class Define(W_Procedure): - def eval(self, ctx): - return define - -def macro_if(ctx, lst): - w_condition = lst.car - w_then = lst.cdr.car - if isinstance(lst.cdr.cdr, W_Nil): - w_else = W_Boolean(False) - else: - w_else = lst.cdr.cdr.car - - w_cond_val = w_condition.eval(ctx) - if w_cond_val.to_boolean() is True: - return w_then.eval(ctx) - else: - return w_else.eval(ctx) + def oper(self, ctx, lst): + w_identifier = lst.car + assert isinstance(w_identifier, W_Identifier) + + w_val = lst.cdr.car.eval(ctx) + ctx.put(w_identifier.name, w_val) + return w_val class MacroIf(W_Procedure): - def eval(self, ctx): - return macro_if + def oper(self, ctx, lst): + w_condition = lst.car + w_then = lst.cdr.car + if isinstance(lst.cdr.cdr, W_Nil): + w_else = W_Boolean(False) + else: + w_else = lst.cdr.cdr.car -def cons(ctx, lst): - w_car = lst.car.eval(ctx) - w_cdr = lst.cdr.car.eval(ctx) - return W_Pair(w_car, w_cdr) + w_cond_val = w_condition.eval(ctx) + if w_cond_val.to_boolean() is True: + return w_then.eval(ctx) + else: + return w_else.eval(ctx) class Cons(W_Procedure): - def eval(self, ctx): - return cons - -def car(ctx, lst): - w_pair = lst.car.eval(ctx) - return w_pair.car + def oper(self, ctx, lst): + w_car = lst.car.eval(ctx) + w_cdr = lst.cdr.car.eval(ctx) + #cons is always creating a new pair + return W_Pair(w_car, w_cdr) class Car(W_Procedure): - def eval(self, ctx): - return car - -def cdr(ctx, lst): - w_pair = lst.car.eval(ctx) - return w_pair.cdr + def oper(self, ctx, lst): + w_pair = lst.car.eval(ctx) + return w_pair.car class Cdr(W_Procedure): - def eval(self, ctx): - return cdr + def oper(self, ctx, lst): + w_pair = lst.car.eval(ctx) + return w_pair.cdr ###################################### # dict mapping operations to callables Modified: pypy/dist/pypy/lang/scheme/test/test_eval.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_eval.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_eval.py Tue Jul 3 11:23:46 2007 @@ -2,6 +2,7 @@ from pypy.lang.scheme.ssparser import parse from pypy.lang.scheme.object import W_Boolean, W_Fixnum, W_Float, W_String from pypy.lang.scheme.object import W_Nil, W_Pair, W_Symbol, W_Identifier +from pypy.lang.scheme.object import W_Procedure from pypy.lang.scheme.object import ExecutionContext from pypy.lang.scheme.operation import mul, add @@ -85,6 +86,11 @@ w_num = eval_expr(ctx, "(+ 1 v1 v2)") assert w_num.to_number() == 46.1 +def test_func(): + ctx = ExecutionContext() + w_func = eval_expr(ctx, "+") + assert isinstance(w_func, W_Procedure) + def test_if_simple(): ctx = ExecutionContext() w_t = eval_expr(ctx, "(if #t #t #f)") Modified: pypy/dist/pypy/lang/scheme/test/test_object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_object.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_object.py Tue Jul 3 11:23:46 2007 @@ -67,3 +67,26 @@ assert w_fnum is ctx.get("v1") assert ctx.get("no_such_key") is None +def test_location(): + w_fnum = W_Fixnum(42) + loc = Location(w_fnum) + assert isinstance(loc, Location) + assert loc.obj is w_fnum + +def test_ctx_sets(): + w_fnum = W_Fixnum(42) + w_fnum2 = W_Fixnum(43) + w_fnum3 = W_Fixnum(44) + + ctx = ExecutionContext({}) + ctx.put("v1", w_fnum) + + ctx2 = ctx.copy() + assert w_fnum is ctx2.get("v1") + ctx.set("v1", w_fnum2) + assert w_fnum2 is ctx2.get("v1") + assert w_fnum2 is ctx.get("v1") + + ctx2.put("v1", w_fnum3) + assert w_fnum3 is ctx2.get("v1") + Modified: pypy/dist/pypy/lang/scheme/test/test_parser.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_parser.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_parser.py Tue Jul 3 11:23:46 2007 @@ -54,6 +54,14 @@ assert unwrap(w_float) == -123456.1234 def test_sexpr(): + w_list = parse('( 1 )') + assert isinstance(w_list, W_Pair) + assert isinstance(w_list.car, W_Fixnum) + assert isinstance(w_list.cdr, W_Nil) + + #w_list = parse('()') + #assert isinstance(w_list, W_Nil) + w_list = parse('(+ 1 2)') assert isinstance(w_list, W_Pair) assert isinstance(w_list.car, W_Identifier) From jlg at codespeak.net Tue Jul 3 11:24:44 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Tue, 3 Jul 2007 11:24:44 +0200 (CEST) Subject: [pypy-svn] r44690 - pypy/dist/pypy/lang/scheme Message-ID: <20070703092444.6510B80B6@code0.codespeak.net> Author: jlg Date: Tue Jul 3 11:24:41 2007 New Revision: 44690 Modified: pypy/dist/pypy/lang/scheme/object.py Log: Location() object; context uses Location() Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Tue Jul 3 11:24:41 2007 @@ -123,11 +123,9 @@ def to_string(self): return "()" -############################ +## # operations -#not sure though any operations should exist here -#it its very similar to operation.add -############################# +## class W_Procedure(W_Root): def __init__(self, pname=""): self.pname = pname @@ -216,23 +214,34 @@ w_pair = lst.car.eval(ctx) return w_pair.cdr -###################################### -# dict mapping operations to callables +## +# Location() +## +class Location(object): + def __init__(self, w_obj): + self.obj = w_obj + +## +# dict mapping operations to W_Xxx objects # callables must have 2 arguments # - ctx = execution context # - lst = list of arguments -###################################### -OPERATION_MAP = \ +## +OMAP = \ { - '+': Add("+"), - '*': Mul("*"), - 'define': Define("define"), - 'if': MacroIf("if"), - 'cons': Cons("cons"), - 'car': Car("car"), - 'cdr': Cdr("cdr"), + '+': Add, + '*': Mul, + 'define': Define, + 'if': MacroIf, + 'cons': Cons, + 'car': Car, + 'cdr': Cdr, } +OPERATION_MAP = {} +for name, cls in OMAP.items(): + OPERATION_MAP[name] = Location(cls(name)) + class ExecutionContext(object): """Execution context implemented as a dict. @@ -242,9 +251,28 @@ assert scope is not None self.scope = scope + def copy(self): + return ExecutionContext(dict(self.scope)) + def get(self, name): - return self.scope.get(name, None) + loc = self.scope.get(name, None) + + if loc is not None: + return loc.obj + else: + return None + + def set(self, name, obj): + loc = self.scope.get(name, None) + + if loc is not None: + loc.obj = obj + else: + self.put(name, obj) def put(self, name, obj): - self.scope[name] = obj + """Overwrites existing variable location + (new location is created) + """ + self.scope[name] = Location(obj) From jlg at codespeak.net Tue Jul 3 14:19:23 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Tue, 3 Jul 2007 14:19:23 +0200 (CEST) Subject: [pypy-svn] r44694 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070703121923.11BED80B1@code0.codespeak.net> Author: jlg Date: Tue Jul 3 14:19:22 2007 New Revision: 44694 Modified: pypy/dist/pypy/lang/scheme/object.py pypy/dist/pypy/lang/scheme/test/test_eval.py Log: W_Macro != W_Procedure; lambda prototype added Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Tue Jul 3 14:19:22 2007 @@ -123,6 +123,11 @@ def to_string(self): return "()" +class W_Lambda(W_Root): + def __init__(self, args, body): + self.args = args + self.body = body + ## # operations ## @@ -139,6 +144,16 @@ def oper(self, ctx, lst): raise NotImplementedError +class W_Macro(W_Root): + def __init__(self, pname=""): + self.pname = pname + + def to_string(self): + return "#" % (self.pname,) + + def eval(self, ctx, lst=None): + raise NotImplementedError + def apply_lst(ctx, fun, lst): acc = None @@ -173,17 +188,17 @@ def oper(self, ctx, lst): return apply_lst(ctx, self.multiplier, lst) -class Define(W_Procedure): - def oper(self, ctx, lst): +class Define(W_Macro): + def eval(self, ctx, lst): w_identifier = lst.car assert isinstance(w_identifier, W_Identifier) w_val = lst.cdr.car.eval(ctx) - ctx.put(w_identifier.name, w_val) + ctx.set(w_identifier.name, w_val) return w_val -class MacroIf(W_Procedure): - def oper(self, ctx, lst): +class MacroIf(W_Macro): + def eval(self, ctx, lst): w_condition = lst.car w_then = lst.cdr.car if isinstance(lst.cdr.cdr, W_Nil): @@ -214,6 +229,12 @@ w_pair = lst.car.eval(ctx) return w_pair.cdr +class Lambda(W_Macro): + def eval(self, ctx, lst): + w_args = lst.car + w_body = lst.cdr.car + return W_Lambda(w_args, w_body) + ## # Location() ## @@ -236,6 +257,7 @@ 'cons': Cons, 'car': Car, 'cdr': Cdr, + 'lambda': Lambda, } OPERATION_MAP = {} Modified: pypy/dist/pypy/lang/scheme/test/test_eval.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_eval.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_eval.py Tue Jul 3 14:19:22 2007 @@ -2,7 +2,7 @@ from pypy.lang.scheme.ssparser import parse from pypy.lang.scheme.object import W_Boolean, W_Fixnum, W_Float, W_String from pypy.lang.scheme.object import W_Nil, W_Pair, W_Symbol, W_Identifier -from pypy.lang.scheme.object import W_Procedure +from pypy.lang.scheme.object import W_Procedure, W_Lambda from pypy.lang.scheme.object import ExecutionContext from pypy.lang.scheme.operation import mul, add @@ -144,3 +144,8 @@ w_cddr = eval_noctx("(cdr (cdr (cons 1 (cons 2 3))))") assert w_cddr.to_number() == 3 +def test_lambda_definition(): + ctx = ExecutionContext() + w_lambda = eval_expr(ctx, "(lambda () 12)") + assert isinstance(w_lambda, W_Lambda) + From jlg at codespeak.net Tue Jul 3 14:41:44 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Tue, 3 Jul 2007 14:41:44 +0200 (CEST) Subject: [pypy-svn] r44696 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070703124144.F270180B6@code0.codespeak.net> Author: jlg Date: Tue Jul 3 14:41:43 2007 New Revision: 44696 Modified: pypy/dist/pypy/lang/scheme/object.py pypy/dist/pypy/lang/scheme/test/test_eval.py Log: trivial lambdas with arguments works Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Tue Jul 3 14:41:43 2007 @@ -128,6 +128,20 @@ self.args = args self.body = body + def eval(self, ctx, lst): + name = self.args + val = lst + my_ctx = ctx.copy() + while not isinstance(name, W_Nil): + assert isinstance(name.car, W_Identifier) + w_val = val.car.eval(ctx) + my_ctx.put(name.car.to_string(), w_val) + + val = val.cdr + name = name.cdr + + return self.body.eval(my_ctx) + ## # operations ## Modified: pypy/dist/pypy/lang/scheme/test/test_eval.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_eval.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_eval.py Tue Jul 3 14:41:43 2007 @@ -144,8 +144,21 @@ w_cddr = eval_noctx("(cdr (cdr (cons 1 (cons 2 3))))") assert w_cddr.to_number() == 3 -def test_lambda_definition(): +def test_lambda_noargs(): ctx = ExecutionContext() w_lambda = eval_expr(ctx, "(lambda () 12)") assert isinstance(w_lambda, W_Lambda) + ctx.put("f1", w_lambda) + w_result = eval_expr(ctx, "(f1)") + assert isinstance(w_result, W_Fixnum) + assert w_result.to_number() == 12 + +def test_lambda_args(): + ctx = ExecutionContext() + eval_expr(ctx, "(define f1 (lambda (n) n))") + + w_result = eval_expr(ctx, "(f1 42)") + assert isinstance(w_result, W_Fixnum) + assert w_result.to_number() == 42 + From jlg at codespeak.net Tue Jul 3 14:55:01 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Tue, 3 Jul 2007 14:55:01 +0200 (CEST) Subject: [pypy-svn] r44697 - pypy/dist/pypy/lang/scheme/test Message-ID: <20070703125501.1622480BA@code0.codespeak.net> Author: jlg Date: Tue Jul 3 14:55:00 2007 New Revision: 44697 Modified: pypy/dist/pypy/lang/scheme/test/test_eval.py Log: test lambdas (context lookup) Modified: pypy/dist/pypy/lang/scheme/test/test_eval.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_eval.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_eval.py Tue Jul 3 14:55:00 2007 @@ -162,3 +162,20 @@ assert isinstance(w_result, W_Fixnum) assert w_result.to_number() == 42 + w_result = eval_expr(ctx, "((lambda (n m) (+ n m)) 42 -42)") + assert isinstance(w_result, W_Fixnum) + assert w_result.to_number() == 0 + +def test_lambda_top_ctx(): + ctx = ExecutionContext() + eval_expr(ctx, "(define n 42)") + eval_expr(ctx, "(define f1 (lambda (m) (+ n m)))") + w_result = eval_expr(ctx, "(f1 -42)") + assert isinstance(w_result, W_Fixnum) + assert w_result.to_number() == 0 + + eval_expr(ctx, "(define n 84)") + w_result = eval_expr(ctx, "(f1 -42)") + assert isinstance(w_result, W_Fixnum) + assert w_result.to_number() == 42 + From jlg at codespeak.net Tue Jul 3 17:08:01 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Tue, 3 Jul 2007 17:08:01 +0200 (CEST) Subject: [pypy-svn] r44704 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070703150801.5D15180A9@code0.codespeak.net> Author: jlg Date: Tue Jul 3 17:08:00 2007 New Revision: 44704 Modified: pypy/dist/pypy/lang/scheme/object.py pypy/dist/pypy/lang/scheme/test/test_eval.py Log: procedures refactoring; Sub procedure added Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Tue Jul 3 17:08:00 2007 @@ -123,10 +123,37 @@ def to_string(self): return "()" -class W_Lambda(W_Root): - def __init__(self, args, body): +class W_Procedure(W_Root): + def __init__(self, pname=""): + self.pname = pname + + def to_string(self): + return "#" % (self.pname,) + + def eval(self, ctx, lst): + return self.procedure(ctx, lst) + + def procedure(self, ctx, lst): + raise NotImplementedError + +class W_Macro(W_Root): + def __init__(self, pname=""): + self.pname = pname + + def to_string(self): + return "#" % (self.pname,) + + def eval(self, ctx, lst=None): + raise NotImplementedError + +class W_Lambda(W_Procedure): + def __init__(self, args, body, pname="#f"): self.args = args self.body = body + self.pname = pname + + def to_string(self): + return "#" % (self.pname,) def eval(self, ctx, lst): name = self.args @@ -145,29 +172,6 @@ ## # operations ## -class W_Procedure(W_Root): - def __init__(self, pname=""): - self.pname = pname - - def to_string(self): - return "#" % (self.pname,) - - def eval(self, ctx, lst=None): - return self.oper(ctx, lst) - - def oper(self, ctx, lst): - raise NotImplementedError - -class W_Macro(W_Root): - def __init__(self, pname=""): - self.pname = pname - - def to_string(self): - return "#" % (self.pname,) - - def eval(self, ctx, lst=None): - raise NotImplementedError - def apply_lst(ctx, fun, lst): acc = None @@ -188,19 +192,27 @@ else: return W_Float(acc) -class Add(W_Procedure): - def adder(self, x, y): +class ListOper(W_Procedure): + def procedure(self, ctx, lst): + return apply_lst(ctx, self.oper, lst) + +class Add(ListOper): + def oper(self, x, y): return x + y - def oper(self, ctx, lst): - return apply_lst(ctx, self.adder, lst) +class Sub(ListOper): + def procedure(self, ctx, lst): + if isinstance(lst.cdr, W_Nil): + return apply_lst(ctx, self.oper, W_Pair( W_Fixnum(0), lst)) + else: + return apply_lst(ctx, self.oper, lst) -class Mul(W_Procedure): - def multiplier(self, x, y): - return x * y + def oper(self, x, y): + return x - y - def oper(self, ctx, lst): - return apply_lst(ctx, self.multiplier, lst) +class Mul(ListOper): + def oper(self, x, y): + return x * y class Define(W_Macro): def eval(self, ctx, lst): @@ -227,19 +239,19 @@ return w_else.eval(ctx) class Cons(W_Procedure): - def oper(self, ctx, lst): + def procedure(self, ctx, lst): w_car = lst.car.eval(ctx) w_cdr = lst.cdr.car.eval(ctx) #cons is always creating a new pair return W_Pair(w_car, w_cdr) class Car(W_Procedure): - def oper(self, ctx, lst): + def procedure(self, ctx, lst): w_pair = lst.car.eval(ctx) return w_pair.car class Cdr(W_Procedure): - def oper(self, ctx, lst): + def procedure(self, ctx, lst): w_pair = lst.car.eval(ctx) return w_pair.cdr @@ -265,6 +277,7 @@ OMAP = \ { '+': Add, + '-': Sub, '*': Mul, 'define': Define, 'if': MacroIf, Modified: pypy/dist/pypy/lang/scheme/test/test_eval.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_eval.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_eval.py Tue Jul 3 17:08:00 2007 @@ -53,6 +53,13 @@ w_num = eval_noctx("(* 4 -5 6.1)") assert w_num.to_number() == (4 * -5 * 6.1) + w_num = eval_noctx("(- 4)") + assert w_num.to_number() == -4 + w_num = eval_noctx("(- 4 5)") + assert w_num.to_number() == -1 + w_num = eval_noctx("(- 4 -5 6.1)") + assert w_num.to_number() == 4 - (-5) - 6.1 + def test_numerical_nested(): w_num = eval_noctx("(+ 4 (* (+ 5) 6) (+ 1 2))") assert w_num.to_number() == 37 From jlg at codespeak.net Tue Jul 3 17:28:13 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Tue, 3 Jul 2007 17:28:13 +0200 (CEST) Subject: [pypy-svn] r44705 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070703152813.0BEC680AB@code0.codespeak.net> Author: jlg Date: Tue Jul 3 17:28:13 2007 New Revision: 44705 Modified: pypy/dist/pypy/lang/scheme/object.py pypy/dist/pypy/lang/scheme/test/test_eval.py Log: number comparison: Equal; recursive factorial lambda test Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Tue Jul 3 17:28:13 2007 @@ -90,6 +90,9 @@ def to_float(self): return float(self.fixnumval) + def equal(self, w_obj): + return self.fixnumval == w_obj.to_number() + class W_Float(W_Root): def __init__(self, val): self.floatval = float(val) @@ -106,6 +109,9 @@ def to_float(self): return self.floatval + def equal(self, w_obj): + return self.floatval == w_obj.to_number() + class W_Pair(W_Root): def __init__(self, car, cdr): self.car = car @@ -255,6 +261,12 @@ w_pair = lst.car.eval(ctx) return w_pair.cdr +class Equal(W_Procedure): + def procedure(self, ctx, lst): + w_first = lst.car.eval(ctx) + w_second = lst.cdr.car.eval(ctx) + return W_Boolean(w_first.equal(w_second)) + class Lambda(W_Macro): def eval(self, ctx, lst): w_args = lst.car @@ -276,14 +288,19 @@ ## OMAP = \ { + #arithmetic operations '+': Add, '-': Sub, '*': Mul, - 'define': Define, - 'if': MacroIf, + #list operations 'cons': Cons, 'car': Car, 'cdr': Cdr, + #comparisons + '=': Equal, + #macros + 'define': Define, + 'if': MacroIf, 'lambda': Lambda, } Modified: pypy/dist/pypy/lang/scheme/test/test_eval.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_eval.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_eval.py Tue Jul 3 17:28:13 2007 @@ -151,9 +151,30 @@ w_cddr = eval_noctx("(cdr (cdr (cons 1 (cons 2 3))))") assert w_cddr.to_number() == 3 +def test_comparison_homonums(): + w_bool = eval_noctx("(= 1 2)") + assert w_bool.to_boolean() is False + + w_bool = eval_noctx("(= 2 2)") + assert w_bool.to_boolean() is True + + w_bool = eval_noctx("(= 2.1 1.2)") + assert w_bool.to_boolean() is False + + w_bool = eval_noctx("(= 2.1 2.1)") + assert w_bool.to_boolean() is True + +def test_comparison_heteronums(): + w_bool = eval_noctx("(= 1 2.2)") + assert w_bool.to_boolean() is False + + w_bool = eval_noctx("(= 2.0 2)") + assert w_bool.to_boolean() is True + def test_lambda_noargs(): ctx = ExecutionContext() w_lambda = eval_expr(ctx, "(lambda () 12)") + assert isinstance(w_lambda, W_Procedure) assert isinstance(w_lambda, W_Lambda) ctx.put("f1", w_lambda) @@ -186,3 +207,18 @@ assert isinstance(w_result, W_Fixnum) assert w_result.to_number() == 42 +def test_lambda_fac(): + ctx = ExecutionContext() + eval_expr(ctx, """ + (define fac + (lambda (n) + (if (= n 1) + n + (* (fac (- n 1)) n))))""") + assert isinstance(ctx.get("fac"), W_Lambda) + w_result = eval_expr(ctx, "(fac 4)") + assert w_result.to_number() == 24 + + w_result = eval_expr(ctx, "(fac 5)") + assert w_result.to_number() == 120 + From jlg at codespeak.net Wed Jul 4 14:38:13 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Wed, 4 Jul 2007 14:38:13 +0200 (CEST) Subject: [pypy-svn] r44721 - pypy/dist/pypy/lang/scheme Message-ID: <20070704123813.50622815E@code0.codespeak.net> Author: jlg Date: Wed Jul 4 14:38:11 2007 New Revision: 44721 Modified: pypy/dist/pypy/lang/scheme/object.py Log: procedures refactoring, arguments evaluated in W_Procedure to list() Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Wed Jul 4 14:38:11 2007 @@ -137,7 +137,14 @@ return "#" % (self.pname,) def eval(self, ctx, lst): - return self.procedure(ctx, lst) + #evaluate all arguments into list + arg_lst = [] + arg = lst + while not isinstance(arg, W_Nil): + arg_lst.append(arg.car.eval(ctx)) + arg = arg.cdr + + return self.procedure(ctx, arg_lst) def procedure(self, ctx, lst): raise NotImplementedError @@ -178,29 +185,20 @@ ## # operations ## -def apply_lst(ctx, fun, lst): - acc = None - - if not isinstance(lst, W_Pair): - #raise argument error - raise - - arg = lst - while not isinstance(arg, W_Nil): - if acc is None: - acc = arg.car.eval(ctx).to_number() - else: - acc = fun(acc, arg.car.eval(ctx).to_number()) - arg = arg.cdr - - if isinstance(acc, int): - return W_Fixnum(acc) - else: - return W_Float(acc) class ListOper(W_Procedure): def procedure(self, ctx, lst): - return apply_lst(ctx, self.oper, lst) + acc = None + for arg in lst: + if acc is None: + acc = arg.eval(ctx).to_number() + else: + acc = self.oper(acc, arg.eval(ctx).to_number()) + + if isinstance(acc, int): + return W_Fixnum(acc) + else: + return W_Float(acc) class Add(ListOper): def oper(self, x, y): @@ -208,10 +206,10 @@ class Sub(ListOper): def procedure(self, ctx, lst): - if isinstance(lst.cdr, W_Nil): - return apply_lst(ctx, self.oper, W_Pair( W_Fixnum(0), lst)) + if len(lst) == 1: + return ListOper.procedure(self, ctx, [W_Fixnum(0), lst[0]]) else: - return apply_lst(ctx, self.oper, lst) + return ListOper.procedure(self, ctx, lst) def oper(self, x, y): return x - y @@ -246,25 +244,25 @@ class Cons(W_Procedure): def procedure(self, ctx, lst): - w_car = lst.car.eval(ctx) - w_cdr = lst.cdr.car.eval(ctx) + w_car = lst[0] + w_cdr = lst[1] #cons is always creating a new pair return W_Pair(w_car, w_cdr) class Car(W_Procedure): def procedure(self, ctx, lst): - w_pair = lst.car.eval(ctx) + w_pair = lst[0] return w_pair.car class Cdr(W_Procedure): def procedure(self, ctx, lst): - w_pair = lst.car.eval(ctx) + w_pair = lst[0] return w_pair.cdr class Equal(W_Procedure): def procedure(self, ctx, lst): - w_first = lst.car.eval(ctx) - w_second = lst.cdr.car.eval(ctx) + w_first = lst[0] + w_second = lst[1] return W_Boolean(w_first.equal(w_second)) class Lambda(W_Macro): From jlg at codespeak.net Wed Jul 4 14:40:12 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Wed, 4 Jul 2007 14:40:12 +0200 (CEST) Subject: [pypy-svn] r44722 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070704124012.69CBE8166@code0.codespeak.net> Author: jlg Date: Wed Jul 4 14:40:12 2007 New Revision: 44722 Removed: pypy/dist/pypy/lang/scheme/operation.py Modified: pypy/dist/pypy/lang/scheme/test/test_eval.py Log: operation.py is no more needed Modified: pypy/dist/pypy/lang/scheme/test/test_eval.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_eval.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_eval.py Wed Jul 4 14:40:12 2007 @@ -4,28 +4,6 @@ from pypy.lang.scheme.object import W_Nil, W_Pair, W_Symbol, W_Identifier from pypy.lang.scheme.object import W_Procedure, W_Lambda from pypy.lang.scheme.object import ExecutionContext -from pypy.lang.scheme.operation import mul, add - -def test_operations_simple(): - w_num1 = W_Fixnum(4) - w_num2 = W_Fixnum(5) - w_num3 = W_Float(6.1) - - w_num = mul(None, [w_num1]) - assert w_num.to_number() == w_num1.to_number() - w_num = mul(None, [w_num1, w_num2]) - assert w_num.to_number() == w_num1.to_number() * w_num2.to_number() - w_num = mul(None, [w_num1, w_num2, w_num3]) - assert w_num.to_number() == (w_num1.to_number() * w_num2.to_number() - * w_num3.to_number()) - - w_num = add(None, [w_num1]) - assert w_num.to_number() == w_num1.to_number() - w_num = add(None, [w_num1, w_num2]) - assert w_num.to_number() == w_num1.to_number() + w_num2.to_number() - w_num = add(None, [w_num1, w_num2, w_num3]) - assert w_num.to_number() == (w_num1.to_number() + w_num2.to_number() - + w_num3.to_number()) def test_eval_obj(): w_num = W_Pair(W_Identifier("+"), From jlg at codespeak.net Wed Jul 4 15:11:05 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Wed, 4 Jul 2007 15:11:05 +0200 (CEST) Subject: [pypy-svn] r44723 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070704131105.085C5815E@code0.codespeak.net> Author: jlg Date: Wed Jul 4 15:11:05 2007 New Revision: 44723 Modified: pypy/dist/pypy/lang/scheme/object.py pypy/dist/pypy/lang/scheme/test/test_object.py Log: lambda is more like W_Procedure now Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Wed Jul 4 15:11:05 2007 @@ -161,31 +161,35 @@ class W_Lambda(W_Procedure): def __init__(self, args, body, pname="#f"): - self.args = args + self.args = [] + arg = args + while not isinstance(arg, W_Nil): + #list of argumen names, not evaluated + self.args.append(arg.car) + arg = arg.cdr + self.body = body self.pname = pname def to_string(self): return "#" % (self.pname,) - def eval(self, ctx, lst): - name = self.args - val = lst - my_ctx = ctx.copy() - while not isinstance(name, W_Nil): - assert isinstance(name.car, W_Identifier) - w_val = val.car.eval(ctx) - my_ctx.put(name.car.to_string(), w_val) - - val = val.cdr - name = name.cdr + def procedure(self, ctx, lst): + if len(lst) != len(self.args): + #wrong argument count + raise + + local_ctx = ctx.copy() + vars = zip(self.args, lst) + for name_val in vars: + assert isinstance(name_val[0], W_Identifier) + local_ctx.put(name_val[0].to_string(), name_val[1]) - return self.body.eval(my_ctx) + return self.body.eval(local_ctx) ## # operations ## - class ListOper(W_Procedure): def procedure(self, ctx, lst): acc = None Modified: pypy/dist/pypy/lang/scheme/test/test_object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_object.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_object.py Wed Jul 4 15:11:05 2007 @@ -1,6 +1,5 @@ import py from pypy.lang.scheme.object import * -from pypy.lang.scheme.operation import * def test_false(): w_false = W_Boolean(False) From jlg at codespeak.net Wed Jul 4 15:22:15 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Wed, 4 Jul 2007 15:22:15 +0200 (CEST) Subject: [pypy-svn] r44724 - pypy/dist/pypy/lang/scheme Message-ID: <20070704132215.CBDBA815E@code0.codespeak.net> Author: jlg Date: Wed Jul 4 15:22:15 2007 New Revision: 44724 Modified: pypy/dist/pypy/lang/scheme/object.py Log: agrument W_Identfier -> str in W_Lambda init Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Wed Jul 4 15:22:15 2007 @@ -164,8 +164,9 @@ self.args = [] arg = args while not isinstance(arg, W_Nil): - #list of argumen names, not evaluated - self.args.append(arg.car) + assert isinstance(arg.car, W_Identifier) + #list of argument names, not evaluated + self.args.append(arg.car.to_string()) arg = arg.cdr self.body = body @@ -181,9 +182,8 @@ local_ctx = ctx.copy() vars = zip(self.args, lst) - for name_val in vars: - assert isinstance(name_val[0], W_Identifier) - local_ctx.put(name_val[0].to_string(), name_val[1]) + for (name, val) in vars: + local_ctx.put(name, val) return self.body.eval(local_ctx) From jlg at codespeak.net Wed Jul 4 16:56:18 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Wed, 4 Jul 2007 16:56:18 +0200 (CEST) Subject: [pypy-svn] r44725 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070704145618.276CB815E@code0.codespeak.net> Author: jlg Date: Wed Jul 4 16:56:17 2007 New Revision: 44725 Modified: pypy/dist/pypy/lang/scheme/object.py pypy/dist/pypy/lang/scheme/test/test_eval.py Log: lambda in lambda cousure; Colusure(Location) Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Wed Jul 4 16:56:17 2007 @@ -33,11 +33,11 @@ w_obj = ctx.get(self.name) if w_obj is not None: - return w_obj #.eval(ctx) + return w_obj else: #reference to undefined identifier #unbound - raise NotImplementedError + raise "Unbound variable: %s" % (self.name, ) class W_Symbol(W_Root): def __init__(self, val): @@ -160,7 +160,7 @@ raise NotImplementedError class W_Lambda(W_Procedure): - def __init__(self, args, body, pname="#f"): + def __init__(self, args, body, clousure, pname="#f"): self.args = [] arg = args while not isinstance(arg, W_Nil): @@ -171,19 +171,23 @@ self.body = body self.pname = pname + self.clousure = clousure def to_string(self): return "#" % (self.pname,) def procedure(self, ctx, lst): if len(lst) != len(self.args): - #wrong argument count - raise + raise "Wrong argument count" local_ctx = ctx.copy() + #ugly hack + for (name, val) in self.clousure.scope.items(): + local_ctx.lput(name, val.obj) + vars = zip(self.args, lst) for (name, val) in vars: - local_ctx.put(name, val) + local_ctx.lput(name, val) return self.body.eval(local_ctx) @@ -273,7 +277,7 @@ def eval(self, ctx, lst): w_args = lst.car w_body = lst.cdr.car - return W_Lambda(w_args, w_body) + return W_Lambda(w_args, w_body, ctx.lcopy()) ## # Location() @@ -282,6 +286,10 @@ def __init__(self, w_obj): self.obj = w_obj +class Clousure(Location): + def __init__(self, w_obj): + self.obj = w_obj + ## # dict mapping operations to W_Xxx objects # callables must have 2 arguments @@ -313,7 +321,7 @@ class ExecutionContext(object): """Execution context implemented as a dict. - { "IDENTIFIER": W_Root } + { "IDENTIFIER": Location(W_Root()) } """ def __init__(self, scope=OPERATION_MAP): assert scope is not None @@ -322,6 +330,14 @@ def copy(self): return ExecutionContext(dict(self.scope)) + def lcopy(self): + lscope = {} + for (name, loc) in self.scope.items(): + if isinstance(loc, Clousure): + lscope[name] = loc + + return ExecutionContext(lscope) + def get(self, name): loc = self.scope.get(name, None) @@ -331,6 +347,7 @@ return None def set(self, name, obj): + """update existing location or create new location new""" loc = self.scope.get(name, None) if loc is not None: @@ -338,9 +355,21 @@ else: self.put(name, obj) + def seta(self, name, obj): + """update existing location""" + loc = self.scope.get(name, None) + + if loc is not None: + loc.obj = obj + else: + #unbound var + raise "Unbound" + def put(self, name, obj): - """Overwrites existing variable location - (new location is created) - """ + """create new location""" self.scope[name] = Location(obj) + def lput(self, name, obj): + """create new location""" + self.scope[name] = Clousure(obj) + Modified: pypy/dist/pypy/lang/scheme/test/test_eval.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_eval.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_eval.py Wed Jul 4 16:56:17 2007 @@ -200,3 +200,18 @@ w_result = eval_expr(ctx, "(fac 5)") assert w_result.to_number() == 120 +def test_lambda2(): + ctx = ExecutionContext() + eval_expr(ctx, """(define adder (lambda (x) (lambda (y) (+ x y))))""") + w_lambda = eval_expr(ctx, "(adder 6)") + assert isinstance(w_lambda, W_Lambda) + + eval_expr(ctx, """(define add6 (adder 6))""") + w_result = eval_expr(ctx, "(add6 5)") + assert isinstance(w_result, W_Fixnum) + assert w_result.to_number() == 11 + + w_result = eval_expr(ctx, "((adder 6) 5)") + assert isinstance(w_result, W_Fixnum) + assert w_result.to_number() == 11 + From jlg at codespeak.net Wed Jul 4 17:00:59 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Wed, 4 Jul 2007 17:00:59 +0200 (CEST) Subject: [pypy-svn] r44726 - pypy/dist/pypy/lang/scheme Message-ID: <20070704150059.C5CDE8181@code0.codespeak.net> Author: jlg Date: Wed Jul 4 17:00:59 2007 New Revision: 44726 Modified: pypy/dist/pypy/lang/scheme/object.py Log: spelling, s/clousre/slosure/ Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Wed Jul 4 17:00:59 2007 @@ -160,7 +160,7 @@ raise NotImplementedError class W_Lambda(W_Procedure): - def __init__(self, args, body, clousure, pname="#f"): + def __init__(self, args, body, closure, pname="#f"): self.args = [] arg = args while not isinstance(arg, W_Nil): @@ -171,7 +171,7 @@ self.body = body self.pname = pname - self.clousure = clousure + self.closure = closure def to_string(self): return "#" % (self.pname,) @@ -182,7 +182,7 @@ local_ctx = ctx.copy() #ugly hack - for (name, val) in self.clousure.scope.items(): + for (name, val) in self.closure.scope.items(): local_ctx.lput(name, val.obj) vars = zip(self.args, lst) @@ -286,7 +286,7 @@ def __init__(self, w_obj): self.obj = w_obj -class Clousure(Location): +class Closure(Location): def __init__(self, w_obj): self.obj = w_obj @@ -333,7 +333,7 @@ def lcopy(self): lscope = {} for (name, loc) in self.scope.items(): - if isinstance(loc, Clousure): + if isinstance(loc, Closure): lscope[name] = loc return ExecutionContext(lscope) @@ -371,5 +371,5 @@ def lput(self, name, obj): """create new location""" - self.scope[name] = Clousure(obj) + self.scope[name] = Closure(obj) From jlg at codespeak.net Wed Jul 4 17:56:46 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Wed, 4 Jul 2007 17:56:46 +0200 (CEST) Subject: [pypy-svn] r44727 - pypy/dist/pypy/lang/scheme Message-ID: <20070704155646.2BDA98113@code0.codespeak.net> Author: jlg Date: Wed Jul 4 17:56:45 2007 New Revision: 44727 Modified: pypy/dist/pypy/lang/scheme/object.py Log: ExecutionContext now has globalscope and scope, no more Closure(), lambda evaluation ignores caller ctx Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Wed Jul 4 17:56:45 2007 @@ -177,17 +177,16 @@ return "#" % (self.pname,) def procedure(self, ctx, lst): + #ctx is a caller context, which is hoyfully ignored if len(lst) != len(self.args): raise "Wrong argument count" - local_ctx = ctx.copy() - #ugly hack - for (name, val) in self.closure.scope.items(): - local_ctx.lput(name, val.obj) + local_ctx = self.closure.copy() + #set lambda arguments vars = zip(self.args, lst) for (name, val) in vars: - local_ctx.lput(name, val) + local_ctx.put(name, val) return self.body.eval(local_ctx) @@ -232,7 +231,7 @@ assert isinstance(w_identifier, W_Identifier) w_val = lst.cdr.car.eval(ctx) - ctx.set(w_identifier.name, w_val) + ctx.gset(w_identifier.name, w_val) return w_val class MacroIf(W_Macro): @@ -277,7 +276,7 @@ def eval(self, ctx, lst): w_args = lst.car w_body = lst.cdr.car - return W_Lambda(w_args, w_body, ctx.lcopy()) + return W_Lambda(w_args, w_body, ctx.copy()) ## # Location() @@ -286,10 +285,6 @@ def __init__(self, w_obj): self.obj = w_obj -class Closure(Location): - def __init__(self, w_obj): - self.obj = w_obj - ## # dict mapping operations to W_Xxx objects # callables must have 2 arguments @@ -323,28 +318,31 @@ { "IDENTIFIER": Location(W_Root()) } """ - def __init__(self, scope=OPERATION_MAP): - assert scope is not None - self.scope = scope - - def copy(self): - return ExecutionContext(dict(self.scope)) + def __init__(self, globalscope=None, scope=None): + if globalscope is None: + self.globalscope = dict(OPERATION_MAP) + else: + self.globalscope = globalscope - def lcopy(self): - lscope = {} - for (name, loc) in self.scope.items(): - if isinstance(loc, Closure): - lscope[name] = loc + if scope is None: + self.scope = {} + else: + self.scope = scope - return ExecutionContext(lscope) + def copy(self): + return ExecutionContext(self.globalscope, dict(self.scope)) def get(self, name): loc = self.scope.get(name, None) if loc is not None: return loc.obj - else: - return None + + loc = self.globalscope.get(name, None) + if loc is not None: + return loc.obj + + return None def set(self, name, obj): """update existing location or create new location new""" @@ -355,21 +353,20 @@ else: self.put(name, obj) - def seta(self, name, obj): - """update existing location""" - loc = self.scope.get(name, None) + def gset(self, name, obj): + """update existing location or create new location new""" + loc = self.globalscope.get(name, None) if loc is not None: loc.obj = obj else: - #unbound var - raise "Unbound" + self.gput(name, obj) - def put(self, name, obj): + def gput(self, name, obj): """create new location""" - self.scope[name] = Location(obj) + self.globalscope[name] = Location(obj) - def lput(self, name, obj): + def put(self, name, obj): """create new location""" - self.scope[name] = Closure(obj) + self.scope[name] = Location(obj) From antocuni at codespeak.net Wed Jul 4 19:06:44 2007 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Wed, 4 Jul 2007 19:06:44 +0200 (CEST) Subject: [pypy-svn] r44728 - pypy/dist/pypy/translator Message-ID: <20070704170644.72E5B8141@code0.codespeak.net> Author: antocuni Date: Wed Jul 4 19:06:43 2007 New Revision: 44728 Modified: pypy/dist/pypy/translator/driver.py Log: at the moment main.exe is needed to import the generated dll. Modified: pypy/dist/pypy/translator/driver.py ============================================================================== --- pypy/dist/pypy/translator/driver.py (original) +++ pypy/dist/pypy/translator/driver.py Wed Jul 4 19:06:43 2007 @@ -694,6 +694,12 @@ pypylib_dll = os.path.join(usession_path, 'pypylib.dll') shutil.copy(dllname, '.') shutil.copy(pypylib_dll, '.') + + # main.exe is a stub but is needed right now because it's + # referenced by pypylib.dll. Will be removed in the future + translator_path, _ = os.path.split(__file__) + main_exe = os.path.join(translator_path, 'cli/src/main.exe') + shutil.copy(main_exe, '.') def task_run_cli(self): pass From antocuni at codespeak.net Wed Jul 4 19:38:06 2007 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Wed, 4 Jul 2007 19:38:06 +0200 (CEST) Subject: [pypy-svn] r44729 - in pypy/dist/pypy/translator/cli: . test Message-ID: <20070704173806.AC4FD814B@code0.codespeak.net> Author: antocuni Date: Wed Jul 4 19:38:05 2007 New Revision: 44729 Modified: pypy/dist/pypy/translator/cli/carbonpython.py pypy/dist/pypy/translator/cli/test/test_carbonpython.py Log: add the possibility to specify the name of the target dll Modified: pypy/dist/pypy/translator/cli/carbonpython.py ============================================================================== --- pypy/dist/pypy/translator/cli/carbonpython.py (original) +++ pypy/dist/pypy/translator/cli/carbonpython.py Wed Jul 4 19:38:05 2007 @@ -116,27 +116,41 @@ return mydict[name] -def compile_dll(filename): - _, name = os.path.split(filename) - dllname, _ = os.path.splitext(name) +def compile_dll(filename, dllname=None, copy_dll=True): + dirname, name = os.path.split(filename) + if dllname is None: + dllname, _ = os.path.splitext(name) + elif dllname.endswith('.dll'): + dllname, _ = os.path.splitext(dllname) module = new.module(dllname) namespace = module.__dict__.get('_namespace_', dllname) + sys.path.insert(0, dirname) execfile(filename, module.__dict__) + sys.path.pop(0) dll = DllDef(dllname, namespace) dll.functions = collect_entrypoints(module.__dict__) dll.compile() - dll.driver.copy_cli_dll() + if copy_dll: + dll.driver.copy_cli_dll() def main(argv): - if len(argv) != 2: + if len(argv) == 2: + filename = argv[1] + dllname = None + elif len(argv) == 3: + filename = argv[1] + dllname = argv[2] + else: print >> sys.stderr, __doc__ sys.exit(2) - filename = argv[1] + + if not filename.endswith('.py'): + filename += '.py' if not os.path.exists(filename): print >> sys.stderr, "Cannot find file %s" % filename sys.exit(1) - compile_dll(filename) + compile_dll(filename, dllname) if __name__ == '__main__': main(sys.argv) Modified: pypy/dist/pypy/translator/cli/test/test_carbonpython.py ============================================================================== --- pypy/dist/pypy/translator/cli/test/test_carbonpython.py (original) +++ pypy/dist/pypy/translator/cli/test/test_carbonpython.py Wed Jul 4 19:38:05 2007 @@ -1,7 +1,9 @@ +import os +import os.path from pypy.tool import udir from pypy.translator.cli.rte import Target from pypy.translator.cli.carbonpython import DllDef, export, collect_entrypoints,\ - collect_class_entrypoints + collect_class_entrypoints, compile_dll from pypy.translator.cli.test.runtest import CliFunctionWrapper, CliTest TEMPLATE = """ @@ -140,3 +142,21 @@ Console.WriteLine(Test.getitem(obj, 0)); """) assert res == 42 + + def test_compile_dll(self): + cwd, _ = os.path.split(__file__) + mylib_py = os.path.join(cwd, 'mylib.py') + compile_dll(mylib_py, copy_dll=False) + res = self._csharp('mylib', """ + Console.WriteLine(mylib.sum(20, 22)); + """) + assert res == 42 + + def test_compile_dll_alternative_name(self): + cwd, _ = os.path.split(__file__) + mylib_py = os.path.join(cwd, 'mylib.py') + compile_dll(mylib_py, 'mylibxxx.dll', copy_dll=False) + res = self._csharp('mylibxxx', """ + Console.WriteLine(mylibxxx.sum(20, 22)); + """) + assert res == 42 From antocuni at codespeak.net Wed Jul 4 19:38:45 2007 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Wed, 4 Jul 2007 19:38:45 +0200 (CEST) Subject: [pypy-svn] r44730 - pypy/dist/pypy/translator/cli Message-ID: <20070704173845.94508814B@code0.codespeak.net> Author: antocuni Date: Wed Jul 4 19:38:45 2007 New Revision: 44730 Modified: pypy/dist/pypy/translator/cli/carbonpython.py Log: sorry, forgot to update the synopsis Modified: pypy/dist/pypy/translator/cli/carbonpython.py ============================================================================== --- pypy/dist/pypy/translator/cli/carbonpython.py (original) +++ pypy/dist/pypy/translator/cli/carbonpython.py Wed Jul 4 19:38:45 2007 @@ -1,6 +1,6 @@ #! /usr/bin/env python """ -Usage: carbonpython.py .py +Usage: carbonpython.py [dll-name] Compiles an RPython module into a .NET dll. """ From antocuni at codespeak.net Wed Jul 4 21:04:19 2007 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Wed, 4 Jul 2007 21:04:19 +0200 (CEST) Subject: [pypy-svn] r44731 - pypy/dist/pypy/translator Message-ID: <20070704190419.5DDE580B9@code0.codespeak.net> Author: antocuni Date: Wed Jul 4 21:04:18 2007 New Revision: 44731 Modified: pypy/dist/pypy/translator/driver.py Log: add an information message Modified: pypy/dist/pypy/translator/driver.py ============================================================================== --- pypy/dist/pypy/translator/driver.py (original) +++ pypy/dist/pypy/translator/driver.py Wed Jul 4 21:04:18 2007 @@ -700,6 +700,7 @@ translator_path, _ = os.path.split(__file__) main_exe = os.path.join(translator_path, 'cli/src/main.exe') shutil.copy(main_exe, '.') + self.log.info("Copied to %s" % os.path.join(os.getcwd(), dllname)) def task_run_cli(self): pass From antocuni at codespeak.net Wed Jul 4 21:13:16 2007 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Wed, 4 Jul 2007 21:13:16 +0200 (CEST) Subject: [pypy-svn] r44732 - in pypy/extradoc/talk/ep2007: . rpython-demo Message-ID: <20070704191316.77E3780C4@code0.codespeak.net> Author: antocuni Date: Wed Jul 4 21:13:15 2007 New Revision: 44732 Added: pypy/extradoc/talk/ep2007/rpython-demo/ pypy/extradoc/talk/ep2007/rpython-demo/carbonpython.py (contents, props changed) pypy/extradoc/talk/ep2007/rpython-demo/demo.txt (contents, props changed) pypy/extradoc/talk/ep2007/rpython-demo/func.py (contents, props changed) Modified: pypy/extradoc/talk/ep2007/rpython.txt Log: some slides about gencli/carbonpython and the demo Added: pypy/extradoc/talk/ep2007/rpython-demo/carbonpython.py ============================================================================== --- (empty file) +++ pypy/extradoc/talk/ep2007/rpython-demo/carbonpython.py Wed Jul 4 21:13:15 2007 @@ -0,0 +1,13 @@ +import sys + +if sys.platform == 'cli': + # on IronPython, export does nothing + def export(*args, **kwds): + if len(args) == 1 and isinstance(args[0], type(export)): + return args[0] + else: + return lambda fn: fn +else: + # import carbonpython's export + from pypy.translator.cli.carbonpython import export + Added: pypy/extradoc/talk/ep2007/rpython-demo/demo.txt ============================================================================== --- (empty file) +++ pypy/extradoc/talk/ep2007/rpython-demo/demo.txt Wed Jul 4 21:13:15 2007 @@ -0,0 +1,39 @@ +# CarbonPython live demo + +$ cat func.py +from carbonpython import export +import time + + at export(int) +def fn(N): + t1 = time.clock() + z = 0 + for index in xrange(N): + x = 2.34+index + y = 3.45+index + z = (x*x)+(y*y)+index + t2 = time.clock() + print t2-t1, 'seconds' + return z + +$ carbonpython.py func.py mylib.dll +... + +$ ipy +IronPython 1.0 (1.0) on .NET 2.0.50727.42 +Copyright (c) Microsoft Corporation. All rights reserved. +>>> import clr +>>> clr.AddReferenceToFile('mylib.dll') +>>> +>>> import func +>>> import mylib +>>> +>>> N = 10**7 +>>> print func.fn(N) +7.770177 seconds +2.000000858e+014 +>>> print mylib.fn(N) +0.25608 seconds +2.000000858e+014 +>>> 7.770177 / 0.25608 +30.3427717901 Added: pypy/extradoc/talk/ep2007/rpython-demo/func.py ============================================================================== --- (empty file) +++ pypy/extradoc/talk/ep2007/rpython-demo/func.py Wed Jul 4 21:13:15 2007 @@ -0,0 +1,14 @@ +from carbonpython import export +import time + + at export(int) +def fn(N): + t1 = time.clock() + z = 0 + for index in xrange(N): + x = 2.34+index + y = 3.45+index + z = (x*x)+(y*y)+index + t2 = time.clock() + print t2-t1, 'seconds' + return z Modified: pypy/extradoc/talk/ep2007/rpython.txt ============================================================================== --- pypy/extradoc/talk/ep2007/rpython.txt (original) +++ pypy/extradoc/talk/ep2007/rpython.txt Wed Jul 4 21:13:15 2007 @@ -3,7 +3,7 @@ RPython: need for speed aka C and C# considered harmful ======================================================= -:Authors: Antonio Cuni (xxx), Maciej Fijalkowski (merlinux GmbH) +:Authors: Antonio Cuni (DISI), Maciej Fijalkowski (merlinux GmbH) :Place: Europython 2007 :Date: XXX @@ -108,12 +108,40 @@ The CLI backend --------------- -XXX anto, feel free to fill +* Produces assemblies for .NET (both Mono and CLR) + +* (Experimental) access to .NET libraries + +* As fast as C# + +* From 4 to 100 times faster than IronPython + +CarbonPython +------------ + +* **Highly** experimental + +* RPython --> .NET DLL + +* DLLs can be imported by C#, IronPython, ... + +* CarbonPython + IronPython = SteelPython :-) + +* Explicit definition of multiple entrypoints + +* Live demo + The JVM backend --------------- -XXX anto, feel free to fill +* Produces classes for the JVM + +* Shares a lot of code with the CLI backend + +* Not as mature as gencli + + The JS backend -------------- From jlg at codespeak.net Thu Jul 5 13:59:35 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Thu, 5 Jul 2007 13:59:35 +0200 (CEST) Subject: [pypy-svn] r44738 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070705115935.97AF580E4@code0.codespeak.net> Author: jlg Date: Thu Jul 5 13:59:34 2007 New Revision: 44738 Modified: pypy/dist/pypy/lang/scheme/object.py pypy/dist/pypy/lang/scheme/test/test_eval.py Log: lambdas body can be multiple expressions; (set! ...) added Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Thu Jul 5 13:59:34 2007 @@ -188,7 +188,13 @@ for (name, val) in vars: local_ctx.put(name, val) - return self.body.eval(local_ctx) + body_expression = self.body + body_result = None + while not isinstance(body_expression, W_Nil): + body_result = body_expression.car.eval(local_ctx) + body_expression = body_expression.cdr + + return body_result # self.body.eval(local_ctx) ## # operations @@ -234,6 +240,15 @@ ctx.gset(w_identifier.name, w_val) return w_val +class Sete(W_Macro): + def eval(self, ctx, lst): + w_identifier = lst.car + assert isinstance(w_identifier, W_Identifier) + + w_val = lst.cdr.car.eval(ctx) + ctx.sete(w_identifier.name, w_val) + return w_val + class MacroIf(W_Macro): def eval(self, ctx, lst): w_condition = lst.car @@ -275,7 +290,7 @@ class Lambda(W_Macro): def eval(self, ctx, lst): w_args = lst.car - w_body = lst.cdr.car + w_body = lst.cdr #.car return W_Lambda(w_args, w_body, ctx.copy()) ## @@ -305,6 +320,7 @@ '=': Equal, #macros 'define': Define, + 'set!': Sete, 'if': MacroIf, 'lambda': Lambda, } @@ -353,6 +369,21 @@ else: self.put(name, obj) + def sete(self, name, obj): + """update existing location or raise""" + loc = self.scope.get(name, None) + if loc is not None: + loc.obj = obj + return obj + + loc = self.globalscope.get(name, None) + if loc is not None: + loc.obj = obj + return obj + + raise "Unbound" + + def gset(self, name, obj): """update existing location or create new location new""" loc = self.globalscope.get(name, None) Modified: pypy/dist/pypy/lang/scheme/test/test_eval.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_eval.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_eval.py Thu Jul 5 13:59:34 2007 @@ -71,6 +71,13 @@ w_num = eval_expr(ctx, "(+ 1 v1 v2)") assert w_num.to_number() == 46.1 +def test_sete(): + ctx = ExecutionContext() + eval_expr(ctx, "(define x 42)") + eval_expr(ctx, "(set! x 43)") + assert ctx.get("x").to_number() == 43 + py.test.raises("Unbound", eval_expr, ctx, "(set! y 42)") + def test_func(): ctx = ExecutionContext() w_func = eval_expr(ctx, "+") @@ -215,3 +222,9 @@ assert isinstance(w_result, W_Fixnum) assert w_result.to_number() == 11 +def test_lambda_long_body(): + ctx = ExecutionContext() + eval_expr(ctx, """(define long_body (lambda () (define x 42) (+ x 1)))""") + w_result = eval_expr(ctx, "(long_body)") + assert w_result.to_number() == 43 + #assert ctx.get("x") is None From jlg at codespeak.net Thu Jul 5 14:14:58 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Thu, 5 Jul 2007 14:14:58 +0200 (CEST) Subject: [pypy-svn] r44739 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070705121458.B70D880C1@code0.codespeak.net> Author: jlg Date: Thu Jul 5 14:14:56 2007 New Revision: 44739 Modified: pypy/dist/pypy/lang/scheme/object.py pypy/dist/pypy/lang/scheme/test/test_eval.py Log: after copy contex cannot create new locations in globalscope Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Thu Jul 5 14:14:56 2007 @@ -237,7 +237,7 @@ assert isinstance(w_identifier, W_Identifier) w_val = lst.cdr.car.eval(ctx) - ctx.gset(w_identifier.name, w_val) + ctx.set(w_identifier.name, w_val) return w_val class Sete(W_Macro): @@ -334,7 +334,7 @@ { "IDENTIFIER": Location(W_Root()) } """ - def __init__(self, globalscope=None, scope=None): + def __init__(self, globalscope=None, scope=None, closure=False): if globalscope is None: self.globalscope = dict(OPERATION_MAP) else: @@ -345,12 +345,13 @@ else: self.scope = scope + self.closure = closure + def copy(self): - return ExecutionContext(self.globalscope, dict(self.scope)) + return ExecutionContext(self.globalscope, dict(self.scope), True) def get(self, name): loc = self.scope.get(name, None) - if loc is not None: return loc.obj @@ -360,17 +361,10 @@ return None - def set(self, name, obj): - """update existing location or create new location new""" - loc = self.scope.get(name, None) - - if loc is not None: - loc.obj = obj - else: - self.put(name, obj) - def sete(self, name, obj): - """update existing location or raise""" + """update existing location or raise + directly used by (set! ) macro + """ loc = self.scope.get(name, None) if loc is not None: loc.obj = obj @@ -383,21 +377,36 @@ raise "Unbound" - - def gset(self, name, obj): + def set(self, name, obj): """update existing location or create new location new""" - loc = self.globalscope.get(name, None) + if self.closure: + loc = self.scope.get(name, None) + else: + loc = self.globalscope.get(name, None) if loc is not None: loc.obj = obj else: - self.gput(name, obj) - - def gput(self, name, obj): - """create new location""" - self.globalscope[name] = Location(obj) + self.put(name, obj) def put(self, name, obj): """create new location""" - self.scope[name] = Location(obj) + if self.closure: + self.scope[name] = Location(obj) + else: + self.globalscope[name] = Location(obj) + + def get_location(self, name): + """internal/test use only + returns location bound to variable + """ + loc = self.scope.get(name, None) + if loc is not None: + return loc + + loc = self.globalscope.get(name, None) + if loc is not None: + return loc + + return None Modified: pypy/dist/pypy/lang/scheme/test/test_eval.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_eval.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_eval.py Thu Jul 5 14:14:56 2007 @@ -74,8 +74,11 @@ def test_sete(): ctx = ExecutionContext() eval_expr(ctx, "(define x 42)") + loc1 = ctx.get_location("x") eval_expr(ctx, "(set! x 43)") + loc2 = ctx.get_location("x") assert ctx.get("x").to_number() == 43 + assert loc1 is loc2 py.test.raises("Unbound", eval_expr, ctx, "(set! y 42)") def test_func(): @@ -227,4 +230,5 @@ eval_expr(ctx, """(define long_body (lambda () (define x 42) (+ x 1)))""") w_result = eval_expr(ctx, "(long_body)") assert w_result.to_number() == 43 - #assert ctx.get("x") is None + assert ctx.get("x") is None + From jlg at codespeak.net Thu Jul 5 16:02:01 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Thu, 5 Jul 2007 16:02:01 +0200 (CEST) Subject: [pypy-svn] r44740 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070705140201.544FD80F4@code0.codespeak.net> Author: jlg Date: Thu Jul 5 16:02:00 2007 New Revision: 44740 Modified: pypy/dist/pypy/lang/scheme/object.py pypy/dist/pypy/lang/scheme/test/test_eval.py Log: (lambda x ) takes any number of arguments, x is newly allocated list of arguments Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Thu Jul 5 16:02:00 2007 @@ -164,10 +164,14 @@ self.args = [] arg = args while not isinstance(arg, W_Nil): - assert isinstance(arg.car, W_Identifier) - #list of argument names, not evaluated - self.args.append(arg.car.to_string()) - arg = arg.cdr + if isinstance(arg, W_Identifier): + self.args.append([arg.to_string()]) + break + else: + assert isinstance(arg.car, W_Identifier) + #list of argument names, not evaluated + self.args.append(arg.car.to_string()) + arg = arg.cdr self.body = body self.pname = pname @@ -177,16 +181,24 @@ return "#" % (self.pname,) def procedure(self, ctx, lst): - #ctx is a caller context, which is hoyfully ignored - if len(lst) != len(self.args): - raise "Wrong argument count" + #ctx is a caller context, which is joyfully ignored + + #if len(lst) != len(self.args): + # raise "Wrong argument count" local_ctx = self.closure.copy() #set lambda arguments - vars = zip(self.args, lst) - for (name, val) in vars: - local_ctx.put(name, val) + for idx in range(len(self.args)): + name = self.args[idx] + if isinstance(name, list): + local_ctx.put(name[0], plst2lst(lst[idx:])) + else: + local_ctx.put(name, lst[idx]) + + #vars = zip(self.args, lst) + #for (name, val) in vars: + # local_ctx.put(name, val) body_expression = self.body body_result = None @@ -196,6 +208,15 @@ return body_result # self.body.eval(local_ctx) +def plst2lst(plst): + """coverts python list() of W_Root into W_Pair scheme list""" + w_cdr = W_Nil() + plst.reverse() + for w_obj in plst: + w_cdr = W_Pair(w_obj, w_cdr) + + return w_cdr + ## # operations ## @@ -378,7 +399,7 @@ raise "Unbound" def set(self, name, obj): - """update existing location or create new location new""" + """update existing location or create new location""" if self.closure: loc = self.scope.get(name, None) else: Modified: pypy/dist/pypy/lang/scheme/test/test_eval.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_eval.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_eval.py Thu Jul 5 16:02:00 2007 @@ -232,3 +232,11 @@ assert w_result.to_number() == 43 assert ctx.get("x") is None +def test_lambda_lstarg(): + ctx = ExecutionContext() + w_result = eval_expr(ctx, """((lambda x x) 1 2 3)""") + assert isinstance(w_result, W_Pair) + assert w_result.car.to_number() == 1 + assert w_result.cdr.car.to_number() == 2 + assert w_result.cdr.cdr.car.to_number() == 3 + From jlg at codespeak.net Thu Jul 5 16:26:08 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Thu, 5 Jul 2007 16:26:08 +0200 (CEST) Subject: [pypy-svn] r44741 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070705142608.BB36480F4@code0.codespeak.net> Author: jlg Date: Thu Jul 5 16:26:07 2007 New Revision: 44741 Modified: pypy/dist/pypy/lang/scheme/ssparser.py pypy/dist/pypy/lang/scheme/test/test_parser.py Log: dotted list parsing Modified: pypy/dist/pypy/lang/scheme/ssparser.py ============================================================================== --- pypy/dist/pypy/lang/scheme/ssparser.py (original) +++ pypy/dist/pypy/lang/scheme/ssparser.py Thu Jul 5 16:26:07 2007 @@ -47,7 +47,8 @@ return {s}; sexpr: - list + dotted + | list | FLOAT | FIXNUM | BOOLEAN @@ -62,6 +63,17 @@ IGNORE* return {p}; + dotted: + '(' + IGNORE* + car = sexpr + '.' + IGNORE* + cdr = sexpr + ')' + IGNORE* + return {W_Pair(car, cdr)}; + pair: car = sexpr cdr = pair Modified: pypy/dist/pypy/lang/scheme/test/test_parser.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_parser.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_parser.py Thu Jul 5 16:26:07 2007 @@ -100,3 +100,9 @@ t = parse("#t") assert unwrap(t) == True +def test_dotted(): + t = parse("(1 . 2)") + assert isinstance(t, W_Pair) + assert unwrap(t.car) == 1 + assert unwrap(t.cdr) == 2 + From jlg at codespeak.net Thu Jul 5 16:56:56 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Thu, 5 Jul 2007 16:56:56 +0200 (CEST) Subject: [pypy-svn] r44742 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070705145656.4C85580F1@code0.codespeak.net> Author: jlg Date: Thu Jul 5 16:56:56 2007 New Revision: 44742 Modified: pypy/dist/pypy/lang/scheme/ssparser.py pypy/dist/pypy/lang/scheme/test/test_parser.py Log: dotted list parsing take2 Modified: pypy/dist/pypy/lang/scheme/ssparser.py ============================================================================== --- pypy/dist/pypy/lang/scheme/ssparser.py (original) +++ pypy/dist/pypy/lang/scheme/ssparser.py Thu Jul 5 16:56:56 2007 @@ -47,8 +47,7 @@ return {s}; sexpr: - dotted - | list + list | FLOAT | FIXNUM | BOOLEAN @@ -63,19 +62,13 @@ IGNORE* return {p}; - dotted: - '(' - IGNORE* + pair: car = sexpr '.' IGNORE* cdr = sexpr - ')' - IGNORE* - return {W_Pair(car, cdr)}; - - pair: - car = sexpr + return {W_Pair(car, cdr)} + | car = sexpr cdr = pair return {W_Pair(car, cdr)} | return {W_Nil()}; Modified: pypy/dist/pypy/lang/scheme/test/test_parser.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_parser.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_parser.py Thu Jul 5 16:56:56 2007 @@ -100,9 +100,26 @@ t = parse("#t") assert unwrap(t) == True -def test_dotted(): +def test_list_dotted(): t = parse("(1 . 2)") assert isinstance(t, W_Pair) assert unwrap(t.car) == 1 assert unwrap(t.cdr) == 2 + t = parse("(1 . (2 . 3))") + assert unwrap(t.car) == 1 + assert unwrap(t.cdr.car) == 2 + assert unwrap(t.cdr.cdr) == 3 + + t = parse("(1 . (2 . (3 . ())))") + assert unwrap(t) == [1, 2, 3] + +def test_list_mixed(): + t = parse("(1 2 . 3)") + assert unwrap(t.car) == 1 + assert unwrap(t.cdr.car) == 2 + assert unwrap(t.cdr.cdr) == 3 + + t = parse("(1 2 . (3 4))") + assert unwrap(t) == [1, 2, 3, 4] + From jlg at codespeak.net Thu Jul 5 17:50:50 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Thu, 5 Jul 2007 17:50:50 +0200 (CEST) Subject: [pypy-svn] r44744 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070705155050.3301880F2@code0.codespeak.net> Author: jlg Date: Thu Jul 5 17:50:49 2007 New Revision: 44744 Modified: pypy/dist/pypy/lang/scheme/object.py pypy/dist/pypy/lang/scheme/test/test_eval.py Log: (quote ...); W_Identifier.to_symbol() method Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Thu Jul 5 17:50:49 2007 @@ -26,6 +26,9 @@ def __repr__(self): return "" + def to_symbol(self): + return W_Symbol(self.name) + def eval(self, ctx): if ctx is None: @@ -314,6 +317,24 @@ w_body = lst.cdr #.car return W_Lambda(w_args, w_body, ctx.copy()) +class Quote(W_Macro): + def symbolize(self, lst): + + if isinstance(lst, W_Pair): + arg = lst + while not isinstance(arg, W_Nil): + arg.car = self.symbolize(arg.car) + arg = arg.cdr + + if isinstance(lst, W_Identifier): + lst = lst.to_symbol() + + return lst + + def eval(self, ctx, lst): + w_obj = self.symbolize(lst.car) + return w_obj + ## # Location() ## @@ -344,6 +365,7 @@ 'set!': Sete, 'if': MacroIf, 'lambda': Lambda, + 'quote': Quote, } OPERATION_MAP = {} Modified: pypy/dist/pypy/lang/scheme/test/test_eval.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_eval.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_eval.py Thu Jul 5 17:50:49 2007 @@ -240,3 +240,31 @@ assert w_result.cdr.car.to_number() == 2 assert w_result.cdr.cdr.car.to_number() == 3 +def test_quote(): + w_fnum = eval_noctx("(quote 42)") + assert isinstance(w_fnum, W_Fixnum) + assert w_fnum.to_number() == 42 + + w_sym = eval_noctx("(quote symbol)") + assert isinstance(w_sym, W_Symbol) + assert w_sym.to_string() == "symbol" + + w_lst = eval_noctx("(quote (1 2 3))") + assert isinstance(w_lst, W_Pair) + assert w_lst.car.to_number() == 1 + assert w_lst.cdr.car.to_number() == 2 + assert w_lst.cdr.cdr.car.to_number() == 3 + + w_lst = eval_noctx("(quote (a (x y) c))") + assert isinstance(w_lst, W_Pair) + assert isinstance(w_lst.car, W_Symbol) + assert w_lst.car.to_string() == "a" + w_pair = w_lst.cdr.car + assert isinstance(w_lst.cdr.cdr.car, W_Symbol) + assert w_lst.cdr.cdr.car.to_string() == "c" + + assert isinstance(w_pair.car, W_Symbol) + assert w_pair.car.to_string() == "x" + assert isinstance(w_pair.cdr.car, W_Symbol) + assert w_pair.cdr.car.to_string() == "y" + From arigo at codespeak.net Thu Jul 5 18:00:10 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Thu, 5 Jul 2007 18:00:10 +0200 (CEST) Subject: [pypy-svn] r44745 - pypy/extradoc/sprintinfo/post-ep2007 Message-ID: <20070705160010.5FE4880F2@code0.codespeak.net> Author: arigo Date: Thu Jul 5 18:00:09 2007 New Revision: 44745 Modified: pypy/extradoc/sprintinfo/post-ep2007/people.txt Log: My room still has a 2nd bed free if someone didn't make hotel arrangements yet. Modified: pypy/extradoc/sprintinfo/post-ep2007/people.txt ============================================================================== --- pypy/extradoc/sprintinfo/post-ep2007/people.txt (original) +++ pypy/extradoc/sprintinfo/post-ep2007/people.txt Thu Jul 5 18:00:09 2007 @@ -8,9 +8,9 @@ column are known to be coming but there are no details available yet from them. -==================== ============== ======================= +==================== ============== ================================= Name Arrive/Depart Accomodation -==================== ============== ======================= +==================== ============== ================================= Maciej Fijalkowski 5/14th Some hostel Antonio Cuni 8/15th Same as Maciek :-) Samuele Pedroni 7/14th Ratonda Centrum Hotels @@ -19,9 +19,9 @@ Jakub Gustak 8/15th Hospitality Club :) Christian Tismer 8/16th Ratonda Centrum Hotels Simon Burton 8/15th -Armin Rigo 8/16th Comfort Vilnius +Armin Rigo 8/16th Comfort Vilnius (room to share!) Bea D?ring 8/13th Comfort Vilnius -==================== ============== ======================= +==================== ============== ================================= People on the following list were present at previous sprints: From jlg at codespeak.net Thu Jul 5 18:32:05 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Thu, 5 Jul 2007 18:32:05 +0200 (CEST) Subject: [pypy-svn] r44747 - in pypy/dist/pypy/lang/scheme: . test Message-ID: <20070705163205.A180E80F6@code0.codespeak.net> Author: jlg Date: Thu Jul 5 18:32:05 2007 New Revision: 44747 Modified: pypy/dist/pypy/lang/scheme/object.py pypy/dist/pypy/lang/scheme/ssparser.py pypy/dist/pypy/lang/scheme/test/test_eval.py Log: quotation parsing Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Thu Jul 5 18:32:05 2007 @@ -16,6 +16,16 @@ def eval(self, ctx): return self +class W_Symbol(W_Root): + def __init__(self, val): + self.name = val + + def to_string(self): + return self.name + + def __repr__(self): + return "" + class W_Identifier(W_Root): def __init__(self, val): self.name = val @@ -40,17 +50,7 @@ else: #reference to undefined identifier #unbound - raise "Unbound variable: %s" % (self.name, ) - -class W_Symbol(W_Root): - def __init__(self, val): - self.name = val - - def to_string(self): - return self.name - - def __repr__(self): - return "" + raise Exception("Unbound variable: %s" % (self.name, )) class W_Boolean(W_Root): def __init__(self, val): @@ -317,9 +317,11 @@ w_body = lst.cdr #.car return W_Lambda(w_args, w_body, ctx.copy()) +def Literal(sexpr): + return W_Pair(W_Identifier('quote'), W_Pair(sexpr, W_Nil())) + class Quote(W_Macro): def symbolize(self, lst): - if isinstance(lst, W_Pair): arg = lst while not isinstance(arg, W_Nil): @@ -418,7 +420,7 @@ loc.obj = obj return obj - raise "Unbound" + raise Exception("Unbound variable: %s" % (name, )) def set(self, name, obj): """update existing location or create new location""" Modified: pypy/dist/pypy/lang/scheme/ssparser.py ============================================================================== --- pypy/dist/pypy/lang/scheme/ssparser.py (original) +++ pypy/dist/pypy/lang/scheme/ssparser.py Thu Jul 5 18:32:05 2007 @@ -2,7 +2,7 @@ from pypy.rlib.parsing.pypackrat import PackratParser from pypy.rlib.parsing.makepackrat import BacktrackException, Status from pypy.lang.scheme.object import W_Pair, W_Fixnum, W_String, W_Identifier -from pypy.lang.scheme.object import W_Nil, W_Boolean, W_Float +from pypy.lang.scheme.object import W_Nil, W_Boolean, W_Float, Literal, W_Symbol def unquote(s): return s.replace('\\"', '"') @@ -46,8 +46,14 @@ EOF return {s}; + literal: + `'` + s = sexpr + return {Literal(s)}; + sexpr: list + | literal | FLOAT | FIXNUM | BOOLEAN Modified: pypy/dist/pypy/lang/scheme/test/test_eval.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_eval.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_eval.py Thu Jul 5 18:32:05 2007 @@ -79,7 +79,7 @@ loc2 = ctx.get_location("x") assert ctx.get("x").to_number() == 43 assert loc1 is loc2 - py.test.raises("Unbound", eval_expr, ctx, "(set! y 42)") + py.test.raises(Exception, eval_expr, ctx, "(set! y 42)") def test_func(): ctx = ExecutionContext() @@ -268,3 +268,31 @@ assert isinstance(w_pair.cdr.car, W_Symbol) assert w_pair.cdr.car.to_string() == "y" +def test_quote_parse(): + w_fnum = eval_noctx("'42") + assert isinstance(w_fnum, W_Fixnum) + assert w_fnum.to_number() == 42 + + w_sym = eval_noctx("'symbol") + assert isinstance(w_sym, W_Symbol) + assert w_sym.to_string() == "symbol" + + w_lst = eval_noctx("'(1 2 3)") + assert isinstance(w_lst, W_Pair) + assert w_lst.car.to_number() == 1 + assert w_lst.cdr.car.to_number() == 2 + assert w_lst.cdr.cdr.car.to_number() == 3 + + w_lst = eval_noctx("'(a (x y) c)") + assert isinstance(w_lst, W_Pair) + assert isinstance(w_lst.car, W_Symbol) + assert w_lst.car.to_string() == "a" + w_pair = w_lst.cdr.car + assert isinstance(w_lst.cdr.cdr.car, W_Symbol) + assert w_lst.cdr.cdr.car.to_string() == "c" + + assert isinstance(w_pair.car, W_Symbol) + assert w_pair.car.to_string() == "x" + assert isinstance(w_pair.cdr.car, W_Symbol) + assert w_pair.cdr.car.to_string() == "y" + From jlg at codespeak.net Thu Jul 5 18:57:24 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Thu, 5 Jul 2007 18:57:24 +0200 (CEST) Subject: [pypy-svn] r44750 - pypy/dist/pypy/lang/scheme Message-ID: <20070705165724.D8A5A80F4@code0.codespeak.net> Author: jlg Date: Thu Jul 5 18:57:24 2007 New Revision: 44750 Modified: pypy/dist/pypy/lang/scheme/object.py pypy/dist/pypy/lang/scheme/ssparser.py Log: (quote ) does nothing Modified: pypy/dist/pypy/lang/scheme/object.py ============================================================================== --- pypy/dist/pypy/lang/scheme/object.py (original) +++ pypy/dist/pypy/lang/scheme/object.py Thu Jul 5 18:57:24 2007 @@ -26,7 +26,7 @@ def __repr__(self): return "" -class W_Identifier(W_Root): +class W_Identifier(W_Symbol): def __init__(self, val): self.name = val @@ -36,9 +36,6 @@ def __repr__(self): return "" - def to_symbol(self): - return W_Symbol(self.name) - def eval(self, ctx): if ctx is None: @@ -321,21 +318,8 @@ return W_Pair(W_Identifier('quote'), W_Pair(sexpr, W_Nil())) class Quote(W_Macro): - def symbolize(self, lst): - if isinstance(lst, W_Pair): - arg = lst - while not isinstance(arg, W_Nil): - arg.car = self.symbolize(arg.car) - arg = arg.cdr - - if isinstance(lst, W_Identifier): - lst = lst.to_symbol() - - return lst - def eval(self, ctx, lst): - w_obj = self.symbolize(lst.car) - return w_obj + return lst.car ## # Location() Modified: pypy/dist/pypy/lang/scheme/ssparser.py ============================================================================== --- pypy/dist/pypy/lang/scheme/ssparser.py (original) +++ pypy/dist/pypy/lang/scheme/ssparser.py Thu Jul 5 18:57:24 2007 @@ -2,7 +2,7 @@ from pypy.rlib.parsing.pypackrat import PackratParser from pypy.rlib.parsing.makepackrat import BacktrackException, Status from pypy.lang.scheme.object import W_Pair, W_Fixnum, W_String, W_Identifier -from pypy.lang.scheme.object import W_Nil, W_Boolean, W_Float, Literal, W_Symbol +from pypy.lang.scheme.object import W_Nil, W_Boolean, W_Float, Literal def unquote(s): return s.replace('\\"', '"') From jlg at codespeak.net Thu Jul 5 19:11:25 2007 From: jlg at codespeak.net (jlg at codespeak.net) Date: Thu, 5 Jul 2007 19:11:25 +0200 (CEST) Subject: [pypy-svn] r44751 - pypy/dist/pypy/lang/scheme/test Message-ID: <20070705171125.C5A9E80F3@code0.codespeak.net> Author: jlg Date: Thu Jul 5 19:11:25 2007 New Revision: 44751 Modified: pypy/dist/pypy/lang/scheme/test/test_eval.py Log: lambda formals with last cdr not nil Modified: pypy/dist/pypy/lang/scheme/test/test_eval.py ============================================================================== --- pypy/dist/pypy/lang/scheme/test/test_eval.py (original) +++ pypy/dist/pypy/lang/scheme/test/test_eval.py Thu Jul 5 19:11:25 2007 @@ -240,6 +240,17 @@ assert w_result.cdr.car.to_number() == 2 assert w_result.cdr.cdr.car.to_number() == 3 +def test_lambda_dotted_lstarg(): + ctx = ExecutionContext() + w_result = eval_expr(ctx, """((lambda (x y . z) z) 3 4)""") + assert isinstance(w_result, W_Nil) + + w_result = eval_expr(ctx, """((lambda (x y . z) z) 3 4 5 6)""") + assert isinstance(w_result, W_Pair) + assert w_result.car.to_number() == 5 + assert w_result.cdr.car.to_number() == 6 + assert isinstance(w_result.cdr.cdr, W_Nil) + def test_quote(): w_fnum = eval_noctx("(quote 42)") assert isinstance(w_fnum, W_Fixnum) From pedronis at codespeak.net Fri Jul 6 13:21:12 2007 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Fri, 6 Jul 2007 13:21:12 +0200 (CEST) Subject: [pypy-svn] r44771 - pypy/extradoc/talk/ep2007/pypy_10_and_jit Message-ID: <20070706112112.191BE8156@code0.codespeak.net> Author: pedronis Date: Fri Jul 6 13:21:11 2007 New Revision: 44771 Added: pypy/extradoc/talk/ep2007/pypy_10_and_jit/ Log: directory for the long talk From pedronis at codespeak.net Fri Jul 6 13:46:45 2007 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Fri, 6 Jul 2007 13:46:45 +0200 (CEST) Subject: [pypy-svn] r44775 - pypy/extradoc/talk/ep2007/pypy_10_and_jit Message-ID: <20070706114645.538758167@code0.codespeak.net> Author: pedronis Date: Fri Jul 6 13:46:44 2007 New Revision: 44775 Added: pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt pypy/extradoc/talk/ep2007/pypy_10_and_jit/ui (contents, props changed) Log: start drafting the talk Added: pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt ============================================================================== --- (empty file) +++ pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt Fri Jul 6 13:46:44 2007 @@ -0,0 +1,53 @@ +.. include:: + +========================================================== +PyPy 1.0 xxxx +========================================================== + +:Authors: Armin Rigo,Samuele Pedroni + +What is PyPy? +============== + +PyPy 1.0 +================ + + +Paradigm +==================== + +.. raw:: html + +
+ +.. image:: arch-overview.png + :align: center + + +Translation framework +================================ + +.. raw:: html + +

+ +.. image:: arch-framework.png + :align: center + + +Compatibility Matrix +========================= + +... + +... starts of JIT stuff + + +.. xxx extra slide arch-translation diagram + + +.. |bullet| unicode:: U+02022 +.. footer:: Samuele Pedroni, Armin Rigo + + + Added: pypy/extradoc/talk/ep2007/pypy_10_and_jit/ui ============================================================================== --- (empty file) +++ pypy/extradoc/talk/ep2007/pypy_10_and_jit/ui Fri Jul 6 13:46:44 2007 @@ -0,0 +1 @@ +link ../ui \ No newline at end of file From pedronis at codespeak.net Fri Jul 6 15:17:55 2007 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Fri, 6 Jul 2007 15:17:55 +0200 (CEST) Subject: [pypy-svn] r44781 - pypy/extradoc/talk/ep2007/pypy_10_and_jit Message-ID: <20070706131755.AE9378165@code0.codespeak.net> Author: pedronis Date: Fri Jul 6 15:17:55 2007 New Revision: 44781 Added: pypy/extradoc/talk/ep2007/pypy_10_and_jit/arch-overview.png - copied unchanged from r44678, pypy/eu-tracking/talk/review2/translation_opts/arch-overview.png Log: copy this From pedronis at codespeak.net Fri Jul 6 15:18:30 2007 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Fri, 6 Jul 2007 15:18:30 +0200 (CEST) Subject: [pypy-svn] r44782 - pypy/extradoc/talk/ep2007/pypy_10_and_jit Message-ID: <20070706131830.34B508168@code0.codespeak.net> Author: pedronis Date: Fri Jul 6 15:18:29 2007 New Revision: 44782 Added: pypy/extradoc/talk/ep2007/pypy_10_and_jit/arch-framework.png - copied unchanged from r44678, pypy/eu-tracking/talk/review2/translation_opts/arch-framework.png Log: copy this png - From pedronis at codespeak.net Fri Jul 6 15:20:00 2007 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Fri, 6 Jul 2007 15:20:00 +0200 (CEST) Subject: [pypy-svn] r44783 - pypy/extradoc/talk/ep2007/pypy_10_and_jit Message-ID: <20070706132000.141F28169@code0.codespeak.net> Author: pedronis Date: Fri Jul 6 15:19:59 2007 New Revision: 44783 Added: pypy/extradoc/talk/ep2007/pypy_10_and_jit/arch-translation.png - copied unchanged from r44678, pypy/eu-tracking/talk/review2/translation_opts/arch-translation.png Log: copy this From pedronis at codespeak.net Fri Jul 6 15:20:33 2007 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Fri, 6 Jul 2007 15:20:33 +0200 (CEST) Subject: [pypy-svn] r44784 - pypy/extradoc/talk/ep2007/pypy_10_and_jit Message-ID: <20070706132033.56C32816B@code0.codespeak.net> Author: pedronis Date: Fri Jul 6 15:20:32 2007 New Revision: 44784 Added: pypy/extradoc/talk/ep2007/pypy_10_and_jit/compat-matrix.png - copied unchanged from r44678, pypy/eu-tracking/talk/review2/test_integration/compat-matrix.png Log: copy this From pedronis at codespeak.net Fri Jul 6 15:25:43 2007 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Fri, 6 Jul 2007 15:25:43 +0200 (CEST) Subject: [pypy-svn] r44785 - pypy/extradoc/talk/ep2007/pypy_10_and_jit Message-ID: <20070706132543.1B253817D@code0.codespeak.net> Author: pedronis Date: Fri Jul 6 15:25:42 2007 New Revision: 44785 Modified: pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt Log: some work on the intro part Modified: pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt ============================================================================== --- pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt (original) +++ pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt Fri Jul 6 15:25:42 2007 @@ -9,9 +9,16 @@ What is PyPy? ============== -PyPy 1.0 -================ +PyPy is: + +* A fun and challenging open source project with many contributions + +* An open source implementation of Python (written in Python) + +* A tool-chain with a *new paradigm* for building interpreters +From Dec 2004 to March 2006 PyPy was a research project, +funded by the EU and a consortium of companies. Paradigm ==================== @@ -23,6 +30,32 @@ .. image:: arch-overview.png :align: center +Motivation +============= + +Conventional approaches to interpreters face hard trade-offs: +speed, maintainability, flexibility. + +A lot of decisions are hard-coded pervasively, improvements +and evolution are hampered (e.g. psyco, stackless require quite some efforts +and cannot bring their full potential). + +Lots of duplication of effort to cover many platforms. + +*It should be possible to do better.* + +PyPy 1.0 +================ + +released: 27th March 2007 + +- *JIT compiler generator working on the Python interpreter* +- more optimizations +- CLI backend produces a PyPy.NET which can interact with CLR libraries +- taint object space and transparent proxies + +*Not completely mature yet but our original vision is fully +materialized* Translation framework ================================ @@ -34,17 +67,20 @@ .. image:: arch-framework.png :align: center +.. JIT stuff Compatibility Matrix ========================= -... - -... starts of JIT stuff - +.. image:: compat-matrix.png + :align: center -.. xxx extra slide arch-translation diagram +Translation Diagram +===================== +.. image:: arch-translation.png + :align: center + :scale: 90 .. |bullet| unicode:: U+02022 .. footer:: Samuele Pedroni, Armin Rigo From pedronis at codespeak.net Fri Jul 6 15:26:33 2007 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Fri, 6 Jul 2007 15:26:33 +0200 (CEST) Subject: [pypy-svn] r44787 - pypy/extradoc/talk/ep2007/pypy_10_and_jit Message-ID: <20070706132633.8DF6B8183@code0.codespeak.net> Author: pedronis Date: Fri Jul 6 15:26:33 2007 New Revision: 44787 Modified: pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt Log: we need a conclusion part Modified: pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt ============================================================================== --- pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt (original) +++ pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt Fri Jul 6 15:26:33 2007 @@ -69,6 +69,8 @@ .. JIT stuff +.. Conclusion??? + Compatibility Matrix ========================= From arigo at codespeak.net Fri Jul 6 15:26:56 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 6 Jul 2007 15:26:56 +0200 (CEST) Subject: [pypy-svn] r44788 - pypy/extradoc/talk/ep2007/pypy_10_and_jit Message-ID: <20070706132656.75FEA8183@code0.codespeak.net> Author: arigo Date: Fri Jul 6 15:26:56 2007 New Revision: 44788 Modified: pypy/extradoc/talk/ep2007/pypy_10_and_jit/ui Log: Fix the symlink. Modified: pypy/extradoc/talk/ep2007/pypy_10_and_jit/ui ============================================================================== --- pypy/extradoc/talk/ep2007/pypy_10_and_jit/ui (original) +++ pypy/extradoc/talk/ep2007/pypy_10_and_jit/ui Fri Jul 6 15:26:56 2007 @@ -1 +1 @@ -link ../ui \ No newline at end of file +link ../../ui \ No newline at end of file From pedronis at codespeak.net Fri Jul 6 15:42:01 2007 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Fri, 6 Jul 2007 15:42:01 +0200 (CEST) Subject: [pypy-svn] r44789 - pypy/extradoc/talk/ep2007/ui Message-ID: <20070706134201.B9BA8816F@code0.codespeak.net> Author: pedronis Date: Fri Jul 6 15:42:01 2007 New Revision: 44789 Added: pypy/extradoc/talk/ep2007/ui/ - copied from r44678, pypy/extradoc/talk/dls2006/ui/ Log: use this one From pedronis at codespeak.net Fri Jul 6 15:43:10 2007 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Fri, 6 Jul 2007 15:43:10 +0200 (CEST) Subject: [pypy-svn] r44790 - pypy/extradoc/talk/ep2007/pypy_10_and_jit Message-ID: <20070706134310.CBEBC818C@code0.codespeak.net> Author: pedronis Date: Fri Jul 6 15:43:10 2007 New Revision: 44790 Added: pypy/extradoc/talk/ep2007/pypy_10_and_jit/ui Log: change back, I forgot to checkin the ui one level up It seems we have different versions of it around Added: pypy/extradoc/talk/ep2007/pypy_10_and_jit/ui ============================================================================== --- (empty file) +++ pypy/extradoc/talk/ep2007/pypy_10_and_jit/ui Fri Jul 6 15:43:10 2007 @@ -0,0 +1 @@ +link ../ui \ No newline at end of file From pedronis at codespeak.net Fri Jul 6 16:23:27 2007 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Fri, 6 Jul 2007 16:23:27 +0200 (CEST) Subject: [pypy-svn] r44791 - pypy/extradoc/talk/ep2007/pypy_10_and_jit Message-ID: <20070706142327.0FE92813A@code0.codespeak.net> Author: pedronis Date: Fri Jul 6 16:23:26 2007 New Revision: 44791 Added: pypy/extradoc/talk/ep2007/pypy_10_and_jit/overview2.png - copied unchanged from r44678, pypy/eu-tracking/talk/review2/dynamic_opts/overview2.png Log: jit approach overview From pedronis at codespeak.net Fri Jul 6 16:25:03 2007 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Fri, 6 Jul 2007 16:25:03 +0200 (CEST) Subject: [pypy-svn] r44792 - pypy/extradoc/talk/ep2007/pypy_10_and_jit Message-ID: <20070706142503.2EB23813A@code0.codespeak.net> Author: pedronis Date: Fri Jul 6 16:25:01 2007 New Revision: 44792 Modified: pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt Log: paste in our the material from the review Modified: pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt ============================================================================== --- pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt (original) +++ pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt Fri Jul 6 16:25:01 2007 @@ -67,9 +67,180 @@ .. image:: arch-framework.png :align: center -.. JIT stuff +Flexibility vs. Performance +============================= + +* interpreters are easy to write and evolve + +* for high performance dynamic compilation is required + +Traditional dynamic compilers +=============================== + +* huge resource investment +* the richer the semantics, the harder to write +* poor encoding of language semantics +* hard to evolve + +Need for novel approaches! + +PyPy Approach: Goal +============================= + +.. raw:: html + +
+ +.. image:: overview2.png + :scale: 55 + + +PyPy Approach (2) +======================= + +* use partial evaluation techniques to generate a dynamic compiler + from an interpreter +* inspiration: Psyco +* our translation tool-chain was designed for trying this + +Futamura +===================== + +* *Partial evalution of computation process - + an approach to a compiler-compiler*, '71 + +* Generating compilers from interpreters, + automatic specialization + +* Relatively little practical impact so far + +Challenges +====================== + +* Effective dynamic compilation requires feedback of runtime + information into compile-time + +* A shortcoming of PE is that in many cases not much can be really + assumed constant at compile-time: poor results + +* For a dynamic language: types are a primary example + +Solution: Promotion +==================== + +* enhance PE with the ability + to "promote" run-time values + to compile-time + +* leverage the dynamic setting + + +Overall ingredients +===================== + +The pieces to enable effective dynamic compiler generation +in PyPy: + +- implementer-supplied hint based approach to fixing + what should be assumed compile-time constant +- *promotion* +- direct support for lazy + allocation only on escape + ("virtuals") +- use stack and registers for language-level frame contents + +.. ("virtualizables") + +Language-agnostic +==================== + +* The dynamic generation process and primitives are language-agnostic. + +* The language implementations should be able to evolve up to + maintaining the hints. + +* By construction all interpreter/language features are supported + +pypy-c-jit +====================== + +PyPy 1.0 contains both the dynamic compiler generator and the start of +its application to PyPy's Python intepreter. + +* included are backends for IA32 and PPC +* integer aritmethic operations are optimized +* for things for which hints were provided + we are in the speed range of gcc -O0 +* demo (63x faster than CPython) + +.. demo f1 + +The transformation: Timeshifting +================================== + +The generation process is implemented as a *binding-time ("color")* +directed transformation of the low-level graphs. + +Coloring +================= + +* green: compile-time value +* red: runtime value + +we reuse the type inference +framework to propagate colors +respecting the constraints from +the hints + +Timeshifting Basics +==================== + +* green operations: unchanged, executed at compile-time + +* red operations: converted into corresponding code emitting code + +Timeshifting Control Flow +=========================== + +- red split points: schedule multiple compilation states +- merge points: merge logic to reuse code for equivalent states + +Promotion +================= + +Promotion is implemented generating a switch that grows to cover the +seen runtime values + +* First compilation stops at a promotion point and the switch with + only a default case is generated. The default will call back into + the compiler with runtime values. + +* On callback the compiler add one more case to the switch and + generate more code assuming the received value. + +.. need to save state in a compact form: paths + +Virtuals + Promotion +===================== + +* example + +.. tlc example results + +Conclusion +============= + +xxx we need some more general status/conclusion slides + +Effective dynamic compiler generation make flexibility and ease of +evolution mostly **orthogonal to the performance question**. + +Implementers are free to implement languages as **understandable interpreters**. + +PyPy proves this a viable approach worth of further exploration. + + -.. Conclusion??? Compatibility Matrix ========================= From arigo at codespeak.net Fri Jul 6 16:56:53 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 6 Jul 2007 16:56:53 +0200 (CEST) Subject: [pypy-svn] r44793 - pypy/extradoc/talk/ep2007/pypy_10_and_jit Message-ID: <20070706145653.136558132@code0.codespeak.net> Author: arigo Date: Fri Jul 6 16:56:52 2007 New Revision: 44793 Added: pypy/extradoc/talk/ep2007/pypy_10_and_jit/ui (contents, props changed) Modified: pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt Log: Reorder a few slides; add a bit of content. The intro is still light but getting better IMHO. Modified: pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt ============================================================================== --- pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt (original) +++ pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt Fri Jul 6 16:56:52 2007 @@ -20,6 +20,20 @@ From Dec 2004 to March 2006 PyPy was a research project, funded by the EU and a consortium of companies. +Motivation +============= + +Conventional approaches to interpreters face hard trade-offs: +speed, maintainability, flexibility. + +A lot of decisions are hard-coded pervasively, improvements +and evolution are hampered (e.g. psyco, stackless require quite some efforts +and cannot bring their full potential). + +Lots of duplication of effort to cover many platforms (C, Java, .NET). + +*It should be possible to do better.* + Paradigm ==================== @@ -30,24 +44,23 @@ .. image:: arch-overview.png :align: center -Motivation -============= - -Conventional approaches to interpreters face hard trade-offs: -speed, maintainability, flexibility. +PyPy 1.0 +================ -A lot of decisions are hard-coded pervasively, improvements -and evolution are hampered (e.g. psyco, stackless require quite some efforts -and cannot bring their full potential). +Released: 27th March 2007 -Lots of duplication of effort to cover many platforms. +Contains, as before: -*It should be possible to do better.* +- a full compliant Python interpreter +- a translation tool-chain that produces reasonably efficient interpreters: + PyPy-C, PyPy-LLVM, PyPy.NET PyPy 1.0 ================ -released: 27th March 2007 +Released: 27th March 2007 + +What's new: - *JIT compiler generator working on the Python interpreter* - more optimizations @@ -57,15 +70,22 @@ *Not completely mature yet but our original vision is fully materialized* -Translation framework -================================ +Compatibility Matrix +========================= -.. raw:: html +.. image:: compat-matrix.png + :align: center -

+Status +========= -.. image:: arch-framework.png - :align: center +xxx a status slide could fit here + + +JIT compiler generator +====================== + +.. (empty transition slide to say "in this talk we're mainly focusing on...") Flexibility vs. Performance ============================= @@ -107,7 +127,7 @@ ===================== * *Partial evalution of computation process - - an approach to a compiler-compiler*, '71 + an approach to a compiler-compiler*, 1971 * Generating compilers from interpreters, automatic specialization @@ -199,12 +219,16 @@ * red operations: converted into corresponding code emitting code +.. demo? + Timeshifting Control Flow =========================== - red split points: schedule multiple compilation states - merge points: merge logic to reuse code for equivalent states +.. demo? + Promotion ================= @@ -220,6 +244,8 @@ .. need to save state in a compact form: paths +.. demo? + Virtuals + Promotion ===================== @@ -227,10 +253,8 @@ .. tlc example results -Conclusion -============= - -xxx we need some more general status/conclusion slides +Conclusion (JIT) +================ Effective dynamic compiler generation make flexibility and ease of evolution mostly **orthogonal to the performance question**. @@ -239,13 +263,23 @@ PyPy proves this a viable approach worth of further exploration. +Conclusion +========== +xxx we need some more general status/conclusion slides -Compatibility Matrix -========================= -.. image:: compat-matrix.png +.. the end + +Translation framework +================================ + +.. raw:: html + +

+ +.. image:: arch-framework.png :align: center Translation Diagram Added: pypy/extradoc/talk/ep2007/pypy_10_and_jit/ui ============================================================================== --- (empty file) +++ pypy/extradoc/talk/ep2007/pypy_10_and_jit/ui Fri Jul 6 16:56:52 2007 @@ -0,0 +1 @@ +link ../ui \ No newline at end of file From hpk at codespeak.net Fri Jul 6 18:50:00 2007 From: hpk at codespeak.net (hpk at codespeak.net) Date: Fri, 6 Jul 2007 18:50:00 +0200 (CEST) Subject: [pypy-svn] r44795 - in pypy/extradoc/talk/ep2007: . interpreter Message-ID: <20070706165000.B7AAB8170@code0.codespeak.net> Author: hpk Date: Fri Jul 6 18:49:59 2007 New Revision: 44795 Added: pypy/extradoc/talk/ep2007/interpreter/ pypy/extradoc/talk/ep2007/interpreter/dynlang.png - copied unchanged from r44794, pypy/extradoc/talk/dzug2007/dynlang.png pypy/extradoc/talk/ep2007/interpreter/interpreter.txt - copied, changed from r44794, pypy/extradoc/talk/ep2007/interpreter.txt Removed: pypy/extradoc/talk/ep2007/interpreter.txt Log: shifting interpreter talk to its own directory, amending it with a few more slides (need to cross-check for redundancy ...) from dzug2007 From hpk at codespeak.net Fri Jul 6 18:50:35 2007 From: hpk at codespeak.net (hpk at codespeak.net) Date: Fri, 6 Jul 2007 18:50:35 +0200 (CEST) Subject: [pypy-svn] r44796 - pypy/extradoc/talk/ep2007/interpreter Message-ID: <20070706165035.BBBC78170@code0.codespeak.net> Author: hpk Date: Fri Jul 6 18:50:34 2007 New Revision: 44796 Added: pypy/extradoc/talk/ep2007/interpreter/ui (contents, props changed) Log: adding ui link Added: pypy/extradoc/talk/ep2007/interpreter/ui ============================================================================== --- (empty file) +++ pypy/extradoc/talk/ep2007/interpreter/ui Fri Jul 6 18:50:34 2007 @@ -0,0 +1 @@ +link ../ui \ No newline at end of file From arigo at codespeak.net Fri Jul 6 18:54:53 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 6 Jul 2007 18:54:53 +0200 (CEST) Subject: [pypy-svn] r44797 - pypy/extradoc/talk/ep2007/pypy_10_and_jit Message-ID: <20070706165453.00D50816F@code0.codespeak.net> Author: arigo Date: Fri Jul 6 18:54:53 2007 New Revision: 44797 Modified: pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt Log: Status and a Performance slide. Modified: pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt ============================================================================== --- pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt (original) +++ pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt Fri Jul 6 18:54:53 2007 @@ -79,13 +79,35 @@ Status ========= -xxx a status slide could fit here - +* still rough edges that need polishing +* still missing a few important extension modules +* right now, useful parts: special languag features; RPython for high-perf + +Performance +============= + +Current interpreter performance is not bad, but lower than CPython: + ++----------+-------------------+---------------+ +| | CPython 2.4.4 | pypy-llvm | ++==========+===================+===============+ +| richards | 1.00 | 1.17 | ++----------+-------------------+---------------+ +| pystone | 1.00 | 1.55 | ++----------+-------------------+---------------+ +| templess | 1.00 | 5.41 | ++----------+-------------------+---------------+ +| gadfly2 | 1.00 | 6.38 | ++----------+-------------------+---------------+ +| mako | 1.00 | 4.46 | ++----------+-------------------+---------------+ JIT compiler generator ====================== -.. (empty transition slide to say "in this talk we're mainly focusing on...") +* our trump card to run plain Python programs fast + +* still work in progress! Flexibility vs. Performance ============================= From fijal at codespeak.net Fri Jul 6 20:01:27 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Fri, 6 Jul 2007 20:01:27 +0200 (CEST) Subject: [pypy-svn] r44802 - in pypy/extradoc/talk/ep2007: . rpython rpython-demo Message-ID: <20070706180127.0DA2C816F@code0.codespeak.net> Author: fijal Date: Fri Jul 6 20:01:27 2007 New Revision: 44802 Added: pypy/extradoc/talk/ep2007/rpython/ - copied from r44798, pypy/extradoc/talk/ep2007/rpython-demo/ pypy/extradoc/talk/ep2007/rpython/rpython.txt - copied unchanged from r44798, pypy/extradoc/talk/ep2007/rpython.txt Removed: pypy/extradoc/talk/ep2007/rpython-demo/ pypy/extradoc/talk/ep2007/rpython.txt Log: Make direcory structure a bit more the same everywhere From fijal at codespeak.net Fri Jul 6 20:02:10 2007 From: fijal at codespeak.net (fijal at codespeak.net) Date: Fri, 6 Jul 2007 20:02:10 +0200 (CEST) Subject: [pypy-svn] r44804 - pypy/extradoc/talk/ep2007/rpython Message-ID: <20070706180210.1CA598159@code0.codespeak.net> Author: fijal Date: Fri Jul 6 20:02:09 2007 New Revision: 44804 Modified: pypy/extradoc/talk/ep2007/rpython/rpython.txt Log: Add a date Modified: pypy/extradoc/talk/ep2007/rpython/rpython.txt ============================================================================== --- pypy/extradoc/talk/ep2007/rpython/rpython.txt (original) +++ pypy/extradoc/talk/ep2007/rpython/rpython.txt Fri Jul 6 20:02:09 2007 @@ -5,7 +5,7 @@ :Authors: Antonio Cuni (DISI), Maciej Fijalkowski (merlinux GmbH) :Place: Europython 2007 -:Date: XXX +:Date: 10 July 2007 Why invent new language? ------------------------ From arigo at codespeak.net Fri Jul 6 20:33:35 2007 From: arigo at codespeak.net (arigo at codespeak.net) Date: Fri, 6 Jul 2007 20:33:35 +0200 (CEST) Subject: [pypy-svn] r44806 - in pypy/extradoc/talk/ep2007: interpreter pypy_10_and_jit Message-ID: <20070706183335.90D968173@code0.codespeak.net> Author: arigo Date: Fri Jul 6 20:33:33 2007 New Revision: 44806 Modified: pypy/extradoc/talk/ep2007/interpreter/interpreter.txt pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt Log: The current benchmarks (it's the latest pypy-llvm that builds). Modified: pypy/extradoc/talk/ep2007/interpreter/interpreter.txt ============================================================================== --- pypy/extradoc/talk/ep2007/interpreter/interpreter.txt (original) +++ pypy/extradoc/talk/ep2007/interpreter/interpreter.txt Fri Jul 6 20:33:33 2007 @@ -151,21 +151,21 @@ Relative speeds to CPython ------------------------------ +(2007-06-14) + +----------+-------------------+---------------+ | | CPython 2.4.4 | pypy-llvm | +==========+===================+===============+ -| richards | 1.00 | 1.17 | +| richards | 1.00 | 1.44 | +----------+-------------------+---------------+ -| pystone | 1.00 | 1.55 | -+----------+-------------------+---------------+ -| templess | 1.00 | 5.41 | +| pystone | 1.00 | 1.28 | +----------+-------------------+---------------+ -| gadfly | 1.00 | 6.38 | +| templess | 1.00 | 3.81 | +----------+-------------------+---------------+ -| mako | 1.00 | 7.65 | +| gadfly2 | 1.00 | 6.22 | ++----------+-------------------+---------------+ +| mako | 1.00 | 3.11 | +----------+-------------------+---------------+ - -(March 2007, improvements afterwards) Python Interpreter Status (1.0) --------------------------------- Modified: pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt ============================================================================== --- pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt (original) +++ pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt Fri Jul 6 20:33:33 2007 @@ -86,28 +86,33 @@ Performance ============= -Current interpreter performance is not bad, but lower than CPython: +Current interpreter performance (2007-06-14) is not bad, but lower than +CPython: +----------+-------------------+---------------+ | | CPython 2.4.4 | pypy-llvm | +==========+===================+===============+ -| richards | 1.00 | 1.17 | +| richards | 1.00 | 1.44 | +----------+-------------------+---------------+ -| pystone | 1.00 | 1.55 | +| pystone | 1.00 | 1.28 | +----------+-------------------+---------------+ -| templess | 1.00 | 5.41 | +| templess | 1.00 | 3.81 | +----------+-------------------+---------------+ -| gadfly2 | 1.00 | 6.38 | +| gadfly2 | 1.00 | 6.22 | +----------+-------------------+---------------+ -| mako | 1.00 | 4.46 | +| mako | 1.00 | 3.11 | +----------+-------------------+---------------+ JIT compiler generator ====================== -* our trump card to run plain Python programs fast +* a lot of time is spent in the Garbage Collector, + so we have room for improvement there -* still work in progress! +* but our real trump card to run plain Python programs fast + is the JIT compiler generator + +* works - but still work in progress before it's really useful! Flexibility vs. Performance ============================= From pedronis at codespeak.net Fri Jul 6 20:34:14 2007 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Fri, 6 Jul 2007 20:34:14 +0200 (CEST) Subject: [pypy-svn] r44807 - pypy/extradoc/talk/ep2007/pypy_10_and_jit Message-ID: <20070706183414.A2F758179@code0.codespeak.net> Author: pedronis Date: Fri Jul 6 20:34:14 2007 New Revision: 44807 Modified: pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt Log: typo Modified: pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt ============================================================================== --- pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt (original) +++ pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt Fri Jul 6 20:34:14 2007 @@ -81,7 +81,7 @@ * still rough edges that need polishing * still missing a few important extension modules -* right now, useful parts: special languag features; RPython for high-perf +* right now, useful parts: special language features; RPython for high-perf Performance ============= From antocuni at codespeak.net Fri Jul 6 20:49:24 2007 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Fri, 6 Jul 2007 20:49:24 +0200 (CEST) Subject: [pypy-svn] r44809 - pypy/extradoc/talk/ep2007/rpython Message-ID: <20070706184924.F36908183@code0.codespeak.net> Author: antocuni Date: Fri Jul 6 20:49:24 2007 New Revision: 44809 Added: pypy/extradoc/talk/ep2007/rpython/demo.py (contents, props changed) Log: automatic execution of the demo Added: pypy/extradoc/talk/ep2007/rpython/demo.py ============================================================================== --- (empty file) +++ pypy/extradoc/talk/ep2007/rpython/demo.py Fri Jul 6 20:49:24 2007 @@ -0,0 +1,9 @@ +import clr +clr.AddReferenceToFile('mylib.dll') + +import func +import mylib + +N = 10**7 +print func.fn(N) +print mylib.fn(N) From antocuni at codespeak.net Fri Jul 6 20:50:34 2007 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Fri, 6 Jul 2007 20:50:34 +0200 (CEST) Subject: [pypy-svn] r44810 - pypy/extradoc/talk/ep2007/rpython Message-ID: <20070706185034.4C1D78181@code0.codespeak.net> Author: antocuni Date: Fri Jul 6 20:50:33 2007 New Revision: 44810 Added: pypy/extradoc/talk/ep2007/rpython/ui (contents, props changed) Log: add a link to ../ui Added: pypy/extradoc/talk/ep2007/rpython/ui ============================================================================== --- (empty file) +++ pypy/extradoc/talk/ep2007/rpython/ui Fri Jul 6 20:50:33 2007 @@ -0,0 +1 @@ +link ../ui/ \ No newline at end of file From antocuni at codespeak.net Fri Jul 6 22:03:01 2007 From: antocuni at codespeak.net (antocuni at codespeak.net) Date: Fri, 6 Jul 2007 22:03:01 +0200 (CEST) Subject: [pypy-svn] r44811 - pypy/extradoc/talk/ep2007/rpython Message-ID: <20070706200301.70C15818C@code0.codespeak.net> Author: antocuni Date: Fri Jul 6 22:02:59 2007 New Revision: 44811 Modified: pypy/extradoc/talk/ep2007/rpython/rpython.txt Log: some edits and some new slides Modified: pypy/extradoc/talk/ep2007/rpython/rpython.txt ============================================================================== --- pypy/extradoc/talk/ep2007/rpython/rpython.txt (original) +++ pypy/extradoc/talk/ep2007/rpython/rpython.txt Fri Jul 6 22:02:59 2007 @@ -1,16 +1,21 @@ ======================================================= -RPython: need for speed aka C and C# considered harmful +RPython: Need for speed ======================================================= -:Authors: Antonio Cuni (DISI), Maciej Fijalkowski (merlinux GmbH) +aka: C and C# considered harmful +================================ + +:Authors: Antonio Cuni (DISI - University of Genoa), Maciej Fijalkowski (merlinux GmbH) :Place: Europython 2007 :Date: 10 July 2007 Why invent new language? ------------------------ -* Grown as a side effect of the pypy project +XXX antocuni: I think this slide makes more sense after the next + +* Grown as a side effect of the PyPy project * Python is too slow for some purposes @@ -21,55 +26,72 @@ What is RPython? ---------------- -* Python (every RPython program has the same meaning - when run on top of CPython) +* RPython programs run unmodified on top of CPython * Restricted subset * Constructed from live objects - initialization is done in Python -* XXX more? +* Python is the meta-programming language for RPython + Restricted, what do you mean? ----------------------------- -* Full type inference - you cannot mix incompatible types +* Static type system -* Polymorphic collections (ie list of ints) +* Full type inference - you cannot mix incompatible types -* No dynamic stuff: switch class, add/remove methods, etc. +* Polymorphic collections (i.e. list of ints) * Java-like object model +* No dynamic stuff: switch class, add/remove methods, etc. + * No support for special methods (only __init__ and __del__ works) -* No frames and such stuff +* No introspection Example of use case ------------------- * Write code -* test/debug on top of CPython +* Test/debug on top of CPython -* compile +* Compile -* graph viewer +* Graph viewer Type inference -------------- XXXX should we really mention that? +:: + + def foo(): + return bar(1, 2) + bar(3, 4.5) + + def bar(a, b): + return a+1 + +* a: Signed U Siged --> Signed + +* b: Signed U Float --> Float + +* result of bar: Signed + 1 --> Signed + + Modules restrictions -------------------- -* few modules work +* Few modules work -* they have different, more static API (ie open()) +* They have different, more static API (ie open()) -* all modules might be used when initializing +* All modules might be used when initializing Few more words about file API ----------------------------- @@ -94,10 +116,21 @@ * no more pros... -Writing standalone C programs ------------------------------ +Writing standalone C/.NET/JVM programs +-------------------------------------- + +:: -XXX explain writing targets + def target(*args): + return entry_point, None + + def entry_point(argv): + print 'Hello World!' + return 0 + +* see also translator/goal/targetnopstandalone.py + +* ./translate.py [--backend={c|cli|jvm}] targetXXX.py Writing CPython extensions --------------------------- @@ -131,6 +164,8 @@ * Live demo +* http://codespeak.net/pypy/dist/pypy/doc/carbonpython.html + The JVM backend --------------- @@ -141,6 +176,7 @@ * Not as mature as gencli +* Only executables at the moment The JS backend @@ -148,3 +184,16 @@ XXX fijal, feel free to fill in + +Conclusions +----------- + +* RPython has lot of rough edges + +* ...but it might be useful in some contexts + +* More convenient than C/C++/C#/Java + +* Much faster than CPython/IronPython/Jython + +* Stay tuned From pedronis at codespeak.net Fri Jul 6 23:11:24 2007 From: pedronis at codespeak.net (pedronis at codespeak.net) Date: Fri, 6 Jul 2007 23:11:24 +0200 (CEST) Subject: [pypy-svn] r44812 - pypy/extradoc/talk/ep2007/pypy_10_and_jit Message-ID: <20070706211124.A05BE818E@code0.codespeak.net> Author: pedronis Date: Fri Jul 6 23:11:22 2007 New Revision: 44812 Modified: pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt Log: tentative conclusion slide Modified: pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt ============================================================================== --- pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt (original) +++ pypy/extradoc/talk/ep2007/pypy_10_and_jit/talk.txt Fri Jul 6 23:11:22 2007 @@ -293,8 +293,17 @@ Conclusion ========== -xxx we need some more general status/conclusion slides +We have achieved a malleable interpreter and interpreter-making +process which can only further improve over time, proving our vision +sound. +This is a solid base looking forward: + +- the rough edges are what we need to tackle next + +- development is going to continue in open source fashion + +- there will be further sprints: one is organized after the conference! .. the end From fijal at codespeak.net Sat Jul 7 11:14:20 20