| v6 documentation | Contained in the v6 distribution. |
v6::perlito - A Perlito front-end for v6.pm
# file: hello_world.pl
use v6-perlito;
"hello, world".say;
$ perl hello_world.pl
The v6::perlito module is a front-end to the Perlito Perl 6 compiler.
- 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.
The Pugs Team <perl6-compiler@perl.org>.
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 2006, 2010 by Flavio Soibelmann Glock and others.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| 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;