What's Implemented in Perlesque, What's Not, and The Plan

This post lists the syntax and semantics already implemented in Perlesque, my aforementioned strongly-typed subset of Perl 6 on the CLR.
  • This bears repeating: keep in mind this is a strongly-typed subset of Perl 6; variables may not change type (note: the contents/referents of variables may have a type that is derived from the variable's type).
  • Named labels and the "goto LABEL" statement, and a label can appear *after* the goto, as well.  Control may not jump "down" into another block, though, of course.  I suspect, but I'm not certain, that Perlesque is the first implementation (of a subset of Perl 6) to support this feature, but please correct me if I'm wrong.
  • Control flow blocks: if/elsif/else, while, until, repeat/while, repeat/until, loop (C-style for loop), and the "next" ("continue") and "last" ("break") statements in all of those loops.  The semantics of next and last match neither the Perl 6 spec or the Perl 5 behavior, but they're quite close to the expected behavior.
  • Declaration of lexical variables:  my $scalar_root = initializer_expression();   The type of $scalar_root is inferred from the type of the initializer expression.  One can also declare the type explicitly:  my Tree::Walker $traverser;
  • Declaration of closures as lexical variables: same as the above, but the initializer expression is also a subroutine declaration, either named or anonymous:   my $routine = sub foo(List[int] $integers, str $name --> int) { say($integers.Count ~ (" items in " ~ $name)); return 1 };   This declares a routine that takes two parameters (a List of integers and a string) and returns an integer.  foo(List[int].new(), "hihi") may also be invoked after this statement, or in any lexical scopes enclosed by the lexical scope in which foo was declared.
  • Declaration of named subroutines: same as the above, but without assigning it to a variable.
  • Type literals.  You can use the name of a type as an expression, since on the CLR's CTS (Common Type System), there is a Type type.  This (sort of) maps from the Perl 6 notion of the name of a type representing the type object.
  • Decimal (signed) integer literals, string literals "double quote: \" <-- double quote"  'single quote: \' <-- single quote', and the common numeric operation operators and comparison operators, as well as the bitwise and logical operators (including negation).  The assignment (mutate in-place) editions of the relevant operators are also implemented.
These features enable Perlesque to be a functional programming language and an imperative programming language, similar to Perl 5 and JavaScript (and Perl 6), but strongly typed.

What's missing from Perlesque (that would make it a useful "human-writable" language)?
  • good (well, any appropriate) error messages on parse failures
  • the aforementioned expression parser, so that precedence can be inferred from an operator precedence table, so so many parentheses aren't necessary when typing the code
The Plan for Perlesque:

Recall my plan for Perlesque: an assembly language to which STD.pm6 will compile itself.  TimToady's "viv" program (written in Perl 5, originally stood for VI->V, 6 to 5, though cutely it can also be read as 5 to 4) will take the output of the STD.pm6 parser (TimToady's definitional grammar written in Perl 6), and will emit Perlesque code that is a direct translation of the Perl 6 code in STD.pm6 itself.

It will translate all expressions to trees of calls into the Cursor/Perl6 runtime (written in some combination of Perlesque and C#), and all control statements to their analogous control structures in Perlesque.  Allow me to gloss over the mountain of work it will take to enable this translation and the supporting runtime libraries, but keep in mind that nearly all of that work is also "implementing Perl 6", so it's work that must be done at some point anyway.

The Perlesque translation of STD.pm6 (let's call it STD.psq) will then be compiled by perlesque.exe to CIL (let's call it STD.psq.exe), and executed on a CLR (Mono on Linux, Mac, or Windows, or .NET on Windows, or Silverlight on many platforms in many browsers).  Tada.  Perl 6.  Larry Wall's definitional parser parsing your Perl 6 and executing it directly (after compiling each compilation unit to CIL), including all the fancy multi-stage compilation and phasers (ask on #perl6 if you don't know what these are) and the other parser-entwined features of Perl 6.

1 comment:

  1. This comment has been removed by a blog administrator.