# Do not edit this file - Generated by Perlito 7.0
use v5;
use utf8;
use strict;
use warnings;
no warnings ('redefine', 'once', 'void', 'uninitialized', 'misc', 'recursion');
use Perlito::Perl5::Runtime;
use Perlito::Perl5::Prelude;
our $MATCH = Perlito::Match->new();
{
package GLOBAL;
sub new { shift; bless { @_ }, "GLOBAL" }

# use v6 
;
{
package Main;
sub new { shift; bless { @_ }, "Main" }
use Perlito::Go::Emitter;
use Perlito::Lisp::Emitter;
use Perlito::Perl5::Emitter;
use Perlito::Javascript::Emitter;
use Perlito::Parrot::Emitter;
use Perlito::Python::Emitter;
use Perlito::Ruby::Emitter;
use Perlito::Grammar;
use Perlito::Grammar::Control;
use Perlito::Grammar::Regex;
use Perlito::Emitter::Token;
use Perlito::Expression;
use Perlito::Precedence;
use Perlito::Macro;
((my  $_V6_COMPILER_NAME = undef) = 'Perlito');
((my  $_V6_COMPILER_VERSION = undef) = '7.0');
((my  $source = undef) = '');
((my  $backend = undef) = '');
((my  $execute = undef) = 0);
((my  $verbose = undef) = 0);
((my  $comp_units = undef) = do { (my  $List_a = []); (my  $List_v = []); $List_a });
((my  $perl6lib = undef) = './lib');
((my  $expand_use = undef) = 1);
if (Main::bool($verbose)) { warn('// Perlito compiler'); warn('// ARGS: ', Main::perl((\@ARGV), )) } ;
(my  $Hash_module_seen = {});
sub module_name { my $grammar = $_[0]; my $str = $_[1]; my $pos = $_[2]; (my  $MATCH = undef); ($MATCH = Perlito::Match->new(('str' => $str), ('from' => $pos), ('to' => $pos), ('bool' => 1))); (($MATCH)->{bool} = ((do { ((my  $pos1 = undef) = $MATCH->to()); (do { ((do { ((my  $m2 = undef) = Perlito::Grammar->ident($str, $MATCH->to())); if (Main::bool($m2)) { (($MATCH)->{to} = $m2->to()); ($MATCH->{'Perlito::Grammar.ident'} = $m2); 1 } else { 0 } }) && (do { ((my  $pos1 = undef) = $MATCH->to()); ((do { ((((('::' eq substr($str, $MATCH->to(), 2)) && ((($MATCH)->{to} = (2 + $MATCH->to()))))) && (do { ((my  $m2 = undef) = $grammar->module_name($str, $MATCH->to())); if (Main::bool($m2)) { (($MATCH)->{to} = $m2->to()); ($MATCH->{'module_name'} = $m2); 1 } else { 0 } })) && (((do { ($MATCH->{capture} = (do { (my  $List_a = []); (my  $List_v = []); push( @{$List_a}, ("" . $MATCH->{'Perlito::Grammar.ident'}) ); ($List_v = ((${$MATCH->{'module_name'}}) || [])); for my $x ( @{[0 .. ((scalar( @{$List_v} ) - 1))] || []} ) { push( @{$List_a}, $List_v->[$x] ) }; $List_a })) }) || 1))) }) || (do { (($MATCH)->{to} = $pos1); ((1 && (((do { ($MATCH->{capture} = (do { (my  $List_a = []); (my  $List_v = []); push( @{$List_a}, ("" . $MATCH->{'Perlito::Grammar.ident'}) ); $List_a })) }) || 1)))) })) })) }) }))); $MATCH };
sub modulename_to_filename { my $s = $_[0]; ((my  $ident = undef) = Main->module_name($s, 0)); return scalar (Main::join((${$ident}), '/')) };
sub add_comp_unit { my $List_parse = $_[0]; for my $comp_unit ( @{$List_parse || []} ) { if (Main::bool(Main::isa($comp_unit, 'CompUnit'))) { if (Main::bool($verbose)) { warn('parsed comp_unit: \'', $comp_unit->name(), '\'') } ; for my $stmt ( @{(($comp_unit->body()) || []) || []} ) { if (Main::bool(($expand_use && Main::isa($stmt, 'Use')))) { ((my  $module_name = undef) = $stmt->mod()); if (Main::bool(!Main::bool(($Hash_module_seen->{$module_name})))) { ($Hash_module_seen->{$module_name} = 1); if (Main::bool(((($backend eq 'perl5')) || (($backend eq 'ast-perl6'))))) {  } else { ((my  $filename = undef) = $module_name); ($filename = $perl6lib . '/' . modulename_to_filename($filename) . '.pm'); if (Main::bool(($verbose))) { warn('// now loading: ', $filename) } ; ((my  $source = undef) = IO::slurp($filename)); ((my  $m = undef) = Perlito::Grammar->exp_stmts($source, 0)); add_comp_unit(${$m}) } }  }  } } ; push( @{$comp_units}, $comp_unit ) } };
if (Main::bool(((((\@ARGV)->[0] eq '-v')) || (((\@ARGV)->[0] eq '--verbose'))))) { ($verbose = 1); shift( @{(\@ARGV)} ) } ;
if (Main::bool((substr((\@ARGV)->[0], 0, 2) eq '-C'))) { ($backend = substr((\@ARGV)->[0], 2, 10)); ($execute = 0); shift( @{(\@ARGV)} ); if (Main::bool((((($backend eq 'perl5')) || (($backend eq 'python'))) || (($backend eq 'ruby'))))) { ($expand_use = 0) }  } ;
if (Main::bool((substr((\@ARGV)->[0], 0, 2) eq '-B'))) { ($backend = substr((\@ARGV)->[0], 2, 10)); ($execute = 1); shift( @{(\@ARGV)} ); if (Main::bool((((($backend eq 'perl5')) || (($backend eq 'python'))) || (($backend eq 'ruby'))))) { ($expand_use = 0) }  } ;
if (Main::bool(((((\@ARGV)->[0] eq '-V')) || (((\@ARGV)->[0] eq '--version'))))) { ($backend = ''); Main::say($_V6_COMPILER_NAME, ' ', $_V6_COMPILER_VERSION); shift( @{(\@ARGV)} ) } else { if (Main::bool((((((\@ARGV)->[0] eq '-h')) || (((\@ARGV)->[0] eq '--help'))) || (($backend eq ''))))) { ($backend = ''); Main::say($_V6_COMPILER_NAME, ' ', $_V6_COMPILER_VERSION, '
perlito [switches] [programfile]
  switches:
    -h --help
    -v --verbose
    -V --version
    -Ctarget        target backend: go, js, lisp, parrot, perl5, python, ruby, ast-perl6
    --expand_use --noexpand_use
                    expand \'use\' statements at compile time
    -e program      one line of program (omit programfile)
'); shift( @{(\@ARGV)} ) }  };
if (Main::bool(((\@ARGV)->[0] eq '--expand_use'))) { ($expand_use = 1); shift( @{(\@ARGV)} ) } ;
if (Main::bool(((\@ARGV)->[0] eq '--noexpand_use'))) { ($expand_use = 0); shift( @{(\@ARGV)} ) } ;
if (Main::bool(($backend && (\@ARGV)))) { (my  $prelude_filename = undef); if (Main::bool(($backend eq 'lisp'))) { ($prelude_filename = $perl6lib . '/Perlito/Lisp/Prelude.pm') } ; if (Main::bool(($backend eq 'js'))) { ($prelude_filename = $perl6lib . '/Perlito/Javascript/Prelude.pm') } ; if (Main::bool(($backend eq 'go'))) { ($prelude_filename = $perl6lib . '/Perlito/Go/Prelude.pm') } ; if (Main::bool($prelude_filename)) { if (Main::bool($verbose)) { warn('// loading lib: ', $prelude_filename) } ; ($source = IO::slurp($prelude_filename)); ((my  $m = undef) = Perlito::Grammar->exp_stmts($source, 0)); add_comp_unit(${$m}) } ; if (Main::bool(((\@ARGV)->[0] eq '-e'))) { shift( @{(\@ARGV)} ); if (Main::bool($verbose)) { warn('// source from command line: ', (\@ARGV)->[0]) } ; ($source = shift( @{(\@ARGV)} )) } else { if (Main::bool($verbose)) { warn('// source from file: ', (\@ARGV)->[0]) } ; ($source = IO::slurp(shift( @{(\@ARGV)} ))) }; if (Main::bool($verbose)) { warn('// backend: ', $backend); warn('now parsing') } ; ((my  $m = undef) = Perlito::Grammar->exp_stmts($source, 0)); add_comp_unit(${$m}); ($comp_units = do { (my  $List_a = []); (my  $List_v = []); push( @{$List_a}, CompUnit->new(('name' => 'GLOBAL'), ('body' => $comp_units)) ); $List_a }); if (Main::bool(($backend eq 'ast-perl6'))) { Main::say('# AST dump - do not edit this file - Generated by ', $_V6_COMPILER_NAME, ' ', $_V6_COMPILER_VERSION); Main::say(Main::perl($comp_units, )) } ; if (Main::bool(($backend eq 'go'))) { Main::say('// Do not edit this file - Generated by ', $_V6_COMPILER_NAME, ' ', $_V6_COMPILER_VERSION); ((my  $filename = undef) = $perl6lib . '/Perlito/Go/Runtime.go'); if (Main::bool(($verbose))) { warn('// now loading: ', $filename) } ; ((my  $source = undef) = IO::slurp($filename)); Main::say($source); Main::say(CompUnit::emit_go_program($comp_units)) } ; if (Main::bool(($backend eq 'lisp'))) { Main::say(';; Do not edit this file - Generated by ', $_V6_COMPILER_NAME, ' ', $_V6_COMPILER_VERSION); ((my  $filename = undef) = $perl6lib . '/Perlito/Lisp/Runtime.lisp'); if (Main::bool(($verbose))) { warn('// now loading: ', $filename) } ; ((my  $source = undef) = IO::slurp($filename)); Main::say($source); Main::say(CompUnit::emit_lisp_program($comp_units)); Main::say('(compiler-main)'); Main::say(';; Note: the line below creates a binary executable:'); Main::say(';; (sb-ext:save-lisp-and-die "tmp.out" :toplevel \'compiler-main :executable t )') } ; if (Main::bool(($backend eq 'perl5'))) { Main::say('# Do not edit this file - Generated by ', $_V6_COMPILER_NAME, ' ', $_V6_COMPILER_VERSION); Main::print(CompUnit::emit_perl5_program($comp_units)) } ; if (Main::bool(($backend eq 'js'))) { Main::say('// Do not edit this file - Generated by ', $_V6_COMPILER_NAME, ' ', $_V6_COMPILER_VERSION); ((my  $filename = undef) = $perl6lib . '/Perlito/Javascript/Runtime.js'); if (Main::bool(($verbose))) { warn('// now loading: ', $filename) } ; ((my  $source = undef) = IO::slurp($filename)); Main::say($source); Main::print(CompUnit::emit_javascript_program($comp_units)) } ; if (Main::bool(($backend eq 'python'))) { Main::say('# Do not edit this file - Generated by ', $_V6_COMPILER_NAME, ' ', $_V6_COMPILER_VERSION); Main::say('#-*- coding: utf-8 -*-'); Main::say(''); Main::say('from Perlito__Python__Runtime import *'); Main::say('from Perlito__Python__Prelude import *'); Main::say('import __builtin__'); Main::say('__all__ = []'); Main::say(''); for my $c ( @{(($comp_units) || []) || []} ) { Main::say($c->emit_python()) } } ; if (Main::bool(($backend eq 'ruby'))) { Main::say('# Do not edit this file - Generated by ', $_V6_COMPILER_NAME, ' ', $_V6_COMPILER_VERSION); Main::say(''); Main::say('require \'Perlito/Ruby/Runtime.rb\''); Main::say(''); for my $c ( @{(($comp_units) || []) || []} ) { Main::say($c->emit_ruby()) } } ; if (Main::bool(($backend eq 'parrot'))) { Main::say('# Do not edit this file - Generated by ', $_V6_COMPILER_NAME, ' ', $_V6_COMPILER_VERSION); for my $c ( @{(($comp_units) || []) || []} ) { Main::say($c->emit_parrot()) } }  } 
}


}

1;
