Permalink
Browse files

Perlito5 - fix Javascript exists; add README-perlito5

  • Loading branch information...
1 parent 8b2a08f commit e90bcbe9bcb5139bb2d430a29d66b3ad21c6d4bd @fglock committed Dec 21, 2011
Showing with 19 additions and 3 deletions.
  1. +5 −1 README-perlito5
  2. +5 −1 lib5/Perlito5/Javascript/Emitter.pm
  3. +9 −1 src5/lib/Perlito5/Javascript/Emitter.pm
View
@@ -6,7 +6,11 @@ Running the tests using v8:
find t5/*.t | perl -ne ' print "*** $_"; chomp; print ` perl -Ilib5 perlito5.pl -Cjs $_ > tmp.js && ~/bin/d8 tmp.js ` '
-Compile the compiler to Javascript:
+Compile the compiler to Javascript into perlito5.js:
perl -Ilib5 perlito5.pl -Cjs src5/util/perlito5.pl > perlito5.js
+Running the tests using perlito5.js and v8:
+
+find t5/*.t | perl -ne ' print "*** $_"; chomp; print ` ~/bin/d8 perlito5.js -- -Cjs $_ > x && ~/bin/d8 x ` '
+
@@ -740,7 +740,11 @@ package GLOBAL;
if (($code eq 'exists')) {
((my $arg) = (defined $self->{arguments} ? $self->{arguments} : ($self->{arguments} ||= bless([], 'ARRAY')))->[0]);
if (Main::isa($arg, 'Lookup')) {
- return scalar (('(' . ($arg->obj())->emit_javascript() . ').hasOwnProperty(' . ($arg->index_exp())->emit_javascript() . ')'))
+ ((my $v) = $arg->obj());
+ if ((((Main::isa($v, 'Var') && ($v->sigil() eq chr(36))) && ($v->name() ne chr(47))))) {
+ ($v = Var->new(('sigil' => chr(37)), ('twigil' => $v->twigil()), ('namespace' => $v->namespace()), ('name' => $v->name())))
+ };
+ return scalar (('(' . $v->emit_javascript() . ').hasOwnProperty(' . ($arg->index_exp())->emit_javascript() . ')'))
};
if (((Main::isa($arg, 'Call') && ($arg->method() eq 'postcircumfix:<' . chr(123) . ' ' . chr(125) . '>')))) {
return scalar (('(' . $arg->invocant()->emit_javascript() . ').hasOwnProperty(' . $arg->arguments()->emit_javascript() . ')'))
@@ -721,7 +721,15 @@ class Apply {
if $code eq 'exists' {
my $arg = @.arguments[0];
if $arg->isa( 'Lookup' ) {
- return '(' . ($arg->obj)->emit_javascript() . ').hasOwnProperty(' . ($arg->index_exp)->emit_javascript() . ')';
+ my $v = $arg->obj;
+ if ( $v->isa('Var')
+ && $v->sigil eq '$'
+ && $v->name ne '/' # XXX $/ is the Perl6 match object
+ )
+ {
+ $v = Var->new( sigil => '%', twigil => $v->twigil, namespace => $v->namespace, name => $v->name );
+ }
+ return '(' . $v->emit_javascript() . ').hasOwnProperty(' . ($arg->index_exp)->emit_javascript() . ')';
}
if ( $arg->isa( 'Call' ) && $arg->method eq 'postcircumfix:<{ }>' ) {
return '(' . $arg->invocant->emit_javascript() . ').hasOwnProperty(' . $arg->arguments->emit_javascript() . ')';

0 comments on commit e90bcbe

Please sign in to comment.