Skip to content

Commit

Permalink
Perlito5 - javascript: sort() withour block
Browse files Browse the repository at this point in the history
  • Loading branch information
fglock committed Mar 13, 2012
1 parent c5369c7 commit 6818cd3
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 36 deletions.
32 changes: 20 additions & 12 deletions html/perlito5.js
Expand Up @@ -350,13 +350,16 @@ p5grep = function(namespace, func, args) {
p5sort = function(namespace, func, args) {
var a_old = namespace["v_a"];
var b_old = namespace["v_b"];
var out = args.sort(
function(a, b) {
namespace["v_a"] = a;
namespace["v_b"] = b;
return func();
}
);
var out =
func == null
? args.sort()
: args.sort(
function(a, b) {
namespace["v_a"] = a;
namespace["v_b"] = b;
return func();
}
);
namespace["v_a"] = a_old;
namespace["v_b"] = b_old;
return out;
Expand Down Expand Up @@ -2014,16 +2017,21 @@ CORE.prototype = function(List__, data) {
if ( (v_code == 'sort') ) {
(function () {
var v_fun = null;
(v_fun = ((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_[0]);
var v_list = null;
(v_list = ((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_[1]);
if ( (num(((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_) > 1) ) {
(v_fun = ((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_[0]);
(v_list = ((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_[1]);
}
else {
(v_list = ((v_self || (v_self = new HashRef({})))._hash_['arguments'] || ((v_self || (v_self = new HashRef({})))._hash_['arguments'] = new ArrayRef([])))._array_[0]);
};
if ( (NAMESPACE["Perlito5::AST::Apply"].ref([v_fun]) == 'Perlito5::AST::Lit::Block') ) {
(v_fun = (v_fun || (v_fun = new HashRef({})))._hash_['stmts']);
(v_fun = ('function () {' + String.fromCharCode(10) + string(_call_((_call_(NAMESPACE["Perlito5::Javascript::LexicalBlock"], "new", ['block', (v_fun || (v_fun = new HashRef({})))._hash_['stmts'],'needs_return', 1,'top_level', 0])), "emit_javascript_indented", [add(v_level, 1)])) + String.fromCharCode(10) + string(NAMESPACE["Perlito5::Javascript"].tab([v_level])) + '}'));
}
else {
(v_fun = (new ArrayRef(interpolate_array(v_fun))));
(v_fun = 'null');
};
throw(('p5sort(NAMESPACE["' + string(NAMESPACE["Perlito5"].v_PKG_NAME) + '"], ' + 'function () {' + String.fromCharCode(10) + string(_call_((_call_(NAMESPACE["Perlito5::Javascript::LexicalBlock"], "new", ['block', v_fun,'needs_return', 1,'top_level', 0])), "emit_javascript_indented", [add(v_level, 1)])) + String.fromCharCode(10) + string(NAMESPACE["Perlito5::Javascript"].tab([v_level])) + '}, ' + string(_call_(v_list, "emit_javascript", [])) + ')'));
throw(('p5sort(NAMESPACE["' + string(NAMESPACE["Perlito5"].v_PKG_NAME) + '"], ' + string(v_fun) + ', ' + string(_call_(v_list, "emit_javascript", [])) + ')'));
})();
};
if ( (v_code == 'prefix:<$>') ) {
Expand Down
17 changes: 12 additions & 5 deletions lib5/Perlito5/Javascript/Emitter.pm
Expand Up @@ -662,15 +662,22 @@ for ($_) {
return (('p5grep(NAMESPACE["' . $Perlito5::PKG_NAME . '"], ' . 'function () {' . chr(10) . (Perlito5::Javascript::LexicalBlock->new(('block' => $fun), ('needs_return' => 1), ('top_level' => 0)))->emit_javascript_indented(($level + 1)) . chr(10) . Perlito5::Javascript::tab($level) . '}, ' . $list->emit_javascript() . ')'))
};
if (($code eq 'sort')) {
((my $fun) = $self->{'arguments'}->[0]);
((my $list) = $self->{'arguments'}->[1]);
(my $fun);
(my $list);
if ((@{$self->{'arguments'}} > 1)) {
($fun = $self->{'arguments'}->[0]);
($list = $self->{'arguments'}->[1])
}
else {
($list = $self->{'arguments'}->[0])
};
if ((ref($fun) eq 'Perlito5::AST::Lit::Block')) {
($fun = $fun->{'stmts'})
($fun = ('function () {' . chr(10) . (Perlito5::Javascript::LexicalBlock->new(('block' => $fun->{'stmts'}), ('needs_return' => 1), ('top_level' => 0)))->emit_javascript_indented(($level + 1)) . chr(10) . Perlito5::Javascript::tab($level) . '}'))
}
else {
($fun = [$fun])
($fun = 'null')
};
return (('p5sort(NAMESPACE["' . $Perlito5::PKG_NAME . '"], ' . 'function () {' . chr(10) . (Perlito5::Javascript::LexicalBlock->new(('block' => $fun), ('needs_return' => 1), ('top_level' => 0)))->emit_javascript_indented(($level + 1)) . chr(10) . Perlito5::Javascript::tab($level) . '}, ' . $list->emit_javascript() . ')'))
return (('p5sort(NAMESPACE["' . $Perlito5::PKG_NAME . '"], ' . $fun . ', ' . $list->emit_javascript() . ')'))
};
if (($code eq 'prefix:<$>')) {
((my $arg) = $self->{'arguments'}->[0]);
Expand Down

0 comments on commit 6818cd3

Please sign in to comment.