Skip to content

Commit 1291513

Browse files
committed
[js] Move is_dynamic_var to BlockInfo.
1 parent 15805af commit 1291513

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/vm/js/Compiler.nqp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,20 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
201201
method ctx(*@value) { $!ctx := @value[0] if @value;$!ctx}
202202
method params() { @!params }
203203
method variables() { @!variables }
204+
205+
method is_dynamic_var($var) {
206+
# HACK due to a nqp misdesign we need a HACK
207+
# TODO Make nqp mark dynamic variables explicitly
208+
my $name := $var.name;
209+
if nqp::chars($name) > 2 {
210+
my str $sigil := nqp::substr($name, 0, 1);
211+
my str $twigil := nqp::substr($name, 1, 1);
212+
if $twigil eq '*' {
213+
return 1;
214+
}
215+
}
216+
return 0;
217+
}
204218
}
205219

206220
method is_valid_js_identifier($identifier) {
@@ -342,7 +356,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
342356
}
343357

344358
my sub set_variable($var, $value) {
345-
if self.is_dynamic_var($var) {
359+
if $*BLOCK.is_dynamic_var($var) {
346360
@setup.push("{$*CTX}[{quote_string($var.name)}] = $value;\n");
347361
}
348362
else {
@@ -382,7 +396,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
382396

383397
set_variable($_, $value);
384398
}
385-
elsif self.is_dynamic_var($_) {
399+
elsif $*BLOCK.is_dynamic_var($_) {
386400
my $tmp := self.unique_var('param');
387401
@sig.push($tmp);
388402

@@ -1122,7 +1136,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
11221136
if $*BLOCK.lookup_static_variable($var) -> $static {
11231137
$value := self.value_as_js($static.value);
11241138
}
1125-
elsif self.is_dynamic_var($var) {
1139+
elsif $*BLOCK.is_dynamic_var($var) {
11261140
$value := "{$*CTX}.lookup({quote_string($var.name)})";
11271141
}
11281142
else {
@@ -1438,20 +1452,6 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
14381452
self.as_js($node, :$want, :$cps);
14391453
}
14401454

1441-
method is_dynamic_var($var) {
1442-
# HACK due to a nqp misdesign we need a HACK
1443-
# TODO Make nqp mark dynamic variables explicitly
1444-
my $name := $var.name;
1445-
if nqp::chars($name) > 2 {
1446-
my str $sigil := nqp::substr($name, 0, 1);
1447-
my str $twigil := nqp::substr($name, 1, 1);
1448-
if $twigil eq '*' {
1449-
return 1;
1450-
}
1451-
}
1452-
return 0;
1453-
}
1454-
14551455
method atpos($array, $index, :$node) {
14561456
my $array_chunk := self.as_js($array, :want($T_OBJ));
14571457
my $index_chunk := self.as_js($index, :want($T_INT));
@@ -1530,7 +1530,7 @@ class QAST::CompilerJS does DWIMYNameMangling does SerializeOnce {
15301530
self.compile_var_as_js_var($var, :$cps);
15311531
}
15321532
elsif self.var_is_lexicalish($var) {
1533-
if self.is_dynamic_var($var) {
1533+
if $*BLOCK.is_dynamic_var($var) {
15341534
self.compile_var_as_part_of_ctx($var, :$cps);
15351535
}
15361536
else {

0 commit comments

Comments
 (0)