Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
179 lines (162 sloc) 5.49 KB
use MONKEY_TYPING;
use CClass;
use CgOp;
use GetOptLong;
use NieczaActions;
use NieczaBackendDotnet;
use NieczaCompiler;
use NieczaFrontendSTD;
use NieczaPassSimplifier;
use NieczaPathSearch;
use Op;
use Operator;
use OpHelpers;
use OptBeta;
use OptRxSimple;
use RxOp;
use Sig;
use STD;
$GLOBAL::DEBUG_STD = (%*ENV<NIECZA_STD_DEBUG> ?? -1 !! 0);
augment class Any {
submethod new(|) { die "Attempted to instantiate undefined class." }
}
our ($Operator, $Operator_Method, $Operator_Replicate, $Operator_FlipFlop,
$Operator_SmartMatch, $Operator_Comma, $Operator_Binding,
$Operator_ShortCircuit, $Operator_Ternary, $Operator_Temp,
$Operator_DotEq, $Operator_Mixin, $Operator_Let, $Operator_PostCall,
$Operator_Function, $Operator_CompoundAssign); #OK
our ($Op, $OpAttribute, $OpBareBlock, $OpBuiltin, $OpCallLike, $OpCallMethod,
$OpCallSub, $OpCatchyWrapper, $OpCgOp, $OpConditional, $OpConstantDecl,
$OpContextVar, $OpDoOnceLoop, $OpForLoop, $OpGather, $OpGeneralConst,
$OpGeneralLoop, $OpGetBlock, $OpGetSlot, $OpHereStub, $OpImmedForLoop,
$OpIndirectVar, $OpLabelled, $OpLetVar, $OpLexical, $OpMakeCursor, $OpNum,
$OpParen, $OpRegexBody, $OpRequire, $OpShortCircuit, $OpSimplePair,
$OpSimpleParcel, $OpStart, $OpStateDecl, $OpStatementList,
$OpStringLiteral, $OpTemporize, $OpTry, $OpWhatever, $OpWhateverCode,
$OpWhen, $OpWhileLoop, $OpYada, $OpYouAreHere, $OpLexicalBind); #OK
our ($RxOp, $RxOpAlt, $RxOpAny, $RxOpBefore, $RxOpCut, $RxOpConj, $RxOpCutLTM,
$RxOpCutBrack, $RxOpCutRule, $RxOpConfineLang, $RxOpCapturing,
$RxOpCClassElem, $RxOpCheckBlock, $RxOpEndpoint, $RxOpListPrim,
$RxOpNone, $RxOpNotBefore, $RxOpNewline, $RxOpProtoRedis, $RxOpQuantifier,
$RxOpSubrule, $RxOpString, $RxOpSequence, $RxOpSigspace, $RxOpSeqAlt,
$RxOpSaveValue, $RxOpStringCap, $RxOpSym, $RxOpStatement, $RxOpSetLang,
$RxOpTilde, $RxOpVoidBlock, $RxOpVarString, $RxOpZeroWidth,
$RxOpZeroWidthCCs); #OK
our ($Sig, $SigParameter, $PassSimplifier, $CClass, $OptBeta, $Backend,
$CgOp, $OptRxSimple); #OK
our $Actions; $Actions = $Actions but role {
}
my $usage = q:to/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 MyModule # precompile a module
OR: niecza # interactive shell
general options:
-n # short for -L CORN
-p # short for -L CORP
-B --backend=NAME # select backend (dotnet)
-L --language=NAME # select your setting
-I --include=DIR # add a directory to search for modules
-v --verbose # detailed timing info
-c --compile # don't run (implied with -C)
--safe # disable system interaction
--help # display this message
output options:
--obj-dir=DIR # select output location (all)
--no-include-source # disable source-based introspection, etc
EOM
my $runobj = Q:CgOp { (box Str (rawcall get_BaseDirectory (rawscall System.AppDomain.get_CurrentDomain))) };
my $basedir = $runobj.IO.append("..").realpath;
my @lib = $basedir.append("lib"), ".".IO.realpath;
my $lang = "CORE";
my $safe = False;
my $bcnd = "dotnet";
my $odir = Str; # backend auto-detect
my $verb = 0;
my @eval;
my $cmod = False;
my $comp = False;
my $version = False;
my $*no_incl_source = False;
GetOptions(:!permute,
"evaluate|e=s" => sub { push @eval, $_ },
"compile-module|C" => sub { $cmod = True },
"backend|B=s" => sub { $bcnd = $_ },
"language|L=s" => sub { $lang = $_ },
"p" => sub { $lang = "CORP" },
"n" => sub { $lang = "CORN" },
"verbose" => sub { $verb++ },
"version|v" => sub { $version = True },
"compile|c" => sub { $comp = True },
"safe" => sub { $safe = True },
"include|I=s" => sub { unshift @lib, $_.IO.realpath },
"obj-dir=s" => sub { $odir = $_ },
"help|h" => sub { say $usage; exit 0 },
"no-include-source" => sub { $*no_incl_source = True },
);
my @*INC;
if $bcnd eq 'dotnet' || $bcnd eq 'mono' {
$Backend = NieczaBackendDotnet.new(obj_dir => $odir, safemode => $safe);
}
else {
note "Backend '$bcnd' not supported";
exit 1;
}
my $c = NieczaCompiler.new(
module_finder => NieczaPathSearch.new(
path => @lib,
),
frontend => NieczaFrontendSTD.new(
lang => $lang,
safemode => $safe,
),
backend => $Backend,
verbose => $verb,
);
if $version {
$c.compile_string('say "This is Niecza Perl 6 {$?PERL<version>}"', True);
exit 0;
}
if $cmod {
if @eval {
note "Module compilation cannot be used with strings to evaluate";
exit 1;
}
if !@*ARGS {
say "No modules named to compile!";
exit 0;
}
for @*ARGS {
$c.compile_module($_);
}
}
elsif @eval {
$c.backend.run_args = @*ARGS;
for @eval {
$c.compile_string($_, !$comp);
}
}
elsif @*ARGS {
my $file = shift @*ARGS;
$c.backend.run_args = @*ARGS;
$c.compile_file($file, !$comp);
}
else {
my $*repl_outer;
my $*repl_outer_frame;
$c.compile_string('$PROCESS::OUTPUT_USED ::= True', !$comp, :repl,
:evalmode);
while True {
print "niecza> ";
my $l = $*IN.get // last;
my $ok;
try {
$c.compile_string($l, !$comp, :repl, :evalmode,
:outer($*repl_outer), :outer_frame($*repl_outer_frame));
$ok = True;
}
say $! unless $ok;
}
say "";
}
Something went wrong with that request. Please try again.