Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Perlito5 - js - add special case for sort()
  • Loading branch information
fglock committed Sep 11, 2013
1 parent e3356de commit 88f8dd7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
11 changes: 9 additions & 2 deletions html/perlito5.js
Expand Up @@ -13674,8 +13674,15 @@ var p5100 = p5pkg['main'];
(List_in = p5list_to_a((v_self || (v_self = new p5HashRef({})))._hash_.p5hget_array('arguments')._array_));
var v_fun;
var v_list;
if ( (p5str(p5pkg["Perlito5::AST::Apply"].ref([List_in.p5aget(0)], 0)) == 'Perlito5::AST::Lit::Block') ) {
(v_fun = (List_in.shift()));
if ( p5bool((v_self || (v_self = new p5HashRef({})))._hash_.p5hget('special_arg')) ) {
(v_fun = ((v_self || (v_self = new p5HashRef({})))._hash_.p5hget('special_arg')));
}
else {
if ( (p5str(p5pkg["Perlito5::AST::Apply"].ref([List_in.p5aget(0)], 0)) == 'Perlito5::AST::Lit::Block') ) {
(v_fun = (List_in.shift()));
};
};
if ( (p5str(p5pkg["Perlito5::AST::Apply"].ref([v_fun], 0)) == 'Perlito5::AST::Lit::Block') ) {
(v_fun = (('function (p5want) {' + String.fromCharCode(10) + p5str(p5call(p5context([p5call(p5pkg["Perlito5::Javascript2::LexicalBlock"], "new", p5list_to_a('block', (v_fun || (v_fun = new p5HashRef({})))._hash_.p5hget('stmts'), 'needs_return', 1, 'top_level', 0), 0)], 0), "emit_javascript2", [(p5num(v_level) + 1)], 0)) + String.fromCharCode(10) + p5str(p5pkg["Perlito5::Javascript2"].tab([v_level], 0)) + '}')));
}
else {
Expand Down
11 changes: 9 additions & 2 deletions perlito5.pl
Expand Up @@ -9935,8 +9935,15 @@ package Perlito5::AST::Apply;
my @in = @{$self->{'arguments'}};
my $fun;
my $list;
if ((ref($in[0]) eq 'Perlito5::AST::Lit::Block')) {
$fun = shift(@in);
if ($self->{'special_arg'}) {
$fun = $self->{'special_arg'}
}
else {
if ((ref($in[0]) eq 'Perlito5::AST::Lit::Block')) {
$fun = shift(@in)
}
};
if ((ref($fun) eq 'Perlito5::AST::Lit::Block')) {
$fun = ('function (p5want) {' . chr(10) . (Perlito5::Javascript2::LexicalBlock->new('block', $fun->{'stmts'}, 'needs_return', 1, 'top_level', 0))->emit_javascript2(($level + 1)) . chr(10) . Perlito5::Javascript2::tab($level) . '}')
}
else {
Expand Down
14 changes: 12 additions & 2 deletions src5/lib/Perlito5/Javascript2/Emitter.pm
Expand Up @@ -2249,9 +2249,19 @@ package Perlito5::AST::Apply;
my $fun;
my $list;

if (ref($in[0]) eq 'Perlito5::AST::Lit::Block') {
if ( $self->{special_arg} ) {
# TODO - test 'special_arg' type (scalar, block, ...)
$fun = $self->{special_arg};
}
else {
if (ref($in[0]) eq 'Perlito5::AST::Lit::Block') {
# the sort function is optional
$fun = shift @in;
}
}

if (ref($fun) eq 'Perlito5::AST::Lit::Block') {
# the sort function is optional
$fun = shift @in;
$fun =
'function (p5want) {' . "\n"
. (Perlito5::Javascript2::LexicalBlock->new( block => $fun->{stmts}, needs_return => 1, top_level => 0 ))->emit_javascript2( $level + 1 ) . "\n"
Expand Down

0 comments on commit 88f8dd7

Please sign in to comment.