Permalink
Browse files

Perlito5 - js2 - bit shift overflow fix

  • Loading branch information...
fglock committed Nov 29, 2012
1 parent 73d6564 commit db3046c4b2e872ac7dbee9e5a9d675df8fc6aa00
Showing with 25 additions and 4 deletions.
  1. +11 −1 html/perlito5.js
  2. +5 −2 perlito5.pl
  3. +5 −1 src5/lib/Perlito5/Javascript2/Emitter.pm
  4. +4 −0 src5/lib/Perlito5/Javascript2/Runtime.pm
View
@@ -527,6 +527,10 @@ p5decr = function(o) {
return p5num(o) - 1;
};
+p5shift_left = function(o, k) {
+ return k < 31 ? o << k : o * Math.pow(2, k);
+};
+
p5and = function(a, fb) {
if (p5bool(a)) {
return fb();
@@ -2295,7 +2299,7 @@ var p5100 = p5pkg['main'];
// our p5pkg["Perlito5::Javascript2"]["Hash_op_infix_js_str"]
(p5pkg["Perlito5::Javascript2"]["Hash_op_infix_js_str"] = {'infix:<eq>' : ' == ', 'infix:<ne>' : ' != ', 'infix:<le>' : ' <= ', 'infix:<ge>' : ' >= ', 'infix:<lt>' : ' < ', 'infix:<gt>' : ' > '});
// our p5pkg["Perlito5::Javascript2"]["Hash_op_infix_js_num"]
- (p5pkg["Perlito5::Javascript2"]["Hash_op_infix_js_num"] = {'infix:<==>' : ' == ', 'infix:<!=>' : ' != ', 'infix:<+>' : ' + ', 'infix:<->' : ' - ', 'infix:<*>' : ' * ', 'infix:</>' : ' / ', 'infix:<%>' : ' % ', 'infix:<>>' : ' > ', 'infix:<<>' : ' < ', 'infix:<>=>' : ' >= ', 'infix:<<=>' : ' <= ', 'infix:<&>' : ' & ', 'infix:<|>' : ' | ', 'infix:<^>' : ' ^ ', 'infix:<>>>' : ' >>> ', 'infix:<<<>' : ' << '});
+ (p5pkg["Perlito5::Javascript2"]["Hash_op_infix_js_num"] = {'infix:<==>' : ' == ', 'infix:<!=>' : ' != ', 'infix:<+>' : ' + ', 'infix:<->' : ' - ', 'infix:<*>' : ' * ', 'infix:</>' : ' / ', 'infix:<%>' : ' % ', 'infix:<>>' : ' > ', 'infix:<<>' : ' < ', 'infix:<>=>' : ' >= ', 'infix:<<=>' : ' <= ', 'infix:<&>' : ' & ', 'infix:<|>' : ' | ', 'infix:<^>' : ' ^ ', 'infix:<>>>' : ' >>> '});
// our p5pkg["Perlito5::Javascript2"]["Hash_op_to_bool"]
(p5pkg["Perlito5::Javascript2"]["Hash_op_to_bool"] = p5a_to_h(p5list_to_a(p5map(p5pkg["Perlito5::Javascript2"], function (p5want) {
return ((p5context([p5pkg["Perlito5::Javascript2"]["v__"], 1], p5want)));
@@ -3622,6 +3626,12 @@ var p5100 = p5pkg['main'];
(v_self = (List__.p5aget(0)));
return (p5context([('Math.pow(' + p5pkg["Perlito5::AST::Apply"].join([', ', p5list_to_a(p5map(p5pkg["Perlito5::AST::Apply"], function (p5want) {
return (p5pkg["Perlito5::Javascript2"].to_num([p5pkg["Perlito5::AST::Apply"]["v__"]], p5want));
+}, p5list_to_a((v_self || (v_self = new p5HashRef({})))._hash_.p5hget_array('arguments')._array_)))], 0) + ')')], p5want));
+ }, 'infix:<<<>', function (List__, p5want) {
+ var v_self;
+ (v_self = (List__.p5aget(0)));
+ return (p5context([('p5shift_left(' + p5pkg["Perlito5::AST::Apply"].join([', ', p5list_to_a(p5map(p5pkg["Perlito5::AST::Apply"], function (p5want) {
+ return (p5pkg["Perlito5::Javascript2"].to_num([p5pkg["Perlito5::AST::Apply"]["v__"]], p5want));
}, p5list_to_a((v_self || (v_self = new p5HashRef({})))._hash_.p5hget_array('arguments')._array_)))], 0) + ')')], p5want));
}, 'prefix:<!>', function (List__, p5want) {
var v_self;
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -63,7 +63,7 @@ package Perlito5::Javascript2;
'infix:<|>' => ' | ',
'infix:<^>' => ' ^ ',
'infix:<>>>' => ' >>> ',
- 'infix:<<<>' => ' << ',
+ # 'infix:<<<>' => ' << ',
);
# these operators always return "bool"
our %op_to_bool = map +($_ => 1), qw(
@@ -1388,6 +1388,10 @@ package Perlito5::AST::Apply;
my $self = $_[0];
'Math.pow(' . join( ', ', map( Perlito5::Javascript2::to_num($_), @{ $self->{arguments} } ) ) . ')';
},
+ 'infix:<<<>' => sub {
+ my $self = $_[0];
+ 'p5shift_left(' . join( ', ', map( Perlito5::Javascript2::to_num($_), @{ $self->{arguments} } ) ) . ')';
+ },
'prefix:<!>' => sub {
my $self = shift;
my $level = shift;
@@ -533,6 +533,10 @@ p5decr = function(o) {
return p5num(o) - 1;
};
+p5shift_left = function(o, k) {
+ return k < 31 ? o << k : o * Math.pow(2, k);
+};
+
p5and = function(a, fb) {
if (p5bool(a)) {
return fb();

0 comments on commit db3046c

Please sign in to comment.