[pure-lang-svn] SF.net SVN: pure-lang:[808] pure/trunk
Status: Beta
Brought to you by:
agraef
From: <ag...@us...> - 2008-09-20 16:39:45
|
Revision: 808 http://pure-lang.svn.sourceforge.net/pure-lang/?rev=808&view=rev Author: agraef Date: 2008-09-20 16:39:35 +0000 (Sat, 20 Sep 2008) Log Message: ----------- Syntax changes (list and array comprehension syntax). Modified Paths: -------------- pure/trunk/interpreter.cc pure/trunk/interpreter.hh pure/trunk/parser.yy pure/trunk/symtable.cc pure/trunk/symtable.hh Modified: pure/trunk/interpreter.cc =================================================================== --- pure/trunk/interpreter.cc 2008-09-20 16:37:50 UTC (rev 807) +++ pure/trunk/interpreter.cc 2008-09-20 16:39:35 UTC (rev 808) @@ -2754,6 +2754,40 @@ return new expr(y); } +expr interpreter::mkmatcomp_expr(expr x, size_t n, + comp_clause_list::iterator cs, + comp_clause_list::iterator end) +{ + if (cs == end) + return expr::cons(x, expr::nil()); + else { + comp_clause& c = *cs; + if (c.second.is_null()) { + expr p = c.first; + return expr::cond(p, mkmatcomp_expr(x, n, ++cs, end), expr::nil()); + } else { + expr pat = c.first, body = mkmatcomp_expr(x, n-1, ++cs, end), + arg = c.second; + closure(pat, body); + expr f = (n&1)?symtab.colcatmap_sym().x:symtab.rowcatmap_sym().x; + return expr(f, expr::lambda(pat, body), arg); + } + } +} + +expr *interpreter::mkmatcomp_expr(expr *x, comp_clause_list *cs) +{ + size_t n = 0; + for (comp_clause_list::iterator it = cs->begin(), end = cs->end(); + it != end; it++) { + comp_clause& c = *it; + if (!c.second.is_null()) n++; + } + expr y = mkmatcomp_expr(*x, n, cs->begin(), cs->end()); + delete x; delete cs; + return new expr(y); +} + // Code generation. #define Dbl(d) ConstantFP::get(Type::DoubleTy, d) Modified: pure/trunk/interpreter.hh =================================================================== --- pure/trunk/interpreter.hh 2008-09-20 16:37:50 UTC (rev 807) +++ pure/trunk/interpreter.hh 2008-09-20 16:39:35 UTC (rev 808) @@ -483,6 +483,9 @@ expr *mklistcomp_expr(expr *x, comp_clause_list *cs); expr mklistcomp_expr(expr x, comp_clause_list::iterator cs, comp_clause_list::iterator end); + expr *mkmatcomp_expr(expr *x, comp_clause_list *cs); + expr mkmatcomp_expr(expr x, size_t n, comp_clause_list::iterator cs, + comp_clause_list::iterator end); // LLVM code generation and execution. Modified: pure/trunk/parser.yy =================================================================== --- pure/trunk/parser.yy 2008-09-20 16:37:50 UTC (rev 807) +++ pure/trunk/parser.yy 2008-09-20 16:39:35 UTC (rev 808) @@ -526,8 +526,14 @@ | DBL { $$ = new expr(EXPR::DBL, $1); } | STR { $$ = new expr(EXPR::STR, $1); } | '{' rows '}' { $$ = new expr(EXPR::MATRIX, $2); } +| '{' expr '|' comp_clauses '}' + { $$ = interp.mkmatcomp_expr($2, $4); } | '[' expr ']' { $$ = interp.mklist_expr($2); } | '[' expr ';' comp_clauses ']' + { interp.warning(yyloc, + "warning: deprecated comprehension syntax"); + $$ = interp.mklistcomp_expr($2, $4); } +| '[' expr '|' comp_clauses ']' { $$ = interp.mklistcomp_expr($2, $4); } | '(' expr ')' { $$ = $2; if ($$->is_pair()) $$->flags() |= EXPR::PAREN; } Modified: pure/trunk/symtable.cc =================================================================== --- pure/trunk/symtable.cc 2008-09-20 16:37:50 UTC (rev 807) +++ pure/trunk/symtable.cc 2008-09-20 16:39:35 UTC (rev 808) @@ -34,11 +34,10 @@ fdiv_sym(); div_sym(); mod_sym(); - // complex_rect_sym() and complex_polar_sym() are not initialized here, as - // they're supposed to come from math.pure which is not included in the - // prelude catch_sym(); catmap_sym(); + rowcatmap_sym(); + colcatmap_sym(); failed_match_sym(); failed_cond_sym(); signal_sym(); Modified: pure/trunk/symtable.hh =================================================================== --- pure/trunk/symtable.hh 2008-09-20 16:37:50 UTC (rev 807) +++ pure/trunk/symtable.hh 2008-09-20 16:39:35 UTC (rev 808) @@ -92,6 +92,8 @@ symbol& mod_sym(); symbol& catch_sym() { return sym("catch"); } symbol& catmap_sym() { return sym("catmap"); } + symbol& rowcatmap_sym() { return sym("rowcatmap"); } + symbol& colcatmap_sym() { return sym("colcatmap"); } symbol& failed_match_sym() { return sym("failed_match"); } symbol& failed_cond_sym() { return sym("failed_cond"); } symbol& signal_sym() { return sym("signal"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |