#!/usr/bin/perl use warnings; use strict; use FindBin; use File::Spec; use lib File::Spec->catdir($FindBin::Bin, "lib"); use lib File::Spec->catdir($FindBin::Bin); BEGIN { eval { require Class::Rebless }; if($@) { warn <catfile($FindBin::Bin, @_) } my (@runjs_args, @pugs_args); { while(@ARGV) { my $arg = shift @ARGV; # Ignore -B JS and -BJS if(uc $arg eq "-B") { shift @ARGV; next; } elsif(uc $arg eq "-BJS") { next; } elsif($arg eq "--") { push @pugs_args, splice @ARGV; } elsif($arg =~ /^--/) { # treat all --options as belonging to runjs push @runjs_args, $arg; } else { push @pugs_args, $arg; } } @ARGV = @runjs_args; } GetOptions( "js=s" => \$PIL2JS::cfg{js}, "run=s" => \my $run, "pugs=s" => \$PIL2JS::cfg{pugs}, "pil2js=s" => \$PIL2JS::cfg{pil2js}, "p6preludepc=s" => \$PIL2JS::cfg{preludepc}, "p6prelude=s" => \$PIL2JS::cfg{prelude}, "testpc=s" => \$PIL2JS::cfg{testpc}, "metamodel-base=s" => \$PIL2JS::cfg{metamodel_base}, "perl5" => \$PIL2JS::cfg{perl5}, "compile-only" => \my $compile_only, "precompile-only" => \my $precompile_only, "help" => \&usage, ) and @pugs_args or usage(); unless(-e $PIL2JS::cfg{preludepc} and -s $PIL2JS::cfg{preludepc}) { warn << '.'; *** Precompiled Prelude for JS doesn't exist yet; precompiling... (You can safely ignore the 'useless use of constant' warnings.) . my $js = precomp_module_to_mini_js "-I", PIL2JS::pwd("lib6"), "-MPrelude::JS"; write_file($js => $PIL2JS::cfg{preludepc}); } unless(-e $PIL2JS::cfg{testpc} and -s $PIL2JS::cfg{testpc}) { warn << '.'; *** Precompiled Test.pm for JS doesn't exist yet; precompiling... (You can safely ignore the 'useless use of constant' warnings.) . my $js = precomp_module_to_mini_js "-MTest"; write_file($js => $PIL2JS::cfg{testpc}); } exit if $precompile_only; my $js = jsbin_hack(compile_perl6_to_standalone_js( # "-I" . PIL2JS::pwd("lib6"), # "-MMarkTestPMAsLoaded", # "-e", 'BEGIN { %*INC{"Test.pm"}++ }', @pugs_args )); print($js), exit if $compile_only; $run ||= 'js'; $run = "js_on_$run" if $run ne 'js'; my $go = main->can("run_$run") or die "unknown run mode"; $go->($js); sub write_file { my ($contents, $file) = @_; open my $fh, ">", $file or die "Couldn't open \"$file\" for writing: $!\n"; print $fh $contents or die "Couldn't write to \"$file\": $!\n"; close $fh or die "Couldn't close \"$file\": $!\n"; } sub usage { print STDERR <