[pure-lang-svn] SF.net SVN: pure-lang:[527] pure/trunk
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-08-18 07:02:34
|
Revision: 527 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=527&view=rev Author: agraef Date: 2008-08-18 07:02:41 +0000 (Mon, 18 Aug 2008) Log Message: ----------- Add tail-recursive sequence operator. Modified Paths: -------------- pure/trunk/ChangeLog pure/trunk/interpreter.cc pure/trunk/lib/prelude.pure pure/trunk/lib/primitives.pure pure/trunk/symtable.cc pure/trunk/symtable.hh Modified: pure/trunk/ChangeLog =================================================================== --- pure/trunk/ChangeLog 2008-08-17 22:56:36 UTC (rev 526) +++ pure/trunk/ChangeLog 2008-08-18 07:02:41 UTC (rev 527) @@ -1,3 +1,11 @@ +2008-08-18 Albert Graef <Dr....@t-...> + + * interpreter.cc (codegen): Generate tail-recursive code for + sequence operator. + + * lib/prelude.pure, lib/primitives.pure: Definition of $$ sequence + operator. + 2008-08-17 Albert Graef <Dr....@t-...> * pure.cc, interpreter.cc/h, runtime.cc: Overhaul of the script Modified: pure/trunk/interpreter.cc =================================================================== --- pure/trunk/interpreter.cc 2008-08-17 22:56:36 UTC (rev 526) +++ pure/trunk/interpreter.cc 2008-08-18 07:02:41 UTC (rev 527) @@ -4233,7 +4233,12 @@ (v = funcall(e, n, x))) // recursive call to a global function return v; - else if (n == 2 && f.tag() == symtab.catch_sym().f) { + else if (n == 2 && f.ftag() == symtab.seq_sym().f) { + // sequence operator + Value *u = codegen(x.xval1().xval2()); + act_builder().CreateCall(module->getFunction("pure_freenew"), u); + return codegen(x.xval2()); + } else if (n == 2 && f.tag() == symtab.catch_sym().f) { // catch an exception; create a little anonymous closure to be called // through pure_catch() expr h = x.xval1().xval2(), y = x.xval2(); Modified: pure/trunk/lib/prelude.pure =================================================================== --- pure/trunk/lib/prelude.pure 2008-08-17 22:56:36 UTC (rev 526) +++ pure/trunk/lib/prelude.pure 2008-08-18 07:02:41 UTC (rev 527) @@ -45,6 +45,7 @@ /* Operators. Note that the parser will automagically give unary minus the same precedence level as the corresponding binary operator. */ +infixl 0 $$ ; // sequence operator infixr 0 $ ; // right-associative application infixr 1 , ; // pair (tuple) infix 2 => ; // mapsto constructor Modified: pure/trunk/lib/primitives.pure =================================================================== --- pure/trunk/lib/primitives.pure 2008-08-17 22:56:36 UTC (rev 526) +++ pure/trunk/lib/primitives.pure 2008-08-18 07:02:41 UTC (rev 527) @@ -201,12 +201,14 @@ x::double==y::int = x==y; x::double!=y::int = x!=y; -/* Logical connectives. Please note that these will be short-circuited only as - explicit calls! But we still want them to work if they are applied - partially, so we add these rules here. */ +/* Logical connectives and sequences. Please note that these enjoy + call-by-name and short-circuit evaluation only as explicit calls! But we + still want them to work if they are applied partially, so we add these + rules here. */ x::int&&y::int = x&&y; x::int||y::int = x||y; +x$$y = y; /* Bigint arithmetic. */ Modified: pure/trunk/symtable.cc =================================================================== --- pure/trunk/symtable.cc 2008-08-17 22:56:36 UTC (rev 526) +++ pure/trunk/symtable.cc 2008-08-18 07:02:41 UTC (rev 527) @@ -120,6 +120,15 @@ return sym(",", 1, infixr); } +symbol& symtable::seq_sym() +{ + symbol *_sym = lookup("$$"); + if (_sym) + return *_sym; + else + return sym("$$", 0, infixl); +} + symbol& symtable::not_sym() { symbol *_sym = lookup("not"); Modified: pure/trunk/symtable.hh =================================================================== --- pure/trunk/symtable.hh 2008-08-17 22:56:36 UTC (rev 526) +++ pure/trunk/symtable.hh 2008-08-18 07:02:41 UTC (rev 527) @@ -49,6 +49,7 @@ symbol& cons_sym(); symbol& void_sym(); symbol& pair_sym(); + symbol& seq_sym(); symbol& neg_sym() { return sym("neg"); } symbol& not_sym(); symbol& bitnot_sym(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |