Permalink
Browse files

Perlito5 - javascript: placeholder code for ~~ operator

  • Loading branch information...
1 parent c04399a commit f40828269284e3caa95fa77220e314b270024a19 @fglock committed Apr 20, 2012
Showing with 17 additions and 4 deletions.
  1. +3 −1 html/perlito5.js
  2. +2 −1 lib5/Perlito5/Javascript/Emitter.pm
  3. +12 −2 src5/lib/Perlito5/Javascript/Emitter.pm
View
@@ -3211,8 +3211,10 @@ var p5100 = p5pkg['main'];
(v_cond = ((v_self || (v_self = new p5HashRef({})))._hash_['cond']));
var v_body = null;
(v_body = (p5call(p5pkg["Perlito5::Javascript::LexicalBlock"], "new", p5list_to_a('block', p5call((v_self || (v_self = new p5HashRef({})))._hash_['body'], "stmts", [], 1), 'needs_return', 0, 'create_context', 1), 0)));
+ var v_expr = null;
+ (v_expr = (p5call(p5pkg["Perlito5::AST::Apply"], "new", p5list_to_a('code', 'infix:<==>', 'arguments', (new p5ArrayRef(p5list_to_a(p5call(p5pkg["Perlito5::AST::Var"], "new", ['sigil', '$', 'namespace', '', 'name', '_'], 1), v_cond)))), 0)));
var v_s = null;
- (v_s = (('when ( ' + p5str(p5pkg["Perlito5::Javascript"].to_bool([v_cond, (p5num(v_level) + 1)], 0)) + ' ) {' + String.fromCharCode(10) + p5str(p5call(v_body, "emit_javascript", [(p5num(v_level) + 1)], 0)) + String.fromCharCode(10) + p5str(p5pkg["Perlito5::Javascript"].tab([v_level], 0)) + '}')));
+ (v_s = (('if ( ' + p5str(p5pkg["Perlito5::Javascript"].to_bool([v_expr, (p5num(v_level) + 1)], 0)) + ' ) {' + String.fromCharCode(10) + p5str(p5call(v_body, "emit_javascript", [(p5num(v_level) + 1)], 0)) + String.fromCharCode(10) + p5str(p5pkg["Perlito5::Javascript"].tab([v_level], 0)) + '}')));
return (p5context([v_s], p5want));
});
}})();
@@ -1170,7 +1170,8 @@ do { for ($_) {
((my $level) = shift());
((my $cond) = $self->{'cond'});
((my $body) = Perlito5::Javascript::LexicalBlock->new('block', $self->{'body'}->stmts(), 'needs_return', 0, 'create_context', 1));
- ((my $s) = ('when ( ' . Perlito5::Javascript::to_bool($cond, ($level + 1)) . ' ) {' . chr(10) . $body->emit_javascript(($level + 1)) . chr(10) . Perlito5::Javascript::tab($level) . '}'));
+ ((my $expr) = Perlito5::AST::Apply->new('code', 'infix:<==>', 'arguments', [Perlito5::AST::Var->new('sigil', '$', 'namespace', '', 'name', '_'), $cond]));
+ ((my $s) = ('if ( ' . Perlito5::Javascript::to_bool($expr, ($level + 1)) . ' ) {' . chr(10) . $body->emit_javascript(($level + 1)) . chr(10) . Perlito5::Javascript::tab($level) . '}'));
return ($s)
}
}};
@@ -1796,8 +1796,18 @@ package Perlito5::AST::When;
my $body = Perlito5::Javascript::LexicalBlock->new( block => $self->{body}->stmts, needs_return => 0, create_context => 1 );
# TODO
-
- my $s = 'when ( ' . Perlito5::Javascript::to_bool($cond, $level + 1) . ' ) {' . "\n"
+ # transform EXPR into ($_ ~~ EXPR)
+
+ # this is a placeholder - this is wrong!
+ my $expr = Perlito5::AST::Apply->new(
+ code => 'infix:<==>',
+ arguments => [
+ Perlito5::AST::Var->new( sigil => '$', namespace => '', name => '_' ),
+ $cond
+ ]
+ );
+
+ my $s = 'if ( ' . Perlito5::Javascript::to_bool($expr, $level + 1) . ' ) {' . "\n"
. $body->emit_javascript( $level + 1 ) . "\n"
. Perlito5::Javascript::tab($level) . '}';
return $s;

0 comments on commit f408282

Please sign in to comment.