Skip to content
This repository
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 327 lines (321 sloc) 13.795 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
# Do not edit this file - Generated by Perlito6 9.0
use v5;
use utf8;
use strict;
use warnings;
no warnings ('redefine', 'once', 'void', 'uninitialized', 'misc', 'recursion');
use Perlito6::Perl5::Runtime;
use Perlito6::Perl5::Prelude;
our $MATCH = Perlito6::Match->new();
{
package GLOBAL;
    sub new { shift; bless { @_ }, "GLOBAL" }

    # use v6
;
    {
    package Main;
        sub new { shift; bless { @_ }, "Main" }
        use Perlito6::Emitter::Token;
        use Perlito6::Expression;
        use Perlito6::Go::Emitter;
        use Perlito6::Grammar::Control;
        use Perlito6::Grammar::Regex;
        use Perlito6::Grammar;
        use Perlito6::Java::Emitter;
        use Perlito6::Javascript::Emitter;
        use Perlito6::Lisp::Emitter;
        use Perlito6::Macro;
        use Perlito6::Parrot::Emitter;
        use Perlito6::Perl5::Emitter;
        use Perlito6::Precedence;
        use Perlito6::Python::Emitter;
        use Perlito6::Ruby::Emitter;
        use Perlito6::Runtime;
        ((my $_V6_COMPILER_NAME) = 'Perlito6');
        ((my $_V6_COMPILER_VERSION) = '9.0');
        ((my $source) = '');
        ((my $backend) = '');
        ((my $execute) = 0);
        ((my $verbose) = 0);
        ((my $comp_units) = do {
    (my $List_a = bless [], 'ARRAY');
    (my $List_v = bless [], 'ARRAY');
    $List_a
});
        ((my $perl6lib) = '.' . chr(47) . 'src6' . chr(47) . 'lib');
        ((my $expand_use) = 1);
        if ($verbose) {
            warn((chr(47) . chr(47) . ' Perlito Perl6 compiler'));
            warn((chr(47) . chr(47) . ' ARGS: '), Main::perl((\@ARGV), ))
        };
        (my $Hash_module_seen = bless {}, 'HASH');
        sub module_name {
            my $grammar = $_[0];
            my $str = $_[1];
            my $pos = $_[2];
            (my $MATCH);
            ($MATCH = Perlito6::Match->new(('str' => $str), ('from' => $pos), ('to' => $pos), ('bool' => 1)));
            (($MATCH)->{bool} = ((do {
    ((my $pos1) = $MATCH->to());
    (do {
    ((do {
    ((my $m2) = Perlito6::Grammar->ident($str, $MATCH->to()));
    if ($m2) {
        (($MATCH)->{to} = $m2->to());
        ($MATCH->{'Perlito6::Grammar.ident'} = $m2);
        1
    }
    else {
        0
    }
}) && (do {
    ((my $pos1) = $MATCH->to());
    ((do {
    ((((('::' eq substr($str, $MATCH->to(), 2)) && ((($MATCH)->{to} = (2 + $MATCH->to()))))) && (do {
    ((my $m2) = $grammar->module_name($str, $MATCH->to()));
    if ($m2) {
        (($MATCH)->{to} = $m2->to());
        ($MATCH->{'module_name'} = $m2);
        1
    }
    else {
        0
    }
})) && (((do {
    ($MATCH->{capture} = (do {
    (my $List_a = bless [], 'ARRAY');
    (my $List_v = bless [], 'ARRAY');
    push( @{$List_a}, "".($MATCH->{'Perlito6::Grammar.ident'}) );
    ($List_v = ((${$MATCH->{'module_name'}})));
    for my $x ( @{(bless [0 .. ((scalar( @{$List_v} ) - 1))], 'ARRAY')} ) {
        push( @{$List_a}, $List_v->[$x] )
    };
    $List_a
}))
}) || 1)))
}) || (do {
    (($MATCH)->{to} = $pos1);
    ((1 && (((do {
    ($MATCH->{capture} = (do {
    (my $List_a = bless [], 'ARRAY');
    (my $List_v = bless [], 'ARRAY');
    push( @{$List_a}, "".($MATCH->{'Perlito6::Grammar.ident'}) );
    $List_a
}))
}) || 1))))
}))
}))
})
})));
            $MATCH
        };
        sub modulename_to_filename {
            my $s = $_[0];
            ((my $ident) = Main->module_name($s, 0));
            return scalar (Main::join((${$ident}), (chr(47))))
        };
        sub expand_use {
            my $stmt = $_[0];
            ((my $module_name) = $stmt->mod());
            if (($module_name eq 'v6')) {
                return ()
            };
            if (!(($Hash_module_seen->{$module_name}))) {
                ($Hash_module_seen->{$module_name} = 1);
                if (((($backend eq 'perl5')) || (($backend eq 'ast-perl6')))) {

                }
                else {
                    ((my $filename) = $module_name);
                    ($filename = ($perl6lib . chr(47) . modulename_to_filename($filename) . '.pm'));
                    if (($verbose)) {
                        warn((chr(47) . chr(47) . ' now loading: '), $filename)
                    };
                    ((my $source) = IO::slurp($filename));
                    ((my $m) = Perlito6::Grammar->exp_stmts($source, 0));
                    add_comp_unit(${$m})
                }
            }
        };
        sub add_comp_unit {
            my $List_parse = $_[0];
            for my $comp_unit ( @{$List_parse} ) {
                if (($expand_use && Main::isa($comp_unit, 'Use'))) {
                    expand_use($comp_unit)
                }
                else {
                    if (Main::isa($comp_unit, 'CompUnit')) {
                        if ($verbose) {
                            warn(('parsed comp_unit: ' . chr(39)), $comp_unit->name(), (chr(39)))
                        };
                        for my $stmt ( @{(($comp_unit->body()))} ) {
                            if (($expand_use && Main::isa($stmt, 'Use'))) {
                                expand_use($stmt)
                            }
                        }
                    }
                };
                push( @{$comp_units}, $comp_unit )
            }
        };
        if (((((\@ARGV)->[0] eq '-v')) || (((\@ARGV)->[0] eq '--verbose')))) {
            ($verbose = 1);
            shift( @{(\@ARGV)} )
        };
        if ((substr((\@ARGV)->[0], 0, 2) eq '-C')) {
            ($backend = substr((\@ARGV)->[0], 2, 10));
            ($execute = 0);
            shift( @{(\@ARGV)} );
            if ((((($backend eq 'perl5')) || (($backend eq 'python'))) || (($backend eq 'ruby')))) {
                ($expand_use = 0)
            }
        };
        if ((substr((\@ARGV)->[0], 0, 2) eq '-B')) {
            ($backend = substr((\@ARGV)->[0], 2, 10));
            ($execute = 1);
            shift( @{(\@ARGV)} );
            if ((((($backend eq 'perl5')) || (($backend eq 'python'))) || (($backend eq 'ruby')))) {
                ($expand_use = 0)
            }
        };
        if (((((\@ARGV)->[0] eq '-V')) || (((\@ARGV)->[0] eq '--version')))) {
            ($backend = '');
            Main::say($_V6_COMPILER_NAME, (' '), $_V6_COMPILER_VERSION);
            shift( @{(\@ARGV)} )
        }
        else {
            if ((((((\@ARGV)->[0] eq '-h')) || (((\@ARGV)->[0] eq '--help'))) || (($backend eq '')))) {
                ($backend = '');
                Main::say($_V6_COMPILER_NAME, (' '), $_V6_COMPILER_VERSION, (chr(10) . 'perlito [switches] [programfile]' . chr(10) . ' switches:' . chr(10) . ' -h --help' . chr(10) . ' -v --verbose' . chr(10) . ' -V --version' . chr(10) . ' -Ctarget target backend: go, js, lisp, parrot, perl5, python, ruby, ast-perl6, java' . chr(10) . ' --expand_use --noexpand_use' . chr(10) . ' expand ' . chr(39) . 'use' . chr(39) . ' statements at compile time' . chr(10) . ' -e program one line of program (omit programfile)' . chr(10)));
                shift( @{(\@ARGV)} )
            }
        };
        if (((\@ARGV)->[0] eq '--expand_use')) {
            ($expand_use = 1);
            shift( @{(\@ARGV)} )
        };
        if (((\@ARGV)->[0] eq '--noexpand_use')) {
            ($expand_use = 0);
            shift( @{(\@ARGV)} )
        };
        if (($backend && (\@ARGV))) {
            (my $prelude_filename);
            if (($backend eq 'lisp')) {
                ($prelude_filename = ($perl6lib . chr(47) . 'Perlito6' . chr(47) . 'Lisp' . chr(47) . 'Prelude.pm'))
            };
            if (($backend eq 'js')) {
                ($prelude_filename = ($perl6lib . chr(47) . 'Perlito6' . chr(47) . 'Javascript' . chr(47) . 'Prelude.pm'))
            };
            if (($backend eq 'go')) {
                ($prelude_filename = ($perl6lib . chr(47) . 'Perlito6' . chr(47) . 'Go' . chr(47) . 'Prelude.pm'))
            };
            if ($prelude_filename) {
                if ($verbose) {
                    warn((chr(47) . chr(47) . ' loading lib: '), $prelude_filename)
                };
                ($source = IO::slurp($prelude_filename));
                ((my $m) = Perlito6::Grammar->exp_stmts($source, 0));
                add_comp_unit(${$m})
            };
            if (((\@ARGV)->[0] eq '-e')) {
                shift( @{(\@ARGV)} );
                if ($verbose) {
                    warn((chr(47) . chr(47) . ' source from command line: '), (\@ARGV)->[0])
                };
                ($source = shift( @{(\@ARGV)} ))
            }
            else {
                if ($verbose) {
                    warn((chr(47) . chr(47) . ' source from file: '), (\@ARGV)->[0])
                };
                ($source = IO::slurp(shift( @{(\@ARGV)} )))
            };
            if ($verbose) {
                warn((chr(47) . chr(47) . ' backend: '), $backend);
                warn(('now parsing'))
            };
            ((my $m) = Perlito6::Grammar->exp_stmts($source, 0));
            add_comp_unit(${$m});
            ($comp_units = do {
    (my $List_a = bless [], 'ARRAY');
    (my $List_v = bless [], 'ARRAY');
    push( @{$List_a}, CompUnit->new(('name' => 'GLOBAL'), ('body' => $comp_units)) );
    $List_a
});
            if (($backend eq 'ast-perl6')) {
                Main::say((chr(35) . ' AST dump - do not edit this file - Generated by '), $_V6_COMPILER_NAME, (' '), $_V6_COMPILER_VERSION);
                Main::say(Main::perl($comp_units, ))
            };
            if (($backend eq 'go')) {
                Main::say((chr(47) . chr(47) . ' Do not edit this file - Generated by '), $_V6_COMPILER_NAME, (' '), $_V6_COMPILER_VERSION);
                ((my $filename) = ($perl6lib . chr(47) . 'Perlito6' . chr(47) . 'Go' . chr(47) . 'Runtime.go'));
                if (($verbose)) {
                    warn((chr(47) . chr(47) . ' now loading: '), $filename)
                };
                ((my $source) = IO::slurp($filename));
                Main::say($source);
                Main::say(CompUnit::emit_go_program($comp_units))
            };
            if (($backend eq 'lisp')) {
                Main::say((chr(59) . chr(59) . ' Do not edit this file - Generated by '), $_V6_COMPILER_NAME, (' '), $_V6_COMPILER_VERSION);
                ((my $filename) = ($perl6lib . chr(47) . 'Perlito6' . chr(47) . 'Lisp' . chr(47) . 'Runtime.lisp'));
                if (($verbose)) {
                    warn((chr(47) . chr(47) . ' now loading: '), $filename)
                };
                ((my $source) = IO::slurp($filename));
                Main::say($source);
                Main::say(CompUnit::emit_lisp_program($comp_units));
                Main::say('(compiler-main)');
                Main::say(chr(59) . chr(59) . ' Note: the line below creates a binary executable:');
                Main::say(chr(59) . chr(59) . ' (sb-ext:save-lisp-and-die ' . chr(34) . 'tmp.out' . chr(34) . ' :toplevel ' . chr(39) . 'compiler-main :executable t )')
            };
            if (($backend eq 'perl5')) {
                Main::say((chr(35) . ' Do not edit this file - Generated by '), $_V6_COMPILER_NAME, (' '), $_V6_COMPILER_VERSION);
                Main::print(CompUnit::emit_perl5_program($comp_units))
            };
            if (($backend eq 'js')) {
                Main::say((chr(47) . chr(47) . ' Do not edit this file - Generated by '), $_V6_COMPILER_NAME, (' '), $_V6_COMPILER_VERSION);
                ((my $filename) = ($perl6lib . chr(47) . 'Perlito6' . chr(47) . 'Javascript' . chr(47) . 'Runtime.js'));
                if (($verbose)) {
                    warn((chr(47) . chr(47) . ' now loading: '), $filename)
                };
                ((my $source) = IO::slurp($filename));
                Main::say($source);
                Main::print(CompUnit::emit_javascript_program($comp_units))
            };
            if (($backend eq 'python')) {
                Main::say((chr(35) . ' Do not edit this file - Generated by '), $_V6_COMPILER_NAME, (' '), $_V6_COMPILER_VERSION);
                Main::say((chr(35) . '-*- coding: utf-8 -*-'));
                Main::say('');
                Main::say(('from Perlito6__Python__Runtime import *'));
                Main::say(('from Perlito6__Python__Prelude import *'));
                Main::say(('import __builtin__'));
                Main::say(('__all__ ' . chr(61) . ' []'));
                Main::say('');
                for my $c ( @{(($comp_units))} ) {
                    Main::say($c->emit_python())
                }
            };
            if (($backend eq 'ruby')) {
                Main::say((chr(35) . ' Do not edit this file - Generated by '), $_V6_COMPILER_NAME, (' '), $_V6_COMPILER_VERSION);
                Main::say('');
                Main::say(('require ' . chr(39) . 'Perlito6' . chr(47) . 'Ruby' . chr(47) . 'Runtime.rb' . chr(39)));
                Main::say(('require ' . chr(39) . 'Perlito6__Ruby__Prelude.rb' . chr(39)));
                Main::say('');
                for my $c ( @{(($comp_units))} ) {
                    Main::say($c->emit_ruby())
                }
            };
            if (($backend eq 'parrot')) {
                Main::say((chr(35) . ' Do not edit this file - Generated by '), $_V6_COMPILER_NAME, (' '), $_V6_COMPILER_VERSION);
                for my $c ( @{(($comp_units))} ) {
                    Main::say($c->emit_parrot())
                }
            };
            if (($backend eq 'java')) {
                Main::say((chr(47) . chr(47) . ' Do not edit this file - Generated by '), $_V6_COMPILER_NAME, (' '), $_V6_COMPILER_VERSION);
                Main::print(CompUnit::emit_java_program($comp_units))
            }
        }
    }


}

1;
Something went wrong with that request. Please try again.