Skip to content

Commit 58acfd1

Browse files
committed
Add a way to mark a block as having a custom arguments processor, and compile it to a :call_sig usage on Parrot.
1 parent fd47dae commit 58acfd1

File tree

2 files changed

+33
-26
lines changed

2 files changed

+33
-26
lines changed

src/QAST/Block.nqp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
class QAST::Block is QAST::Node {
22
has str $!blocktype;
33
has int $!lexical;
4+
has int $!custom_args;
45
has str $!cuid;
56
has %!symbol;
67

7-
method blocktype(*@value) { $!blocktype := @value[0] if @value; $!blocktype }
8-
method lexical(*@value) { $!lexical := @value[0] if @value; $!lexical }
8+
method blocktype(*@value) { $!blocktype := @value[0] if @value; $!blocktype }
9+
method lexical(*@value) { $!lexical := @value[0] if @value; $!lexical }
10+
method custom_args(*@value) { $!custom_args := @value[0] if @value; $!custom_args }
911

1012
my $cur_cuid := 0;
1113
my $cuid_suffix := ~nqp::time_n();

src/QAST/Compiler.nqp

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -269,33 +269,38 @@ class QAST::Compiler is HLL::Compiler {
269269
# Generate parameter handling code.
270270
my $decls := self.post_new('Ops');
271271
my %lex_params;
272-
for $block.params {
273-
my @param := ['.param'];
274-
275-
if $_.scope eq 'local'{
276-
nqp::push(@param, $block.local_type_long($_.name));
277-
nqp::push(@param, $_.name);
278-
}
279-
else {
280-
my $reg := $block.lex_reg($_.name);
281-
nqp::push(@param, $block.lexical_type_long($_.name));
282-
nqp::push(@param, $reg);
283-
%lex_params{$_.name} := $reg;
284-
}
285-
286-
if $_.slurpy {
287-
nqp::push(@param, ':slurpy');
288-
if $_.named {
289-
nqp::push(@param, ':named');
272+
if $node.custom_args {
273+
$decls.push_pirop('.param pmc CALL_SIG :call_sig');
274+
}
275+
else {
276+
for $block.params {
277+
my @param := ['.param'];
278+
279+
if $_.scope eq 'local'{
280+
nqp::push(@param, $block.local_type_long($_.name));
281+
nqp::push(@param, $_.name);
290282
}
283+
else {
284+
my $reg := $block.lex_reg($_.name);
285+
nqp::push(@param, $block.lexical_type_long($_.name));
286+
nqp::push(@param, $reg);
287+
%lex_params{$_.name} := $reg;
288+
}
289+
290+
if $_.slurpy {
291+
nqp::push(@param, ':slurpy');
292+
if $_.named {
293+
nqp::push(@param, ':named');
294+
}
295+
}
296+
elsif $_.named {
297+
nqp::push(@param, ':named(' ~ self.escape($_.named) ~ ')');
298+
}
299+
300+
$decls.push_pirop(pir::join(' ', @param));
291301
}
292-
elsif $_.named {
293-
nqp::push(@param, ':named(' ~ self.escape($_.named) ~ ')');
294-
}
295-
296-
$decls.push_pirop(pir::join(' ', @param));
297302
}
298-
303+
299304
# Generate declarations.
300305
for $block.lexicals {
301306
$decls.push_pirop('.lex ' ~ self.escape($_.name) ~ ', ' ~ $block.lex_reg($_.name));

0 commit comments

Comments
 (0)