Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Perlito5 - js - use context information when "use" is the last statem…
…ent; reported by Stanislav Poussep
  • Loading branch information
fglock committed Sep 11, 2013
1 parent 3792772 commit 596ae83
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
22 changes: 20 additions & 2 deletions html/perlito5.js
Expand Up @@ -12268,7 +12268,7 @@ var p5100 = p5pkg['main'];
})();
}
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::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'))) ) {
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::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 {
Expand Down Expand Up @@ -14431,12 +14431,30 @@ var p5100 = p5pkg['main'];
var p5164 = p5make_package("Perlito5::AST::Use");
p5for_lex(function () {
p5typeglob_set("Perlito5::AST::Use", "emit_javascript2", function (List__, p5want) {
try {
var v_self;
(v_self = (List__.shift()));
var v_level;
(v_level = (List__.shift()));
var v_wantarray;
(v_wantarray = (List__.shift()));
p5pkg["Perlito5::Grammar::Use"].emit_time_eval([v_self], null);
return (p5context([('// ' + p5str((v_self || (v_self = new p5HashRef({})))._hash_.p5hget('code')) + ' ' + p5str((v_self || (v_self = new p5HashRef({})))._hash_.p5hget('mod')) + String.fromCharCode(10))], p5want));
if ( (p5str(v_wantarray) == 'runtime') ) {
throw(p5context(['p5context([], p5want)'], p5want))
}

else {
throw(p5context([('// ' + p5str((v_self || (v_self = new p5HashRef({})))._hash_.p5hget('code')) + ' ' + p5str((v_self || (v_self = new p5HashRef({})))._hash_.p5hget('mod')) + String.fromCharCode(10))], p5want))
}
}
catch(err) {
if ( err instanceof Error ) {
throw(err);
}
else {
return(err);
}
}
});
}, [0], false, "");
})()
Expand Down
10 changes: 8 additions & 2 deletions perlito5.pl
Expand Up @@ -8893,7 +8893,7 @@ package Perlito5::Javascript2::LexicalBlock;
push(@str, ('for (var i_ = 0; i_ < 1 ; i_++) {' . chr(10) . $body->emit_javascript2(($level + 1)) . chr(10) . Perlito5::Javascript2::tab($level) . '}'))
}
else {
if (((($last_statement->isa('Perlito5::AST::For') || $last_statement->isa('Perlito5::AST::While')) || ($last_statement->isa('Perlito5::AST::Apply') && ($last_statement->code() eq 'goto'))) || ($last_statement->isa('Perlito5::AST::Apply') && ($last_statement->code() eq 'return')))) {
if ((((($last_statement->isa('Perlito5::AST::For') || $last_statement->isa('Perlito5::AST::While')) || $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 {
Expand Down Expand Up @@ -10268,8 +10268,14 @@ package Perlito5::AST::Use;
sub Perlito5::AST::Use::emit_javascript2 {
my $self = shift();
my $level = shift();
my $wantarray = shift();
Perlito5::Grammar::Use::emit_time_eval($self);
('// ' . $self->{'code'} . ' ' . $self->{'mod'} . chr(10))
if (($wantarray eq 'runtime')) {
return 'p5context([], p5want)'
}
else {
return ('// ' . $self->{'code'} . ' ' . $self->{'mod'} . chr(10))
}
}
};

Expand Down
10 changes: 9 additions & 1 deletion src5/lib/Perlito5/Javascript2/Emitter.pm
Expand Up @@ -611,6 +611,7 @@ package Perlito5::Javascript2::LexicalBlock;
}
elsif ( $last_statement->isa( 'Perlito5::AST::For' )
|| $last_statement->isa( 'Perlito5::AST::While' )
|| $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 @@ -2772,8 +2773,15 @@ package Perlito5::AST::Use;
sub emit_javascript2 {
my $self = shift;
my $level = shift;
my $wantarray = shift;
Perlito5::Grammar::Use::emit_time_eval($self);
'// ' . $self->{code} . ' ' . $self->{mod} . "\n"

if ($wantarray eq 'runtime') {
return 'p5context([], p5want)';
}
else {
return '// ' . $self->{code} . ' ' . $self->{mod} . "\n";
}
}
}

Expand Down

0 comments on commit 596ae83

Please sign in to comment.