fglock / Perlito

"Perlito" Perl programming language compiler
http://fglock.github.io/Perlito/
Other
414 stars 47 forks source link

p5tr should be implemented #24

Closed shlomif closed 9 years ago

shlomif commented 9 years ago

After I replaced the require with a use in that fc-solve branch, I got this:

shlomif@telaviv1:~/Download/unpack/perl/Perlito/Perlito$ perl perlito5.pl -Cjs -I src5/lib/ -I/home/shlomif/progs/freecell/git/fc-solve/cpan/Games-Solitaire-Verify/Games-Solitaire-Verify/lib /home/shlomif/progs/freecell/git/fc-solve/cpan/Games-Solitaire-Verify/Games-Solitaire-Verify/script/expand-solitaire-multi-card-moves > ~/e.js
shlomif@telaviv1:~/Download/unpack/perl/Perlito/Perlito$ node ~/e.js 
/home/shlomif/e.js:2555
                p5tr(p5pkg["File::Spec"]["v_VERSION"], '_', '');
                ^
ReferenceError: p5tr is not defined
    at p5pkg.Scalar::Util.List_ISA (/home/shlomif/e.js:2555:3)
    at /home/shlomif/e.js:2565:4
    at Object.<anonymous> (/home/shlomif/e.js:8436:3)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3
shlomif@telaviv1:~/Download/unpack/perl/Perlito/Perlito$ 

It is written that:

        elsif ($code eq 'p5:tr') {
            # TODO: tr/// not implemented
            $str =  
                 'p5tr(' . $var->emit_javascript3() . ', ' . $regex_args->[0]->emit_javascript3() . ', ' . $regex_args->[1]->emit_javascript3() . ')'
        }

Perhaps you'd like to try to get the code in Games-Solitaire-Verify--for-Perlito--Get-Rid-of-Getopt-Long branch fully functional to avoid the round-trip delays.

fglock commented 9 years ago

commit 269af472860e2b3142681534b61d6c2742b7bb0c has an initial "tr" implementation.

I'm checking out Games-Solitaire-Verify--for-Perlito--Get-Rid-of-Getopt-Long

shlomif commented 9 years ago

@fglock: thanks!

fglock commented 9 years ago

One of the dependencies is generating this AST node:

                bless({
                    'arguments' => [
                        '""',
                        sub { "DUMMY" },
                        'fallback',
                        1,
                    ],
                    'code' => 'use',
                    'mod' => 'overload',
                }, 'Perlito5::AST::Use'),

The anon function is generated at BEGIN time, I'll investigate if there is a workaround.

Devel::StackTrace will probably be a problem as well, I think the Devel modules would only work in perl5-in-C:

                bless({
                    'arguments' => [
                        1.2,
                    ],
                    'code' => 'use',
                    'mod' => 'Devel::StackTrace',
                }, 'Perlito5::AST::Use'),

POSIX and List::Util will also be problematic to convert to JS.

shlomif commented 9 years ago

@fglock : thanks for the update. I should note that my interest in Perlito is so I can convert the Perl 5 code of https://metacpan.org/release/Games-Solitaire-Verify to JavaScript for use online in http://fc-solve.shlomifish.org/js-fc-solve/text/ . I can take a different approach and use http://www.shlomifish.org/microperl-web-repl-v1/repl.html - perl 5 for JS via Emscripten. What is your suggestion for now?

fglock commented 9 years ago

Emscripten is best for your application as-is, because you have XS code, which is loaded indirectly through other modules.

Perlito5 at this stage can only load pure-perl modules. The "Perlito5X" namespace contains modules that are being ported to pure-perl. But Perlito5X is not at a point where you can get arbitrary code and it will "just work".

I'll keep an eye on the problems we've found so far, and keep implementing the missing pieces.

2014-10-29 15:38 GMT+01:00 Shlomi Fish notifications@github.com:

@fglock https://github.com/fglock : thanks for the update. I should note that my interest in Perlito is so I can convert the Perl 5 code of https://metacpan.org/release/Games-Solitaire-Verify to JavaScript for use online in http://fc-solve.shlomifish.org/js-fc-solve/text/ . I can take a different approach and use http://www.shlomifish.org/microperl-web-repl-v1/repl.html - perl 5 for JS via Emscripten. What is your suggestion for now?

— Reply to this email directly or view it on GitHub https://github.com/fglock/Perlito/issues/24#issuecomment-60934607.

shlomif commented 9 years ago

@fglock: thanks for the insights. I think I'll take the Emscripten route now.