Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Perlito5 - js2 - bit shift overflow fix
  • Loading branch information
fglock committed Nov 29, 2012
1 parent 73d6564 commit db3046c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
12 changes: 11 additions & 1 deletion html/perlito5.js
Expand Up @@ -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();
Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions perlito5.pl

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion src5/lib/Perlito5/Javascript2/Emitter.pm
Expand Up @@ -63,7 +63,7 @@ package Perlito5::Javascript2;
'infix:<|>' => ' | ',
'infix:<^>' => ' ^ ',
'infix:<>>>' => ' >>> ',
'infix:<<<>' => ' << ',
# 'infix:<<<>' => ' << ',
);
# these operators always return "bool"
our %op_to_bool = map +($_ => 1), qw(
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src5/lib/Perlito5/Javascript2/Runtime.pm
Expand Up @@ -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();
Expand Down

0 comments on commit db3046c

Please sign in to comment.