Skip to content

Commit

Permalink
Only sink if we know about &sink
Browse files Browse the repository at this point in the history
Doesn't quite work it seems.
  • Loading branch information
moritz committed Feb 16, 2012
1 parent 21e7425 commit d17935e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/Perl6/Actions.pm
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,10 @@ class Perl6::Actions is HLL::Actions {
);
}

$mainline := Perl6::Sinker.sink($mainline);
# if &sink isn't in scope, we can't add sink calls either
if $*HAS_SINK {
$mainline := Perl6::Sinker.sink($mainline);
}

# If our caller wants to know the mainline ctx, provide it here.
# (CTXSAVE is inherited from HLL::Actions.) Don't do this when
Expand Down
4 changes: 4 additions & 0 deletions src/Perl6/Grammar.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ grammar Perl6::Grammar is HLL::Grammar {
# XXX Hack: clear any marks.
pir::set_hll_global__vPsP(['HLL', 'Grammar'], '%!MARKHASH', nqp::null());

my $*HAS_SINK;

my $cursor := self.comp_unit;
$*W.pop_lexpad(); # UNIT
$*W.pop_lexpad(); # UNIT_OUTER
Expand Down Expand Up @@ -423,6 +425,7 @@ grammar Perl6::Grammar is HLL::Grammar {
# CHECK time.
:my @*CHECK_PHASERS := [];


# Setting loading and symbol setup.
{
# Create unit outer (where we assemble any lexicals accumulated
Expand All @@ -436,6 +439,7 @@ grammar Perl6::Grammar is HLL::Grammar {
unless pir::defined(%*COMPILING<%?OPTIONS><outer_ctx>) {
$*SETTING := $*W.load_setting(%*COMPILING<%?OPTIONS><setting> // 'CORE');
}
$*HAS_SINK := $*W.is_lexical('&sink');
$/.CURSOR.unitstart();
try {
my $EXPORTHOW := $*W.find_symbol(['EXPORTHOW']);
Expand Down
25 changes: 21 additions & 4 deletions src/Perl6/Sinker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,30 @@ class Perl6::Sinker {

# Called when we encounter a block in the tree.
method visit_block($block) {
self.visit_children($block);
$block.blocktype eq 'declaration'
?? $block
!! self.visit_children($block);
}

method visit_stmts($st) {
my $i := 0;
while $i < +@($st) - 1 {
$st[$i] := self.visit_children($st[$i]);
$i++;
}
$st;
}

# Called when we encounter a PAST::Op in the tree. Produces either
# the op itself or some replacement opcode to put in the tree.
method visit_op($op) {
$op;
if $op.pasttype eq 'call'
|| $op.pasttype eq 'callmethod'
|| !$op.pasttype {
PAST::Op.new(:name('&sink'), $op);
} else {
$op;
}
}

# Handles visiting a PAST::Want node.
Expand All @@ -40,10 +57,10 @@ class Perl6::Sinker {
$node[$i] := self.visit_block($visit);
}
elsif $visit.isa(PAST::Stmts) {
$node[$i] := self.visit_children($visit);
$node[$i] := self.visit_stmts($visit);
}
elsif $visit.isa(PAST::Stmt) {
$node[$i] := self.visit_children($visit);
$node[$i] := self.visit_stmts($visit);
}
elsif $visit.isa(PAST::Want) {
$node[$i] := self.visit_want($visit);
Expand Down
2 changes: 2 additions & 0 deletions src/core/control.pm
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ sub sleep($seconds = $Inf) { # fractional seconds also allowed
return $time2 - $time1;
}

sub sink(|$x) { $x.?sink; Nil }

sub QX($cmd) {
my Mu $pio := pir::open__Pss(nqp::unbox_s($cmd), 'rp');
fail "Unable to execute '$cmd'" unless $pio;
Expand Down

0 comments on commit d17935e

Please sign in to comment.