Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Perlito5 - command line compiler - catch internal errors

  • Loading branch information...
commit faef513f98cf9596aa3b7ec088e882f62a442928 1 parent b371c5d
Flavio S. Glock authored
Showing with 168 additions and 152 deletions.
  1. +72 −64 perlito5.pl
  2. +96 −88 src5/util/perlito5.pl
136 perlito5.pl
View
@@ -12063,79 +12063,87 @@ package Perlito5::Runtime;
}
}
else {
- (%INC = ());
- ($Perlito5::EXPAND_USE = 0);
- (my $m);
- (my $ok);
(do {
- ($m = Perlito5::Grammar->exp_stmts($source, 0));
- ($ok = 1)
- });
- if ((!($ok) || ($m->{'to'} != length($source)))) {
- ((my $error) = ((${'@'} || ((($m->{'to'} != length($source)) && ('Syntax Error near ' . $m->{'to'})))) || 'Unknown error'));
- warn($error);
- exit(255)
- }
- else {
- (my $comp_units);
- if ($expand_use) {
+ (%INC = ());
+ ($Perlito5::EXPAND_USE = 0);
+ (my $m);
(my $ok);
(do {
- ($comp_units = Perlito5::Grammar::Use::add_comp_unit(Perlito5::Match::flat($m)));
+ ($m = Perlito5::Grammar->exp_stmts($source, 0));
($ok = 1)
});
- if (!($ok)) {
- ((my $error) = (${'@'} || 'Unknown error loading a module'));
+ if ((!($ok) || ($m->{'to'} != length($source)))) {
+ ((my $error) = ((${'@'} || ((($m->{'to'} != length($source)) && ('Syntax Error near ' . $m->{'to'})))) || 'Unknown error'));
warn($error);
exit(255)
}
- }
- else {
- ($comp_units = Perlito5::Match::flat($m))
- };
- ($comp_units = [Perlito5::AST::CompUnit->new('name', 'main', 'body', $comp_units)]);
- if (($backend eq 'perl5')) {
- say('# Do not edit this file - Generated by ', $_V5_COMPILER_NAME, ' ', $_V5_COMPILER_VERSION);
- if ($expand_use) {
- print(Perlito5::Perl5::Runtime->emit_perl5())
- };
- print(Perlito5::AST::CompUnit::emit_perl5_program($comp_units))
- };
- if (($backend eq 'perl6')) {
- say('# Do not edit this file - Generated by ', $_V5_COMPILER_NAME, ' ', $_V5_COMPILER_VERSION);
- print(Perlito5::AST::CompUnit::emit_perl6_program($comp_units))
- };
- if (($backend eq 'js')) {
- say('// Do not edit this file - Generated by ', $_V5_COMPILER_NAME, ' ', $_V5_COMPILER_VERSION);
- if ($expand_use) {
- print(Perlito5::Javascript2::Runtime->emit_javascript2());
- print(Perlito5::Javascript2::Array->emit_javascript2());
- print(Perlito5::Javascript2::CORE->emit_javascript2());
- print(Perlito5::Javascript2::IO->emit_javascript2());
- print(Perlito5::Javascript2::Sprintf->emit_javascript2())
- };
- print(Perlito5::AST::CompUnit::emit_javascript2_program($comp_units))
- };
- if (($backend eq 'js3')) {
- say('// Do not edit this file - Generated by ', $_V5_COMPILER_NAME, ' ', $_V5_COMPILER_VERSION);
- if ($expand_use) {
- print(Perlito5::Javascript3::Runtime->emit_javascript3());
- print(Perlito5::Javascript3::CORE->emit_javascript3());
- print(Perlito5::Javascript3::IO->emit_javascript3());
- print(Perlito5::Javascript3::Sprintf->emit_javascript3())
+ else {
+ (my $comp_units);
+ if ($expand_use) {
+ (my $ok);
+ (do {
+ ($comp_units = Perlito5::Grammar::Use::add_comp_unit(Perlito5::Match::flat($m)));
+ ($ok = 1)
+ });
+ if (!($ok)) {
+ ((my $error) = (${'@'} || 'Unknown error loading a module'));
+ warn($error);
+ exit(255)
+ }
+ }
+ else {
+ ($comp_units = Perlito5::Match::flat($m))
+ };
+ ($comp_units = [Perlito5::AST::CompUnit->new('name', 'main', 'body', $comp_units)]);
+ if (($backend eq 'perl5')) {
+ say('# Do not edit this file - Generated by ', $_V5_COMPILER_NAME, ' ', $_V5_COMPILER_VERSION);
+ if ($expand_use) {
+ print(Perlito5::Perl5::Runtime->emit_perl5())
+ };
+ print(Perlito5::AST::CompUnit::emit_perl5_program($comp_units))
+ };
+ if (($backend eq 'perl6')) {
+ say('# Do not edit this file - Generated by ', $_V5_COMPILER_NAME, ' ', $_V5_COMPILER_VERSION);
+ print(Perlito5::AST::CompUnit::emit_perl6_program($comp_units))
+ };
+ if (($backend eq 'js')) {
+ say('// Do not edit this file - Generated by ', $_V5_COMPILER_NAME, ' ', $_V5_COMPILER_VERSION);
+ if ($expand_use) {
+ print(Perlito5::Javascript2::Runtime->emit_javascript2());
+ print(Perlito5::Javascript2::Array->emit_javascript2());
+ print(Perlito5::Javascript2::CORE->emit_javascript2());
+ print(Perlito5::Javascript2::IO->emit_javascript2());
+ print(Perlito5::Javascript2::Sprintf->emit_javascript2())
+ };
+ print(Perlito5::AST::CompUnit::emit_javascript2_program($comp_units))
+ };
+ if (($backend eq 'js3')) {
+ say('// Do not edit this file - Generated by ', $_V5_COMPILER_NAME, ' ', $_V5_COMPILER_VERSION);
+ if ($expand_use) {
+ print(Perlito5::Javascript3::Runtime->emit_javascript3());
+ print(Perlito5::Javascript3::CORE->emit_javascript3());
+ print(Perlito5::Javascript3::IO->emit_javascript3());
+ print(Perlito5::Javascript3::Sprintf->emit_javascript3())
+ };
+ print(Perlito5::AST::CompUnit::emit_javascript3_program($comp_units))
+ };
+ if (($backend eq 'ast-perl5')) {
+ say(Perlito5::Dumper::Dumper($comp_units))
+ }
+ else {
+ if (($backend eq 'ast-pretty')) {
+ (do { my $m = Perlito5::Grammar->exp_stmts( 'use Data::Printer {colored=>1,class=>{expand=>"all",show_methods=>"none"}};p($comp_units);1', 0);my $source; $source .= (defined $_ ? $_->emit_perl5(0, "scalar") : "") . ";\n" for @{ Perlito5::Match::flat($m) }; eval $source;});
+ print(${'@'})
+ }
+ }
};
- print(Perlito5::AST::CompUnit::emit_javascript3_program($comp_units))
- };
- if (($backend eq 'ast-perl5')) {
- say(Perlito5::Dumper::Dumper($comp_units))
- }
- else {
- if (($backend eq 'ast-pretty')) {
- (do { my $m = Perlito5::Grammar->exp_stmts( 'use Data::Printer {colored=>1,class=>{expand=>"all",show_methods=>"none"}};p($comp_units);1', 0);my $source; $source .= (defined $_ ? $_->emit_perl5(0, "scalar") : "") . ";\n" for @{ Perlito5::Match::flat($m) }; eval $source;});
- print(${'@'})
- }
- }
- }
+ (${'@'} = undef())
+ })
+ };
+ if (${'@'}) {
+ ((my $error) = ${'@'});
+ warn($error);
+ exit(255)
}
};
184 src5/util/perlito5.pl
View
@@ -166,104 +166,112 @@ package Perlito;
}
}
else {
- # call the "ahead of time" compiler
-
- # since we are generating code that will run from scratch,
- # we need to start with an empty %INC so that all modules are "used"
- %INC = ();
-
- # partially disable "use"
- $Perlito5::EXPAND_USE = 0;
-
- my $m;
- my $ok;
eval {
- $m = Perlito5::Grammar->exp_stmts($source, 0);
- $ok = 1;
- };
- if ( !$ok
- || $m->{to} != length($source)
- )
- {
- my $error = $@
- || ( $m->{to} != length($source)
- && "Syntax Error near " . $m->{to}
- )
- || "Unknown error";
- warn $error;
- exit(255);
- }
- else {
- my $comp_units;
- if ($expand_use) {
- my $ok;
- eval {
- $comp_units = Perlito5::Grammar::Use::add_comp_unit(Perlito5::Match::flat($m));
- $ok = 1;
- };
- if ( !$ok ) {
- my $error = $@
- || "Unknown error loading a module";
- warn $error;
- exit(255);
- }
+ # call the "ahead of time" compiler
+
+ # since we are generating code that will run from scratch,
+ # we need to start with an empty %INC so that all modules are "used"
+ %INC = ();
+
+ # partially disable "use"
+ $Perlito5::EXPAND_USE = 0;
+
+ my $m;
+ my $ok;
+ eval {
+ $m = Perlito5::Grammar->exp_stmts($source, 0);
+ $ok = 1;
+ };
+ if ( !$ok
+ || $m->{to} != length($source)
+ )
+ {
+ my $error = $@
+ || ( $m->{to} != length($source)
+ && "Syntax Error near " . $m->{to}
+ )
+ || "Unknown error";
+ warn $error;
+ exit(255);
}
else {
- $comp_units = Perlito5::Match::flat($m);
- }
+ my $comp_units;
+ if ($expand_use) {
+ my $ok;
+ eval {
+ $comp_units = Perlito5::Grammar::Use::add_comp_unit(Perlito5::Match::flat($m));
+ $ok = 1;
+ };
+ if ( !$ok ) {
+ my $error = $@
+ || "Unknown error loading a module";
+ warn $error;
+ exit(255);
+ }
+ }
+ else {
+ $comp_units = Perlito5::Match::flat($m);
+ }
- $comp_units = [
- Perlito5::AST::CompUnit->new(
- name => 'main',
- body => $comp_units,
- ),
- ];
-
- if ($backend eq 'perl5') {
- say "# Do not edit this file - Generated by ", $_V5_COMPILER_NAME, " ", $_V5_COMPILER_VERSION;
- if ( $expand_use ) {
- print Perlito5::Perl5::Runtime->emit_perl5();
+ $comp_units = [
+ Perlito5::AST::CompUnit->new(
+ name => 'main',
+ body => $comp_units,
+ ),
+ ];
+
+ if ($backend eq 'perl5') {
+ say "# Do not edit this file - Generated by ", $_V5_COMPILER_NAME, " ", $_V5_COMPILER_VERSION;
+ if ( $expand_use ) {
+ print Perlito5::Perl5::Runtime->emit_perl5();
+ }
+ print Perlito5::AST::CompUnit::emit_perl5_program( $comp_units );
}
- print Perlito5::AST::CompUnit::emit_perl5_program( $comp_units );
- }
- if ($backend eq 'perl6') {
- say "# Do not edit this file - Generated by ", $_V5_COMPILER_NAME, " ", $_V5_COMPILER_VERSION;
- print Perlito5::AST::CompUnit::emit_perl6_program( $comp_units );
- }
- if ($backend eq 'js') {
- say "// Do not edit this file - Generated by ", $_V5_COMPILER_NAME, " ", $_V5_COMPILER_VERSION;
- if ( $expand_use ) {
- print Perlito5::Javascript2::Runtime->emit_javascript2();
- print Perlito5::Javascript2::Array->emit_javascript2();
- print Perlito5::Javascript2::CORE->emit_javascript2();
- print Perlito5::Javascript2::IO->emit_javascript2();
- print Perlito5::Javascript2::Sprintf->emit_javascript2();
+ if ($backend eq 'perl6') {
+ say "# Do not edit this file - Generated by ", $_V5_COMPILER_NAME, " ", $_V5_COMPILER_VERSION;
+ print Perlito5::AST::CompUnit::emit_perl6_program( $comp_units );
}
- print Perlito5::AST::CompUnit::emit_javascript2_program( $comp_units );
- }
- if ($backend eq 'js3') {
- say "// Do not edit this file - Generated by ", $_V5_COMPILER_NAME, " ", $_V5_COMPILER_VERSION;
- if ( $expand_use ) {
- print Perlito5::Javascript3::Runtime->emit_javascript3();
- print Perlito5::Javascript3::CORE->emit_javascript3();
- print Perlito5::Javascript3::IO->emit_javascript3();
- print Perlito5::Javascript3::Sprintf->emit_javascript3();
+ if ($backend eq 'js') {
+ say "// Do not edit this file - Generated by ", $_V5_COMPILER_NAME, " ", $_V5_COMPILER_VERSION;
+ if ( $expand_use ) {
+ print Perlito5::Javascript2::Runtime->emit_javascript2();
+ print Perlito5::Javascript2::Array->emit_javascript2();
+ print Perlito5::Javascript2::CORE->emit_javascript2();
+ print Perlito5::Javascript2::IO->emit_javascript2();
+ print Perlito5::Javascript2::Sprintf->emit_javascript2();
+ }
+ print Perlito5::AST::CompUnit::emit_javascript2_program( $comp_units );
+ }
+ if ($backend eq 'js3') {
+ say "// Do not edit this file - Generated by ", $_V5_COMPILER_NAME, " ", $_V5_COMPILER_VERSION;
+ if ( $expand_use ) {
+ print Perlito5::Javascript3::Runtime->emit_javascript3();
+ print Perlito5::Javascript3::CORE->emit_javascript3();
+ print Perlito5::Javascript3::IO->emit_javascript3();
+ print Perlito5::Javascript3::Sprintf->emit_javascript3();
+ }
+ print Perlito5::AST::CompUnit::emit_javascript3_program( $comp_units );
+ }
+ # if ($backend eq 'java') {
+ # say "// Do not edit this file - Generated by ", $_V5_COMPILER_NAME, " ", $_V5_COMPILER_VERSION;
+ # print Perlito5::AST::CompUnit::emit_java_program( $comp_units );
+ # }
+ if ($backend eq 'ast-perl5') {
+ say Perlito5::Dumper::Dumper( $comp_units );
+ }
+ elsif ($backend eq 'ast-pretty') {
+ eval 'use Data::Printer {colored=>1,class=>{expand=>"all",show_methods=>"none"}};p($comp_units);1';
+ print $@;
}
- print Perlito5::AST::CompUnit::emit_javascript3_program( $comp_units );
- }
- # if ($backend eq 'java') {
- # say "// Do not edit this file - Generated by ", $_V5_COMPILER_NAME, " ", $_V5_COMPILER_VERSION;
- # print Perlito5::AST::CompUnit::emit_java_program( $comp_units );
- # }
- if ($backend eq 'ast-perl5') {
- say Perlito5::Dumper::Dumper( $comp_units );
- }
- elsif ($backend eq 'ast-pretty') {
- eval 'use Data::Printer {colored=>1,class=>{expand=>"all",show_methods=>"none"}};p($comp_units);1';
- print $@;
}
+ $@ = undef;
}
}
+ if ( $@ ) {
+ my $error = $@;
+ warn $error;
+ exit(255);
+ }
}
=pod
Please sign in to comment.
Something went wrong with that request. Please try again.