Skip to content

Commit

Permalink
Perlito5 - fix Data::Dumper; TODO update; fix perlito5-browser-perl6.pl
Browse files Browse the repository at this point in the history
  • Loading branch information
fglock committed Jun 11, 2015
1 parent 169110f commit 1a7f1d4
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 42 deletions.
18 changes: 13 additions & 5 deletions TODO-perlito5
Expand Up @@ -10,7 +10,7 @@ TODO list for Perlito5

-- Test (implemented as Perlito5::Test)

-- Data::Dumper (implemented as Perlito5::Dumper)
-- Data::Dumper (implemented as Perlito5X::Dumper)

-- create perlito5-specific libs for:
feature.pm
Expand Down Expand Up @@ -305,6 +305,18 @@ TODO list for Perlito5

* Javascript backend

-- DESTROY
Try::Tiny uses DESTROY to implement finally() - and it doesn't execute in js:

$ nodejs perlito5.js -Isrc5/lib -I. -I /usr/local/lib/perl5/site_perl/5.20.0 -e ' use Try::Tiny; try { print "this\n" }; try { die "this" } catch { print "catched\n" } finally { print "done\n" } '
this
catched

$ perl -e ' use Try::Tiny; try { print "this\n" }; try { die "this" } catch { print "catched\n" } finally { print "done\n" } '
this
catched
done

-- constant subroutines
-- prototype mismatch
$ perl -e ' sub X () { 123 } print X, "\n"; eval " sub X { 456 } "; '
Expand All @@ -319,10 +331,6 @@ TODO list for Perlito5
\undef,
];

-- indirect object is confused here, maybe a problem at import() time:
$ node perlito5.js -Isrc5/lib -I. -e ' use Data::Dumper; $v = [20, \$v ]; print Dumper $v '
Warning: Died: Can't call method Dumper on unblessed reference

