v6::perlito - A Perlito front-end for v6.pm


v6 documentation Contained in the v6 distribution.

Index


Code Index:

NAME

Top

v6::perlito - A Perlito front-end for v6.pm

SYNOPSIS

Top

    # file: hello_world.pl
    use v6-perlito;
    "hello, world".say;

    $ perl hello_world.pl

DESCRIPTION

Top

The v6::perlito module is a front-end to the Perlito Perl 6 compiler.

REQUIREMENTS

Top

- The source file header must be valid perl5 and perl6 code.

This is a valid header:

    #!/usr/bin/perl
    use v6-perlito;

* it executes perl5

* perl5 will call the v6.pm module.

This is an invalid header:

    #!/usr/bin/pugs
    use v6;

* it tells perl5 to execute /usr/bin/pugs.

* it tells perl5 that Perl v6.0.0 required.

AUTHORS

Top

The Pugs Team <perl6-compiler@perl.org>.

SEE ALSO

Top

The Perl 6 homepage at http://dev.perl.org/perl6.

- the Perl 6 Synopsis: http://dev.perl.org/perl6/doc/synopsis.html.

The Pugs homepage at http://pugscode.org/.

The Parrot homepage at http://www.parrotcode.org.

COPYRIGHT

Top


v6 documentation Contained in the v6 distribution.

package v6::perlito;
use Filter::Util::Call;
use strict;

sub compile {
    my $source = $_[0];
    return $source if $source =~ /^\s*$/;
    $::_V6_COMPILER_NAME    = 'Perlito';
    $::_V6_COMPILER_VERSION = '7.0';
    require Perlito::Perl5::Emitter;
    require Perlito::Grammar;
    require Perlito::Grammar::Regex;
    require Perlito::Emitter::Token;
    require Perlito::Macro;
    my @comp_unit;
    my $pos = 0;
    my $p = Perlito::Grammar->exp_stmts( $source, $pos );
    if (!$p || length($source) > $p->to) {
        warn "<$source>\n";
        die "Syntax error at pos ", $p->to, "\n";
    }
    push @comp_unit,
        CompUnit->new(
            name => 'GLOBAL',
            body => $$p,
        );
    # Don't write when we failed to compile, otherwise it never recompiles!
    die "Syntax error" unless @comp_unit;
    my $result;
    $result .=  "# Do not edit this file - Generated by $::_V6_COMPILER_NAME $::_V6_COMPILER_VERSION\n";
    $result .= CompUnit::emit_perl5_program( \@comp_unit );
    return $result;
}

sub import {
    filter_add(
        sub {
            my $status;
            if (($status = filter_read_exact(1e9)) > 0) {
                $_ = compile($_);
            }
            $status;
        })
}

1;