Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Perlito5 - js - code cleanup
  • Loading branch information
fglock committed Sep 11, 2013
1 parent 8a5c833 commit e3356de
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 36 deletions.
30 changes: 15 additions & 15 deletions html/perlito5.js
Expand Up @@ -11972,24 +11972,15 @@ var p5100 = p5pkg['main'];
if ( (((p5bool(p5call(v_last_statement, "isa", ['Perlito5::AST::Apply'], 0)) && (p5str(p5call(v_last_statement, "code", [], 0)) == 'return')) && p5bool((v_self || (v_self = new p5HashRef({})))._hash_.p5hget('top_level'))) && p5bool((v_last_statement || (v_last_statement = new p5HashRef({})))._hash_.p5hget_array('arguments')._array_)) ) {
(v_last_statement = ((v_last_statement || (v_last_statement = new p5HashRef({})))._hash_.p5hget_array('arguments')._array_.p5aget(0)));
};
if ( p5bool(p5call(v_last_statement, "isa", ['Perlito5::AST::Lit::Block'], 0)) ) {
(function () {
var v_body;
(v_body = (p5call(p5pkg["Perlito5::Javascript2::LexicalBlock"], "new", p5list_to_a('block', (v_last_statement || (v_last_statement = new p5HashRef({})))._hash_.p5hget('stmts'), 'needs_return', 1), 0)));
List_str.p5push([('for (var i_ = 0; i_ < 1 ; i_++) {' + String.fromCharCode(10) + p5str(p5call(v_body, "emit_javascript2", [(p5num(v_level) + 1)], 0)) + String.fromCharCode(10) + p5str(p5pkg["Perlito5::Javascript2"].tab([v_level], 0)) + '}')]);
})();
if ( ((((((p5bool(p5call(v_last_statement, "isa", ['Perlito5::AST::For'], 0)) || p5bool(p5call(v_last_statement, "isa", ['Perlito5::AST::While'], 0))) || p5bool(p5call(v_last_statement, "isa", ['Perlito5::AST::If'], 0))) || p5bool(p5call(v_last_statement, "isa", ['Perlito5::AST::Lit::Block'], 0))) || p5bool(p5call(v_last_statement, "isa", ['Perlito5::AST::Use'], 0))) || (p5bool(p5call(v_last_statement, "isa", ['Perlito5::AST::Apply'], 0)) && (p5str(p5call(v_last_statement, "code", [], 0)) == 'goto'))) || (p5bool(p5call(v_last_statement, "isa", ['Perlito5::AST::Apply'], 0)) && (p5str(p5call(v_last_statement, "code", [], 0)) == 'return'))) ) {
List_str.p5push(p5list_to_a(p5call(v_last_statement, "emit_javascript2", [v_level, 'runtime'], 1)));
}
else {
if ( (((((p5bool(p5call(v_last_statement, "isa", ['Perlito5::AST::For'], 0)) || p5bool(p5call(v_last_statement, "isa", ['Perlito5::AST::While'], 0))) || p5bool(p5call(v_last_statement, "isa", ['Perlito5::AST::If'], 0))) || p5bool(p5call(v_last_statement, "isa", ['Perlito5::AST::Use'], 0))) || (p5bool(p5call(v_last_statement, "isa", ['Perlito5::AST::Apply'], 0)) && (p5str(p5call(v_last_statement, "code", [], 0)) == 'goto'))) || (p5bool(p5call(v_last_statement, "isa", ['Perlito5::AST::Apply'], 0)) && (p5str(p5call(v_last_statement, "code", [], 0)) == 'return'))) ) {
List_str.p5push(p5list_to_a(p5call(v_last_statement, "emit_javascript2", [v_level, 'runtime'], 1)));
if ( p5bool(v_has_local) ) {
List_str.p5push([('return p5cleanup_local(local_idx, (' + p5str(p5pkg["Perlito5::Javascript2"].to_runtime_context(p5list_to_a((new p5ArrayRef([v_last_statement])), v_level), 0)) + '));')]);
}
else {
if ( p5bool(v_has_local) ) {
List_str.p5push([('return p5cleanup_local(local_idx, (' + p5str(p5pkg["Perlito5::Javascript2"].to_runtime_context(p5list_to_a((new p5ArrayRef([v_last_statement])), v_level), 0)) + '));')]);
}
else {
List_str.p5push([('return (' + p5str(p5pkg["Perlito5::Javascript2"].to_runtime_context(p5list_to_a((new p5ArrayRef([v_last_statement])), v_level), 0)) + ');')]);
};
List_str.p5push([('return (' + p5str(p5pkg["Perlito5::Javascript2"].to_runtime_context(p5list_to_a((new p5ArrayRef([v_last_statement])), v_level), 0)) + ');')]);
};
};
};
Expand Down Expand Up @@ -12093,6 +12084,15 @@ var p5100 = p5pkg['main'];
(v_self = (List__.shift()));
var v_level;
(v_level = (List__.shift()));
var v_wantarray;
(v_wantarray = (List__.shift()));
var v_body;
if ( (p5str(v_wantarray) == 'runtime') ) {
(v_body = (p5call(p5pkg["Perlito5::Javascript2::LexicalBlock"], "new", p5list_to_a('block', (v_self || (v_self = new p5HashRef({})))._hash_.p5hget('stmts'), 'needs_return', 1), 0)));
}
else {
(v_body = (p5call(p5pkg["Perlito5::Javascript2::LexicalBlock"], "new", p5list_to_a('block', (v_self || (v_self = new p5HashRef({})))._hash_.p5hget('stmts'), 'needs_return', 0, 'top_level', 0), 0)));
};
var v_init;
(v_init = (''));
if ( (p5str((v_self || (v_self = new p5HashRef({})))._hash_.p5hget('name')) == 'INIT') ) {
Expand All @@ -12102,7 +12102,7 @@ var p5100 = p5pkg['main'];
(v_init = ((p5str(p5pkg["Perlito5::Javascript2"].tab([(p5num(v_level) + 2)], 0)) + ('if (' + p5str(v_tmp) + ') { return }; ' + p5str(v_tmp) + ' = 1;' + String.fromCharCode(10)))));
})();
};
return (p5context([('p5for_lex(' + 'function () {' + String.fromCharCode(10) + p5str(v_init) + p5str(p5call(p5context([p5call(p5pkg["Perlito5::Javascript2::LexicalBlock"], "new", p5list_to_a('block', (v_self || (v_self = new p5HashRef({})))._hash_.p5hget('stmts'), 'needs_return', 0, 'top_level', 0), 0)], 0), "emit_javascript2", [(p5num(v_level) + 2)], 0)) + String.fromCharCode(10) + p5str(p5pkg["Perlito5::Javascript2"].tab([(p5num(v_level) + 1)], 0)) + '}, ' + '[0], ' + p5str(p5call(v_self, "emit_javascript2_continue", [v_level], 0)) + ', ' + '"' + p5str(p5or((v_self || (v_self = new p5HashRef({})))._hash_.p5hget('label'), function () { return '' })) + '"' + ')')], p5want));
return (p5context([('p5for_lex(' + 'function () {' + String.fromCharCode(10) + p5str(v_init) + p5str(p5call(v_body, "emit_javascript2", [(p5num(v_level) + 2)], 0)) + String.fromCharCode(10) + p5str(p5pkg["Perlito5::Javascript2"].tab([(p5num(v_level) + 1)], 0)) + '}, ' + '[0], ' + p5str(p5call(v_self, "emit_javascript2_continue", [v_level], 0)) + ', ' + '"' + p5str(p5or((v_self || (v_self = new p5HashRef({})))._hash_.p5hget('label'), function () { return '' })) + '"' + ')')], p5want));
});
p5typeglob_set("Perlito5::AST::Lit::Block", "emit_javascript2_continue", function (List__, p5want) {
try {
Expand Down
26 changes: 14 additions & 12 deletions perlito5.pl
Expand Up @@ -8879,21 +8879,15 @@ package Perlito5::Javascript2::LexicalBlock;
if (((($last_statement->isa('Perlito5::AST::Apply') && ($last_statement->code() eq 'return')) && $self->{'top_level'}) && @{$last_statement->{'arguments'}})) {
$last_statement = $last_statement->{'arguments'}->[0]
};
if ($last_statement->isa('Perlito5::AST::Lit::Block')) {
my $body = Perlito5::Javascript2::LexicalBlock->new('block', $last_statement->{'stmts'}, 'needs_return', 1);
push(@str, ('for (var i_ = 0; i_ < 1 ; i_++) {' . chr(10) . $body->emit_javascript2(($level + 1)) . chr(10) . Perlito5::Javascript2::tab($level) . '}'))
if ((((((($last_statement->isa('Perlito5::AST::For') || $last_statement->isa('Perlito5::AST::While')) || $last_statement->isa('Perlito5::AST::If')) || $last_statement->isa('Perlito5::AST::Lit::Block')) || $last_statement->isa('Perlito5::AST::Use')) || ($last_statement->isa('Perlito5::AST::Apply') && ($last_statement->code() eq 'goto'))) || ($last_statement->isa('Perlito5::AST::Apply') && ($last_statement->code() eq 'return')))) {
push(@str, $last_statement->emit_javascript2($level, 'runtime'))
}
else {
if (((((($last_statement->isa('Perlito5::AST::For') || $last_statement->isa('Perlito5::AST::While')) || $last_statement->isa('Perlito5::AST::If')) || $last_statement->isa('Perlito5::AST::Use')) || ($last_statement->isa('Perlito5::AST::Apply') && ($last_statement->code() eq 'goto'))) || ($last_statement->isa('Perlito5::AST::Apply') && ($last_statement->code() eq 'return')))) {
push(@str, $last_statement->emit_javascript2($level, 'runtime'))
if ($has_local) {
push(@str, ('return p5cleanup_local(local_idx, (' . Perlito5::Javascript2::to_runtime_context([$last_statement], $level) . '));'))
}
else {
if ($has_local) {
push(@str, ('return p5cleanup_local(local_idx, (' . Perlito5::Javascript2::to_runtime_context([$last_statement], $level) . '));'))
}
else {
push(@str, ('return (' . Perlito5::Javascript2::to_runtime_context([$last_statement], $level) . ');'))
}
push(@str, ('return (' . Perlito5::Javascript2::to_runtime_context([$last_statement], $level) . ');'))
}
}
};
Expand Down Expand Up @@ -8969,12 +8963,20 @@ package Perlito5::AST::Lit::Block;
sub Perlito5::AST::Lit::Block::emit_javascript2 {
my $self = shift();
my $level = shift();
my $wantarray = shift();
my $body;
if (($wantarray eq 'runtime')) {
$body = Perlito5::Javascript2::LexicalBlock->new('block', $self->{'stmts'}, 'needs_return', 1)
}
else {
$body = Perlito5::Javascript2::LexicalBlock->new('block', $self->{'stmts'}, 'needs_return', 0, 'top_level', 0)
};
my $init = '';
if (($self->{'name'} eq 'INIT')) {
my $tmp = ('p5pkg.main._tmp' . Perlito5::Javascript2::get_label());
$init = (Perlito5::Javascript2::tab(($level + 2)) . ('if (' . $tmp . ') { return }; ' . $tmp . ' = 1;' . chr(10)))
};
return ('p5for_lex(' . 'function () {' . chr(10) . $init . (Perlito5::Javascript2::LexicalBlock->new('block', $self->{'stmts'}, 'needs_return', 0, 'top_level', 0))->emit_javascript2(($level + 2)) . chr(10) . Perlito5::Javascript2::tab(($level + 1)) . '}, ' . '[0], ' . $self->emit_javascript2_continue($level) . ', ' . '"' . (($self->{'label'} || '')) . '"' . ')')
return ('p5for_lex(' . 'function () {' . chr(10) . $init . $body->emit_javascript2(($level + 2)) . chr(10) . Perlito5::Javascript2::tab(($level + 1)) . '}, ' . '[0], ' . $self->emit_javascript2_continue($level) . ', ' . '"' . (($self->{'label'} || '')) . '"' . ')')
};
sub Perlito5::AST::Lit::Block::emit_javascript2_continue {
my $self = shift();
Expand Down
20 changes: 11 additions & 9 deletions src5/lib/Perlito5/Javascript2/Emitter.pm
Expand Up @@ -573,16 +573,10 @@ package Perlito5::Javascript2::LexicalBlock;
$last_statement = $last_statement->{arguments}[0];
}

if ( $last_statement->isa( 'Perlito5::AST::Lit::Block' ) ) {
my $body = Perlito5::Javascript2::LexicalBlock->new( block => $last_statement->{stmts}, needs_return => 1 );
push @str,
'for (var i_ = 0; i_ < 1 ; i_++) {' . "\n"
. $body->emit_javascript2( $level + 1 ) . "\n"
. Perlito5::Javascript2::tab($level) . '}'
}
elsif ( $last_statement->isa( 'Perlito5::AST::For' )
if ( $last_statement->isa( 'Perlito5::AST::For' )
|| $last_statement->isa( 'Perlito5::AST::While' )
|| $last_statement->isa( 'Perlito5::AST::If' )
|| $last_statement->isa( 'Perlito5::AST::Lit::Block' )
|| $last_statement->isa( 'Perlito5::AST::Use' )
|| $last_statement->isa( 'Perlito5::AST::Apply' ) && $last_statement->code eq 'goto'
|| $last_statement->isa( 'Perlito5::AST::Apply' ) && $last_statement->code eq 'return'
Expand Down Expand Up @@ -722,6 +716,14 @@ package Perlito5::AST::Lit::Block;
sub emit_javascript2 {
my $self = shift;
my $level = shift;
my $wantarray = shift;
my $body;
if ($wantarray eq 'runtime') {
$body = Perlito5::Javascript2::LexicalBlock->new( block => $self->{stmts}, needs_return => 1 );
}
else {
$body = Perlito5::Javascript2::LexicalBlock->new( block => $self->{stmts}, needs_return => 0, top_level => 0 );
}

my $init = "";
if ($self->{name} eq 'INIT') {
Expand All @@ -737,7 +739,7 @@ package Perlito5::AST::Lit::Block;
return 'p5for_lex('
. "function () {\n"
. $init
. (Perlito5::Javascript2::LexicalBlock->new( block => $self->{stmts}, needs_return => 0, top_level => 0 ))->emit_javascript2($level + 2) . "\n"
. $body->emit_javascript2($level + 2) . "\n"
. Perlito5::Javascript2::tab($level + 1) . '}, '
. '[0], '
. $self->emit_javascript2_continue($level) . ', '
Expand Down

0 comments on commit e3356de

Please sign in to comment.