Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 6cd530395f
Fetching contributors…

Cannot retrieve contributors at this time

executable file 100 lines (87 sloc) 2.479 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;
my $genapp;
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 # run a program
OR: niecza -c My::Module # precompile a module
OR: niecza # interactive shell
general options:
-L --language=NAME # select your setting
--gen-app=EXEFILE # make self-contained binary (not with -c)
--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,
'gen-app=s' => \$genapp, '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);
}
if (defined($genapp) && $module) {
usage(\*STDERR, 1);
}
$lang = 'SAFE' if $safe;
sub run {
compile(stopafter => $stopafter, aot => $aot, selfcontained => $genapp,
stagetime => $stagestats, lang => $lang, safe => $safe,
setting => $setting, @_);
system 'mono', CompilerDriver::build_file('MAIN.exe')
if !({@_}->{name}) && !$stopafter && !$genapp;
}
if ($module) {
for (@ARGV) {
run(name => $_);
}
} elsif (@ARGV) {
require File::Slurp;
for (@ARGV) {
run(file => $_);
}
} 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.