Skip to content

Commit

Permalink
Perlito5 - js - fix subscripted constant
Browse files Browse the repository at this point in the history
  • Loading branch information
fglock committed Jun 2, 2014
1 parent f8653da commit dfd91f9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 2 deletions.
3 changes: 3 additions & 0 deletions html/perlito5.js
Expand Up @@ -14511,6 +14511,9 @@ return (p5context([(p5str((p5pkg["Perlito5::Javascript2::LexicalBlock"]["v__"] |
v_self = (List__.shift());
var v_level;
v_level = (List__.shift());
if ( (((p5bool(p5call((v_self || (v_self = new p5HashRef({})))._hash_.p5hget('obj'), "isa", ['Perlito5::AST::Apply'], 0)) && (p5str(p5call((v_self || (v_self = new p5HashRef({})))._hash_.p5hget('obj'), "code", [], 0)) == 'circumfix:<( )>')) && (p5num(p5call((v_self || (v_self = new p5HashRef({})))._hash_.p5hget('obj'), "arguments", [], p5want)._array_) == 1)) && p5bool(p5call((v_self || (v_self = new p5HashRef({})))._hash_.p5hget_hash('obj')._hash_.p5hget_array('arguments')._array_.p5aget(0), "isa", ['Perlito5::AST::Apply'], 0))) ) {
(function () { throw(p5call((v_self || (v_self = new p5HashRef({})))._hash_.p5hget('obj'), "emit_javascript2", [v_level, 'list'], p5want)) })();
};
if ( (p5bool(p5call((v_self || (v_self = new p5HashRef({})))._hash_.p5hget('obj'), "isa", ['Perlito5::AST::Var'], 0)) && (p5str(p5call((v_self || (v_self = new p5HashRef({})))._hash_.p5hget('obj'), "sigil", [], 0)) == '$')) ) {
var v_v;
v_v = (p5call(p5pkg["Perlito5::AST::Var"], "new", p5list_to_a('sigil', '@', 'namespace', p5call((v_self || (v_self = new p5HashRef({})))._hash_.p5hget('obj'), "namespace", [], 1), 'name', p5call((v_self || (v_self = new p5HashRef({})))._hash_.p5hget('obj'), "name", [], 1)), 0));
Expand Down
3 changes: 3 additions & 0 deletions perlito5.pl
Expand Up @@ -9113,6 +9113,9 @@ package Perlito5::AST::Index;
sub Perlito5::AST::Index::emit_javascript2_container {
my $self = shift;
my $level = shift;
if ($self->{'obj'}->isa('Perlito5::AST::Apply') && $self->{'obj'}->code() eq 'circumfix:<( )>' && @{$self->{'obj'}->arguments()} == 1 && $self->{'obj'}->{'arguments'}->[0]->isa('Perlito5::AST::Apply')) {
return $self->{'obj'}->emit_javascript2($level, 'list')
}
if ($self->{'obj'}->isa('Perlito5::AST::Var') && $self->{'obj'}->sigil() eq '$') {
my $v = Perlito5::AST::Var->new('sigil' => '@', 'namespace' => $self->{'obj'}->namespace(), 'name' => $self->{'obj'}->name());
return $v->emit_javascript2($level)
Expand Down
9 changes: 9 additions & 0 deletions src5/lib/Perlito5/Javascript2/Emitter.pm
Expand Up @@ -900,6 +900,15 @@ package Perlito5::AST::Index;
sub emit_javascript2_container {
my $self = shift;
my $level = shift;
if ( $self->{obj}->isa('Perlito5::AST::Apply')
&& $self->{obj}->code eq 'circumfix:<( )>'
&& @{ $self->{obj}->arguments } == 1
&& $self->{obj}->{arguments}[0]->isa('Perlito5::AST::Apply')
)
{
# say Perlito5::Dumper::Dumper $self->{obj};
return $self->{obj}->emit_javascript2($level, 'list');
}
if ( $self->{obj}->isa('Perlito5::AST::Var')
&& $self->{obj}->sigil eq '$'
)
Expand Down
20 changes: 18 additions & 2 deletions t5/01-perlito/250-context.t
Expand Up @@ -7,7 +7,7 @@ sub k { my @x = (8, 9); @x }

sub o { my @x = (8, 9); my @y = (11,12); @x, @y }

print "1..4\n";
print "1..6\n";

my $x = x();
my ($y) = x();
Expand Down Expand Up @@ -39,6 +39,21 @@ $got = "$x [@x]";
print "not " if $expect ne $got;
print "ok 4 - $expect : $got\n";

{
my $x = (x)[0];
my $expect = "4";
my $got = "$x";
print "not " if $expect ne $got;
print "ok 5 - $expect : $got\n";
}
{
my $x = (x)[1];
my $expect = "5";
my $got = "$x";
print "not " if $expect ne $got;
print "ok 6 - $expect : $got\n";
}

# TODO - bug: var declaration inside a list
#
# sub n { my @x = 8, 9; @x }
Expand All @@ -48,6 +63,7 @@ print "ok 4 - $expect : $got\n";
# $expect = "1 [8]";
# $got = "$x [@x]";
# print "not " if $expect ne $got;
# print "ok 5 - $expect : $got\n";
# print "ok 7 - $expect : $got\n";
#


0 comments on commit dfd91f9

Please sign in to comment.