Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
Simple test of subcalls in NQP.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmichaud committed Oct 21, 2009
1 parent 3de213c commit 5b85aa3
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
22 changes: 21 additions & 1 deletion src/NQP/Actions.pm
Expand Up @@ -11,7 +11,27 @@ NQP::Grammar.O(':prec<r=>, :assoc<list>', '%concatenation');
NQP::Grammar.O(':prec<i=>, :assoc<right>', '%assignment');
NQP::Grammar.O(':prec<g=>, :assoc<list>, :nextterm<nulltermish>', '%comma');

method TOP($/) { make $<EXPR>.ast; }
method TOP($/) { make $<subcall>.ast; }

method subcall($/) {
my $past := $<arglist>.ast;
$past.name(~$<ident>);
$past.pasttype('call');
$past.node($/);
make $past;
}

method arglist($/) {
my $past := PAST::Op.new( :node($/) );
if $<EXPR> {
my $expr := $<EXPR>[0].ast;
if $expr.name eq 'infix:<,>' {
for $expr.list { $past.push($_); }
}
else { $past.push($expr); }
}
make $past;
}

method term:sym<value>($/) { make $<value>.ast; }

Expand Down
1 change: 1 addition & 0 deletions src/NQP/Compiler.pir
Expand Up @@ -15,6 +15,7 @@ NQP::Compiler - NQP compiler

.include 'src/gen/nqp-grammar.pir'
.include 'src/gen/nqp-actions.pir'
.include 'src/cheats/nqp-builtins.pir'

.namespace ['NQP';'Compiler']

Expand Down
6 changes: 5 additions & 1 deletion src/NQP/Grammar.pm
@@ -1,6 +1,10 @@
grammar NQP::Grammar is HLL::Grammar;

token TOP { <EXPR> }
token TOP { <subcall> }

token subcall { <ident> '(' <arglist> ')' }

rule arglist { <EXPR>? }

proto token term { <...> }
token term:sym<value> { <value> }
Expand Down
19 changes: 19 additions & 0 deletions src/cheats/nqp-builtins.pir
@@ -0,0 +1,19 @@
.namespace []

.sub 'print'
.param pmc list :slurpy
.local pmc list_it
list_it = iter list
list_loop:
unless list_it goto list_done
$P0 = shift list_it
print $P0
goto list_loop
list_done:
.return (1)
.end

.sub 'say'
.param pmc list :slurpy
.tailcall 'print'(list :flat, "\n")
.end

0 comments on commit 5b85aa3

Please sign in to comment.