Skip to content

Commit

Permalink
Add a way to mark a block as having a custom arguments processor, and…
Browse files Browse the repository at this point in the history
… compile it to a :call_sig usage on Parrot.
  • Loading branch information
jnthn committed Jul 7, 2012
1 parent fd47dae commit 58acfd1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 26 deletions.
6 changes: 4 additions & 2 deletions src/QAST/Block.nqp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
class QAST::Block is QAST::Node {
has str $!blocktype;
has int $!lexical;
has int $!custom_args;
has str $!cuid;
has %!symbol;

method blocktype(*@value) { $!blocktype := @value[0] if @value; $!blocktype }
method lexical(*@value) { $!lexical := @value[0] if @value; $!lexical }
method blocktype(*@value) { $!blocktype := @value[0] if @value; $!blocktype }
method lexical(*@value) { $!lexical := @value[0] if @value; $!lexical }
method custom_args(*@value) { $!custom_args := @value[0] if @value; $!custom_args }

my $cur_cuid := 0;
my $cuid_suffix := ~nqp::time_n();
Expand Down
53 changes: 29 additions & 24 deletions src/QAST/Compiler.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -269,33 +269,38 @@ class QAST::Compiler is HLL::Compiler {
# Generate parameter handling code.
my $decls := self.post_new('Ops');
my %lex_params;
for $block.params {
my @param := ['.param'];

if $_.scope eq 'local'{
nqp::push(@param, $block.local_type_long($_.name));
nqp::push(@param, $_.name);
}
else {
my $reg := $block.lex_reg($_.name);
nqp::push(@param, $block.lexical_type_long($_.name));
nqp::push(@param, $reg);
%lex_params{$_.name} := $reg;
}

if $_.slurpy {
nqp::push(@param, ':slurpy');
if $_.named {
nqp::push(@param, ':named');
if $node.custom_args {
$decls.push_pirop('.param pmc CALL_SIG :call_sig');
}
else {
for $block.params {
my @param := ['.param'];

if $_.scope eq 'local'{
nqp::push(@param, $block.local_type_long($_.name));
nqp::push(@param, $_.name);
}
else {
my $reg := $block.lex_reg($_.name);
nqp::push(@param, $block.lexical_type_long($_.name));
nqp::push(@param, $reg);
%lex_params{$_.name} := $reg;
}

if $_.slurpy {
nqp::push(@param, ':slurpy');
if $_.named {
nqp::push(@param, ':named');
}
}
elsif $_.named {
nqp::push(@param, ':named(' ~ self.escape($_.named) ~ ')');
}

$decls.push_pirop(pir::join(' ', @param));
}
elsif $_.named {
nqp::push(@param, ':named(' ~ self.escape($_.named) ~ ')');
}

$decls.push_pirop(pir::join(' ', @param));
}

# Generate declarations.
for $block.lexicals {
$decls.push_pirop('.lex ' ~ self.escape($_.name) ~ ', ' ~ $block.lex_reg($_.name));
Expand Down

0 comments on commit 58acfd1

Please sign in to comment.