Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 92 lines (80 sloc) 2.259 kb
#! /usr/bin/env perl
use warnings;
use strict;
use 5.010;
BEGIN {
use FindBin;
use File::Spec;
unshift @INC, File::Spec->catdir($FindBin::RealBin, "src");
}
use CompilerDriver ':all';
use Getopt::Long;
use autodie ':all';
my @evaluate;
my $module;
my $stagestats;
my $stopafter;
my $aot;
my $lang = 'CORE';
my $setting;
my $safe;
sub usage {
my ($fh, $ex) = @_;
print $fh <<EOM;
niecza -- a command line wrapper for Niecza
usage: niecza -e 'code' # run a one-liner
OR: niecza file.pl [args] # run a program
OR: niecza -c My::Module # precompile a module
OR: niecza # interactive shell
general options:
-L --language=NAME # select your setting
--setting # precompile target is a setting
-v --stage-stats # detailed timing info
--stop-after=STAGE # stop after STAGE and dump AST
--aot # run ahead-of-time compiler
--safe # disable system interaction, implies -L SAFE
EOM
exit $ex;
}
GetOptions('evaluate|e=s' => \@evaluate, 'aot' => \$aot,
'compile|c' => \$module,
'language|L=s' => \$lang, 'stage-stats|v' => \$stagestats,
'stop-after=s' => \$stopafter, 'safe' => \$safe, 'setting' => \$setting)
or usage(\*STDERR, 1);
my $excl = 0;
$excl++ if @evaluate;
$excl++ if @ARGV;
if ($excl > 1 || $module && !@ARGV || $safe && ($lang ne 'CORE')) {
usage(\*STDERR, 1);
}
$lang = 'SAFE' if $safe;
sub run {
compile(stopafter => $stopafter, aot => $aot,
stagetime => $stagestats, lang => $lang, safe => $safe,
setting => $setting, @_);
system 'mono', CompilerDriver::build_file('MAIN.exe'), @ARGV
if !({@_}->{name}) && !$stopafter;
}
if ($module) {
for (@ARGV) {
run(name => $_);
}
} elsif (@ARGV) {
require File::Slurp;
run(file => shift(@ARGV));
} elsif (@evaluate) {
for (@evaluate) {
run(code => $_);
}
} else {
require Term::ReadLine;
my $term = Term::ReadLine->new('niecza');
while (defined ($_ = $term->readline("> ")) ) {
/^\s*[^\s#]/ or next;
eval {
run(code => "say do $_");
};
say $@ if $@;
$term->addhistory($_) if /\S/;
}
}
Jump to Line
Something went wrong with that request. Please try again.