Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Mark params in $*BLOCK.
  • Loading branch information
pmurias committed Aug 14, 2014
1 parent 447c6cd commit 003a34a
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/vm/js/QAST/Compiler.nqp
Expand Up @@ -256,7 +256,8 @@ class QAST::CompilerJS does DWIMYNameMangling {
has $!outer; # Outer block's BlockInfo
has @!js_lexicals; # javascript variables we need to declare for the block
has $!tmp; # We use a bunch of TMP{$n} to store intermediate javascript results
has $!ctx; # The object we keep dynamic variables and exception handlers in
has $!ctx; # The object we keep dynamic variables and exception handlers in
has @!params; # the parameters the block takes

method new($qast, $outer) {
my $obj := nqp::create(self);
Expand All @@ -268,6 +269,7 @@ class QAST::CompilerJS does DWIMYNameMangling {
$!qast := $qast;
$!outer := $outer;
@!js_lexicals := nqp::list();
@!params := nqp::list();
$!tmp := 0;
}

Expand All @@ -280,6 +282,10 @@ class QAST::CompilerJS does DWIMYNameMangling {
'TMP'~$!tmp;
}

method add_param($param) {
@!params.push($param);
}

method tmps() {
my @tmps;
my $i := 1;
Expand All @@ -294,6 +300,7 @@ class QAST::CompilerJS does DWIMYNameMangling {
method outer() { $!outer }
method qast() { $!qast }
method ctx(*@value) { $!ctx := @value[0] if @value;$!ctx}
method params() { @!params }
}


Expand Down Expand Up @@ -576,10 +583,16 @@ class QAST::CompilerJS does DWIMYNameMangling {
}
}

method declare_var(QAST::Var $var) {
method declare_var(QAST::Var $node) {
# TODO vars more complex the non-dynamic lexicals
if $var.decl eq 'var' {
$*BLOCK.add_js_lexical(self.mangle_name($var.name));
if $node.decl eq 'var' {
$*BLOCK.add_js_lexical(self.mangle_name($node.name));
} elsif $node.decl eq 'param' {
if $node.scope eq 'local' || $node.scope eq 'lexical' {
$*BLOCK.add_param($node);
} else {
nqp::die("Parameter cannot have scope '{$node.scope}'; use 'local' or 'lexical'");
}
}
}

Expand Down

0 comments on commit 003a34a

Please sign in to comment.