Author: kjs Date: Thu Jan 10 15:27:17 2008 New Revision: 24736 Modified: trunk/languages/punie/lib/builtins.pir trunk/languages/punie/lib/punie-actions.pm trunk/languages/punie/lib/punie.pg
Log: [punie] o fix action for list. o add 'chop' to grammar o add action and built-in impl. for 'chop' Modified: trunk/languages/punie/lib/builtins.pir ============================================================================== --- trunk/languages/punie/lib/builtins.pir (original) +++ trunk/languages/punie/lib/builtins.pir Thu Jan 10 15:27:17 2008 @@ -228,10 +228,15 @@ .sub 'prefix:!' .param pmc a - $P0 = a + $P0 = !a .return ($P0) .end +.sub 'infix:,' + .param pmc args :slurpy + .return (args) +.end + .sub 'print' .param pmc list :slurpy .local pmc iter @@ -246,9 +251,12 @@ .return (1) .end -.sub 'infix:,' - .param pmc args :slurpy - .return (args) + +.sub 'chop' + .param pmc expr + $S0 = expr + chopn $S0, 1 + .return ($S0) .end # Local Variables: Modified: trunk/languages/punie/lib/punie-actions.pm ============================================================================== --- trunk/languages/punie/lib/punie-actions.pm (original) +++ trunk/languages/punie/lib/punie-actions.pm Thu Jan 10 15:27:17 2008 @@ -242,6 +242,22 @@ make $( $/{$key} ); } +method list($/) { + make PAST::Op.new( :inline(" new %r, 'ResizablePMCArray'"), :node($/) ); +} + +method do_chop($/) { + my $past := PAST::Op.new( :name('chop'), :pasttype('call'), :node($/) ); + + if $<expr> { + $past.push( $( $<expr>[0] ) ); + } + else { # XXX not sure if this scope should be package + $past.push( PAST::Var.new( :name('$_'), :scope('package') ) ); + } + make $past; +} + method variable($/) { my $viviself := 'Undef'; my $sigil := ~$<sigil>[0]; Modified: trunk/languages/punie/lib/punie.pg ============================================================================== --- trunk/languages/punie/lib/punie.pg (original) +++ trunk/languages/punie/lib/punie.pg Thu Jan 10 15:27:17 2008 @@ -98,6 +98,7 @@ token term { + | <list> {*} #= list | \( <expr> \) {*} #= expr | <number> {*} #= number | <integer> {*} #= integer @@ -107,7 +108,32 @@ | do <.ws> <block> {*} #= block | <opcall> {*} #= subcall | <subcall> {*} #= subcall + | <do_chop> {*} #= do_chop | <variable> {*} #= variable + + #| <split> {*} #= split + #| <join> {*} #= join +} + + +rule list { + \( \) + {*} +} + +## XXX add "pattern" to lexical rules. +##rule split { +## split [\( <variable> [',' <variable> [',' <expr>]? ]? \)]? +##} + +## XXX complete this and implement +##rule join { +## join [\( <oexpr> ',' <expr> \)]? +##} + +rule do_chop { + 'chop' [\( <expr> \)]? + {*} }