-- phase order
print x(); # js will try to execute this before the sub declaration
sub x { "ok\n"; }
Expand Down
38 changes: 21 additions & 17 deletions perlito5.pl
Expand Up @@ -3827,7 +3827,7 @@ package Perlito5::Grammar::Use;
# use Perlito5::Grammar::Precedence
# use Perlito5::Grammar
# use strict
my %Perlito_internal_module = ('strict' => 'Perlito5X::strict', 'warnings' => 'Perlito5X::warnings', 'feature' => 'Perlito5X::feature', 'utf8' => 'Perlito5X::utf8', 'bytes' => 'Perlito5X::bytes', 'encoding' => 'Perlito5X::encoding', 'Carp' => 'Perlito5X::Carp', 'Exporter' => 'Perlito5X::Exporter', 'Data::Dumper' => 'Perlito5::Dumper');
my %Perlito_internal_module = ('strict' => 'Perlito5X::strict', 'warnings' => 'Perlito5X::warnings', 'feature' => 'Perlito5X::feature', 'utf8' => 'Perlito5X::utf8', 'bytes' => 'Perlito5X::bytes', 'encoding' => 'Perlito5X::encoding', 'Carp' => 'Perlito5X::Carp', 'Exporter' => 'Perlito5X::Exporter', 'Data::Dumper' => 'Perlito5X::Dumper');
sub Perlito5::Grammar::Use::use_decl {
my $str = $_[0];
my $pos = $_[1];
Expand Down Expand Up @@ -7912,22 +7912,6 @@ sub Perlito5::Rul::NotBefore::set_captures_to_array {
# use Perlito5::Emitter::Token
package main;
package Perlito5::Dumper;
sub Perlito5::Dumper::import {
my $pkg = shift;
my $callpkg = caller(0);
*{$callpkg . '::Dumper'} = \&Dumper;
return
}
sub Perlito5::Dumper::Dumper {
my $seen = {};
my $level = ' ';
my @out;
for my $i (0 .. $#_) {
my $pos = '$VAR' . ($i + 1);
push(@out, $pos . ' = ' . _dumper($_[$i], $level, $seen, $pos) . ';' . chr(10))
}
return join('', @out)
}
sub Perlito5::Dumper::ast_dumper {
my $seen = {};
my $level = '';
Expand Down Expand Up @@ -12154,6 +12138,26 @@ sub Perlito5::Perl5::Runtime::emit_perl5 {
1;
# use Perlito5::Perl5::Runtime
package main;
package Data::Dumper;
# use Perlito5::Dumper
sub Data::Dumper::import {
my $pkg = shift;
my $callpkg = caller(0);
*{$callpkg . '::Dumper'} = \&Dumper;
return
}
sub Data::Dumper::Dumper {
my $seen = {};
my $level = ' ';
my @out;
for my $i (0 .. $#_) {
my $pos = '$VAR' . ($i + 1);
push(@out, $pos . ' = ' . Perlito5::Dumper::_dumper($_[$i], $level, $seen, $pos) . ';' . chr(10))
}
return join('', @out)
}
1;
package main;
package Perlito5::TreeGrammar;
# use Data::Dumper
# use strict
Expand Down
20 changes: 1 addition & 19 deletions src5/lib/Perlito5/Dumper.pm
@@ -1,31 +1,13 @@
package Perlito5::Dumper;

sub import {
my $pkg = shift;
my $callpkg = caller(0);
*{ $callpkg . "::Dumper" } = \&Dumper;
return;
}

sub Dumper {
# old-style Data::Dumper
my $seen = {};
my $level = ' ';
my @out;
for my $i (0 .. $#_) {
my $pos = '$VAR' . ($i + 1);
push @out, "$pos = " . _dumper($_[$i], $level, $seen, $pos) . ";\n";
}
return join('', @out);
}

sub ast_dumper {
my $seen = {};
my $level = '';
my $pos = '[TODO - recursive structure in AST is not supported]';
return _dumper($_[0], $level, $seen, $pos);
}

# Note: this is called from Perlito5X/Dumper.pm
sub _dumper {
my ($obj, $tab, $seen, $pos) = @_;

Expand Down
2 changes: 1 addition & 1 deletion src5/lib/Perlito5/Grammar/Use.pm
Expand Up @@ -14,7 +14,7 @@ my %Perlito_internal_module = (
encoding => 'Perlito5X::encoding',
Carp => 'Perlito5X::Carp',
Exporter => 'Perlito5X::Exporter',
'Data::Dumper' => 'Perlito5::Dumper',
'Data::Dumper' => 'Perlito5X::Dumper',
# vars => 'Perlito5::vars', # this is "hardcoded" in stmt_use()
# constant => 'Perlito5::constant',
);
Expand Down
23 changes: 23 additions & 0 deletions src5/lib/Perlito5X/Dumper.pm
@@ -0,0 +1,23 @@
package Data::Dumper;
use Perlito5::Dumper;

sub import {
my $pkg = shift;
my $callpkg = caller(0);
*{ $callpkg . "::Dumper" } = \&Dumper;
return;
}

sub Dumper {
my $seen = {};
my $level = ' ';
my @out;
for my $i (0 .. $#_) {
my $pos = '$VAR' . ($i + 1);
push @out, "$pos = " . Perlito5::Dumper::_dumper($_[$i], $level, $seen, $pos) . ";\n";
}
return join('', @out);
}

1;

2 changes: 2 additions & 0 deletions src5/util/perlito5-browser-perl6.pl
Expand Up @@ -5,6 +5,8 @@ package Perlito5;
use Perlito5::Compiler;
use Perlito5::Perl6::Emitter;
use Perlito5::Perl6::PrettyPrinter;
use Perlito5::Javascript2::Emitter;
use Perlito5::Javascript2::Runtime;

sub compile_p5_to_p6 {
my $s = shift;
Expand Down

0 comments on commit 1a7f1d4

Please sign in to comment.