Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Perlito5 - js - exists with array index
  • Loading branch information
fglock committed Oct 15, 2013
1 parent 890d83b commit a3b2e64
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 2 deletions.
14 changes: 14 additions & 0 deletions html/perlito5.js
Expand Up @@ -14021,10 +14021,24 @@ return (p5call(p5pkg["Perlito5::AST::Apply"]["v__"], "emit_javascript2_set_list"
(function () { throw(p5context([('(' + p5str(p5call(v_v, "emit_javascript2", [], 0)) + ')._hash_.hasOwnProperty(' + p5str(p5call(p5call(v_arg, "autoquote", p5list_to_a((v_arg || (v_arg = new p5HashRef({})))._hash_.p5hget('index_exp')), 0), "emit_javascript2", [v_level], 0)) + ')')], p5want)) })();
})();
};
if ( p5bool(p5call(v_arg, "isa", ['Perlito5::AST::Index'], 0)) ) {
(function () {
var v_v;
v_v = (p5call(v_arg, "obj", [], 0));
if ( (p5bool(p5call(v_v, "isa", ['Perlito5::AST::Var'], 0)) && (p5str(p5call(v_v, "sigil", [], 0)) == '$')) ) {
v_v = (p5call(p5pkg["Perlito5::AST::Var"], "new", p5list_to_a('sigil', '@', 'namespace', p5call(v_v, "namespace", [], 1), 'name', p5call(v_v, "name", [], 1)), 0));
(function () { throw(p5context([('(' + p5str(p5call(v_v, "emit_javascript2", [], 0)) + ').hasOwnProperty(' + p5str(p5call((v_arg || (v_arg = new p5HashRef({})))._hash_.p5hget('index_exp'), "emit_javascript2", [v_level], 0)) + ')')], p5want)) })();
};
(function () { throw(p5context([('(' + p5str(p5call(v_v, "emit_javascript2", [], 0)) + ')._array_.hasOwnProperty(' + p5str(p5call((v_arg || (v_arg = new p5HashRef({})))._hash_.p5hget('index_exp'), "emit_javascript2", [v_level], 0)) + ')')], p5want)) })();
})();
};
if ( p5bool(p5call(v_arg, "isa", ['Perlito5::AST::Call'], 0)) ) {
if ( (p5str(p5call(v_arg, "method", [], 0)) == 'postcircumfix:<{ }>') ) {
(function () { throw(p5context([('(' + p5str(p5call(p5call(v_arg, "invocant", [], 0), "emit_javascript2", [], 0)) + ')._hash_.hasOwnProperty(' + p5str(p5call(p5call(p5pkg["Perlito5::AST::Lookup"], "autoquote", p5list_to_a((v_arg || (v_arg = new p5HashRef({})))._hash_.p5hget('arguments')), 0), "emit_javascript2", [v_level], 0)) + ')')], p5want)) })();
};
if ( (p5str(p5call(v_arg, "method", [], 0)) == 'postcircumfix:<[ ]>') ) {
(function () { throw(p5context([('(' + p5str(p5call(p5call(v_arg, "invocant", [], 0), "emit_javascript2", [], 0)) + ')._array_.hasOwnProperty(' + p5str(p5call((v_arg || (v_arg = new p5HashRef({})))._hash_.p5hget('arguments'), "emit_javascript2", [v_level], 0)) + ')')], p5want)) })();
};
};
if ( (p5bool(p5call(v_arg, "isa", ['Perlito5::AST::Var'], 0)) && (p5str(p5call(v_arg, "sigil", [], 0)) == '&')) ) {
(function () {
Expand Down
10 changes: 8 additions & 2 deletions html/perlito5to6.html
Expand Up @@ -27,9 +27,15 @@ <h1><a href="http://www.perlito.org">"Perlito" Perl5 to Perl6 Compiler</a></h1>
my @x = qw/ x y z /;
print $x[1], "\n";

for my $x (reverse @x) { say $x }
for my $x ( reverse @x ) { say $x }

for (my $i=0; $i<10; $i++) { say $i }
for ( my $i = 0 ; $i < 10 ; $i++ ) { say $i }

sub mysub {
my $x = shift;
my $y = shift;
$x + $y;
}

</textarea><br/>
<input type="button" value="Execute" onclick="execute()"/>
Expand Down
11 changes: 11 additions & 0 deletions perlito5.pl
Expand Up @@ -9791,10 +9791,21 @@ package Perlito5::AST::Apply;
}
return('(' . $v->emit_javascript2() . ')._hash_.hasOwnProperty(' . $arg->autoquote($arg->{'index_exp'})->emit_javascript2($level) . ')')
}
if ($arg->isa('Perlito5::AST::Index')) {
my $v = $arg->obj();
if ($v->isa('Perlito5::AST::Var') && $v->sigil() eq '$') {
$v = Perlito5::AST::Var->new('sigil' => '@', 'namespace' => $v->namespace(), 'name' => $v->name());
return('(' . $v->emit_javascript2() . ').hasOwnProperty(' . $arg->{'index_exp'}->emit_javascript2($level) . ')')
}
return('(' . $v->emit_javascript2() . ')._array_.hasOwnProperty(' . $arg->{'index_exp'}->emit_javascript2($level) . ')')
}
if ($arg->isa('Perlito5::AST::Call')) {
if ($arg->method() eq 'postcircumfix:<{ }>') {
return('(' . $arg->invocant()->emit_javascript2() . ')._hash_.hasOwnProperty(' . Perlito5::AST::Lookup->autoquote($arg->{'arguments'})->emit_javascript2($level) . ')')
}
if ($arg->method() eq 'postcircumfix:<[ ]>') {
return('(' . $arg->invocant()->emit_javascript2() . ')._array_.hasOwnProperty(' . $arg->{'arguments'}->emit_javascript2($level) . ')')
}
}
if ($arg->isa('Perlito5::AST::Var') && $arg->sigil() eq '&') {
my $name = $arg->{'name'};
Expand Down
14 changes: 14 additions & 0 deletions src5/lib/Perlito5/Javascript2/Emitter.pm
Expand Up @@ -2338,10 +2338,24 @@ package Perlito5::AST::Apply;
}
return '(' . $v->emit_javascript2() . ')._hash_.hasOwnProperty(' . $arg->autoquote($arg->{index_exp})->emit_javascript2($level) . ')';
}
if ($arg->isa( 'Perlito5::AST::Index' )) {
my $v = $arg->obj;
if ( $v->isa('Perlito5::AST::Var')
&& $v->sigil eq '$'
)
{
$v = Perlito5::AST::Var->new( sigil => '@', namespace => $v->namespace, name => $v->name );
return '(' . $v->emit_javascript2() . ').hasOwnProperty(' . $arg->{index_exp}->emit_javascript2($level) . ')';
}
return '(' . $v->emit_javascript2() . ')._array_.hasOwnProperty(' . $arg->{index_exp}->emit_javascript2($level) . ')';
}
if ($arg->isa( 'Perlito5::AST::Call' )) {
if ( $arg->method eq 'postcircumfix:<{ }>' ) {
return '(' . $arg->invocant->emit_javascript2() . ')._hash_.hasOwnProperty(' . Perlito5::AST::Lookup->autoquote($arg->{arguments})->emit_javascript2($level) . ')';
}
if ( $arg->method eq 'postcircumfix:<[ ]>' ) {
return '(' . $arg->invocant->emit_javascript2() . ')._array_.hasOwnProperty(' . $arg->{arguments}->emit_javascript2($level) . ')';
}
}
if ( $arg->isa('Perlito5::AST::Var')
&& $arg->sigil eq '&'
Expand Down

0 comments on commit a3b2e64

Please sign in to comment.