http://www.perlmonks.org?node_id=1066754


in reply to Re^2: sourcefilter with complete parser?
in thread sourcefilter with complete parser?

Thanks, even if you replied to the wrong person. =)

Please let me point out that 100% translation is always possible if you don't care about performance.

The most brutal force (if this word exists) is done by emulating the CPU of a processor supporting the language.

I'm not interested to emulate or translate more than 80% of a language even if it might be quite easy with some LISP dialects were most of the complicated constructs are just implemented in some core stuff.

Let me give you an example: there is a very subtle difference how JS and Perl numify strings.

Frankly I don't care to support software which relies on such differences. It even throws warnings.

DB<116> use warnings;0+"2" => 2 DB<117> 0+"ss2" => 0 DB<118> 0+"3ss2" => 3 DB<119> use warnings;0+"3ss2" Argument "3ss2" isn't numeric in addition

>>> a="ss2"; 0+parseInt(a) NaN >>> a="3ss2"; 0+parseInt(a) 3

Of course it's possible to wrap every variable in numeric context with a function which numifies the Perl way.

Such a code would be incredibly slow.

But only supporting the "normal" scalar case were strings are to be treated like numbers is far faster.

Just substract zero:

>>> a="2"; 0+a "02" >>> a="2"; 0+a-0 2

My theory is that it's pretty feasible to create a new language which is a subset of Perl5 or Perl6 and creates acceptable JS.

"Acceptable" doesn't mean 100% compatible. Neither different versions of Perl nor JS are ever 100% compatible.

perlito is already quite good at this.

Cheers Rolf

( addicted to the Perl Programming Language)

Replies are listed 'Best First'.
Re^4: sourcefilter with complete parser?
by raiph (Deacon) on Dec 16, 2013 at 19:15 UTC
    My theory is that it's pretty feasible to create a new language which is a subset of Perl5 or Perl6 and creates acceptable JS.

    Have you considered helping Pawel Murias, Jimmy Zhuo, Reini Urban, Zaki Mughal, Tokuhiro Matsuno et al progress the JS backend for NQP? Note that while that project's main goal is to compile Rakudo Perl 6 to JS (which is why the repo is called rakudo-js), the interim goal is to compile the much simpler NQP to JS and (based on comments by pmurias) the project is quite close to achieving this lesser goal.

    Achieving this lesser goal would mean a few things potentially relevant to your quest:

    • There'd be a Perlish lang (NQP -- not quite a small subset of P6) that targets JS (in addition to PIR/Parrot, Java/JVM, and MoarVM).
    • There'd be a Perlish toolkit (also called NQP) for easily creating langs, dialects, and compilers that automatically target JS (and NQP's other backends).
    • Anything you did to improve JS codegen would be leveraged by all langs/compilers in the NQP ecosystem (NQP itself, P6, phpish, rubyish, yourlang, et al).

      I'm was considering now...

      But B::Deparse has my priority and each time I looked into perlito it resulted into mail dialogs with Flavio.

      I need a projects which keep me entertained and B::Deparse is fun ... and last time I talked to Reini in Kiev he wasn't too fond about porting to JS.

      But you might help me with your expertise:

      Do you know any Perl6 on Perl5 implementation?

      Or at least a P6-parser in P5 and/or a consistent language specification?

      UPDATE

      Or s/Perl6/NQP/ for last three questions.

      Cheers Rolf

      ( addicted to the Perl Programming Language)

        last time I talked to Reini in Kiev he wasn't too fond about porting to JS.

        Was he specifically talking of the JS backend work for NQP or just the notion of (targeting) JS in general?

        Anyhoo, I suggest you speak to Pawel Murias. He's playing in the same space as you (perlish langs, parsing, compiling, generating JS). You can leave a message for him on the IRC freenode channel #perl6 with something like "preflex: tell pmurias Perl 6 rules".

        Do you know any Perl6 on Perl5 implementation? Or at least a P6-parser in P5?

        Larry Wall's viv?

        a consistent language specification?

        There's specs aka "Perl 6 specification documents". These specs are the most up to date, complete, and self-consistent human language documents we have that are part of specifying Perl 6.

        The executable "roast" test suite for testing any P6 implementation, and Rakudo's executable P6 Grammar and Actions, can also be considered effective specification.

        Or s/Perl6/NQP/ for last three questions.

        In the same way that a P6 is effectively specified by code such as its grammar/actions and test suite, so NQP is effectively specified by its code such as its test suite and Grammar and Actions.

        HTAAOF :)