Permalink
Browse files

Perlito5 - option -Cast-perl5 also works on node.js

  • Loading branch information...
1 parent 6000e54 commit 1ac95f39c3abcc16ac9d133c5834d79b207206de @fglock committed Apr 3, 2012
Showing with 18 additions and 8 deletions.
  1. +1 −0 ChangeLog
  2. +3 −1 html/perlito5.js
  3. +1 −1 lib5/Perlito5/Dumper.pm
  4. +3 −3 perlito5.pl
  5. +7 −1 src5/lib/Perlito5/Dumper.pm
  6. +3 −2 src5/util/perlito5.pl
View
@@ -10,6 +10,7 @@ Dev 2012-02-29
-- here-docs
-- new Perl5-in-Perl6 backend (experimental)
-- new option -Bjs/-Bperl5
+-- new option -Cast-perl5
-- added option -I
Note: -I./src5/lib is needed to compile the compiler and to run some of the tests
-- runs some tests from the perl5 test suite (pmurias++)
View
@@ -1255,7 +1255,9 @@ var p5100 = NAMESPACE['main'];
}
else {
if ( bool(v_ref) ) {
- throw(p5context([('bless(' + '...' + (', ' + String.fromCharCode(39) + p5str(v_ref) + String.fromCharCode(39) + ')'))], p5want));
+ throw(p5context([('bless({' + String.fromCharCode(10) + p5124.join(['', interpolate_array(p5map(p5124, function (p5want) {
+ return (p5context([(p5str(v_tab1) + (String.fromCharCode(39) + p5str(NAMESPACE["Perlito5::Dumper"]["v__"]) + String.fromCharCode(39) + ' => ') + p5str(p5124.Dumper(interpolate_array((v_obj || (v_obj = new HashRef({})))._hash_[NAMESPACE["Perlito5::Dumper"]["v__"]], (num(v_level) + 1)), 0)) + ',' + String.fromCharCode(10))], p5want));
+}, interpolate_array(p5sort(p5124, null, interpolate_array(p5124.keys([(v_obj)._hash_], 1))))))], 0) + p5str(v_tab) + ('}, ' + String.fromCharCode(39) + p5str(v_ref) + String.fromCharCode(39) + ')'))], p5want));
};
};
};
View
@@ -19,7 +19,7 @@ sub Perlito5::Dumper::Dumper {
}
else {
if ($ref) {
- return (('bless(' . '...' . (', ' . chr(39) . $ref . chr(39) . ')')))
+ return (('bless({' . chr(10) . join('', map(($tab1 . (chr(39) . $_ . chr(39) . ' => ') . Dumper($obj->{$_}, ($level + 1)) . ',' . chr(10)), sort(keys(%{$obj})))) . $tab . ('}, ' . chr(39) . $ref . chr(39) . ')')))
}
}
};
View
@@ -20,6 +20,7 @@ package Perlito;
use Perlito5::Perl6::Emitter;
use Perlito5::Precedence;
use Perlito5::Runtime;
+use Perlito5::Dumper;
((my $_V5_COMPILER_NAME) = 'Perlito5');
((my $_V5_COMPILER_VERSION) = '8.0');
((my $source) = '');
@@ -64,7 +65,7 @@ package Perlito;
else {
if ((((($ARGV[0] eq '-h')) || (($ARGV[0] eq '--help'))) || (($backend eq '')))) {
($backend = '');
- Perlito5::Runtime::say($_V5_COMPILER_NAME, ' ', $_V5_COMPILER_VERSION, chr(10) . 'perlito5 [switches] [programfile]' . chr(10) . ' switches:' . chr(10) . ' -h --help' . chr(10) . ' -v --verbose' . chr(10) . ' -V --version' . chr(10) . ' -Idirectory specify @INC/include directory (several -I' . chr(39) . 's allowed)' . chr(10) . ' -Ctarget target backend: js, perl5, perl6' . chr(10) . ' -Btarget execute using the backend: js' . chr(10) . ' --expand_use --noexpand_use' . chr(10) . ' expand ' . chr(39) . 'use' . chr(39) . ' statements at compile time' . chr(10) . ' -e program one line of program (omit programfile)' . chr(10));
+ Perlito5::Runtime::say($_V5_COMPILER_NAME, ' ', $_V5_COMPILER_VERSION, chr(10) . 'perlito5 [switches] [programfile]' . chr(10) . ' switches:' . chr(10) . ' -h --help' . chr(10) . ' -v --verbose' . chr(10) . ' -V --version' . chr(10) . ' -Idirectory specify @INC/include directory (several -I' . chr(39) . 's allowed)' . chr(10) . ' -Ctarget target backend: js, perl5, perl6' . chr(10) . ' -Cast-perl5 emits a dump of the abstract syntax tree' . chr(10) . ' -Btarget execute using the backend: js' . chr(10) . ' --expand_use --noexpand_use' . chr(10) . ' expand ' . chr(39) . 'use' . chr(39) . ' statements at compile time' . chr(10) . ' -e program one line of program (omit programfile)' . chr(10));
shift(@ARGV)
}
};
@@ -145,8 +146,7 @@ package Perlito;
print(Perlito5::AST::CompUnit::emit_javascript_program($comp_units))
};
if (($backend eq 'ast-perl5')) {
- (do { my $m = Perlito5::Grammar->exp_stmts("do {" . 'use Data::Dumper' . "}", 0);my $source = $m->flat()->[0]->emit_perl5(0, "scalar");eval $source;});
- print(Dumper($comp_units))
+ Perlito5::Runtime::say(Perlito5::Dumper::Dumper($comp_units))
}
else {
if (($backend eq 'ast-pretty')) {
@@ -38,7 +38,13 @@ sub Dumper {
# };
# $@ = '';
- return 'bless(' . "..." . ", '$ref')";
+ # assume it's a blessed HASH
+
+ return "bless({\n"
+ . join( "",
+ map($tab1 . "'$_' => " . Dumper($obj->{$_}, $level+1) . ",\n", sort keys %$obj)
+ )
+ . $tab . "}, '$ref')";
}
return "'$obj'";
View
@@ -18,6 +18,7 @@ package Perlito;
## use Perlito5::Python::Emitter;
## use Perlito5::Ruby::Emitter;
use Perlito5::Runtime;
+use Perlito5::Dumper;
my $_V5_COMPILER_NAME = 'Perlito5';
my $_V5_COMPILER_VERSION = '8.0';
@@ -82,6 +83,7 @@ package Perlito;
-V --version
-Idirectory specify \@INC/include directory (several -I's allowed)
-Ctarget target backend: js, perl5, perl6
+ -Cast-perl5 emits a dump of the abstract syntax tree
-Btarget execute using the backend: js
--expand_use --noexpand_use
expand 'use' statements at compile time
@@ -199,8 +201,7 @@ package Perlito;
# print Perlito5::AST::CompUnit::emit_java_program( $comp_units );
# }
if ($backend eq 'ast-perl5') {
- eval "use Data::Dumper";
- print Dumper( $comp_units );
+ 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';

0 comments on commit 1ac95f3

Please sign in to comment.