Browse files

A bit more decrufting for NieczaCompiler

  • Loading branch information...
1 parent 51e9a26 commit db7fa59321459649a8c50cea25ab75ce7af0b734 @sorear committed Oct 30, 2011
Showing with 36 additions and 48 deletions.
  1. +0 −9 lib/CodeGen.cs
  2. +6 −6 src/NieczaBackendDotnet.pm6
  3. +16 −13 src/NieczaCompiler.pm6
  4. +4 −5 src/NieczaFrontendSTD.pm6
  5. +3 −3 src/NieczaPathSearch.pm6
  6. +7 −12 src/niecza
View
9 lib/CodeGen.cs
@@ -3286,15 +3286,6 @@ class NamProcessor {
void EnterCode(List<object> frags) {
List<object> latefrags = new List<object>();
- if ((sub.special & SubInfo.MAINLINE) != 0 &&
- sub.unit.is_mainish) {
- FieldInfo fi = cpb.tb.DefineField(
- "RTFRAME", typeof(Frame),
- FieldAttributes.Public | FieldAttributes.Static);
- frags.Add(a(j("_cpsop"),
- CpsOp.SetSField(fi, CpsOp.CallFrame())));
- }
-
// Lexpad setup: XXX should be done *before* entry, indeed
// before the binder, so defaults work right
View
12 src/NieczaBackendDotnet.pm6
@@ -36,7 +36,7 @@ sub upcalled(*@args) {
when "check_dated" {
shift @args;
for @args -> $module, $hash {
- my ($file, $modt, $src) = #OK
+ my ($file, $src) = #OK
$*compiler.module_finder.load_module($module);
my $trueh = gethash($src);
say "check-dated $module: was $hash now $trueh" if $v;
@@ -62,8 +62,10 @@ class StaticSub { ... }
class Type { ... }
method new(*%_) {
+ my $self = callsame;
Q:CgOp { (rnull (rawscall Niecza.Downcaller,CompilerBlob.InitSlave {&upcalled} {Unit} {StaticSub} {Type})) };
- nextsame;
+ downcall("safemode") if $self.safemode;
+ $self;
}
sub downcall(*@args) {
@@ -74,11 +76,9 @@ sub gethash($str) {
Q:CgOp { (box Str (rawscall Niecza.Downcaller,CompilerBlob.DoHash (obj_getstr {$str}))) }
}
-method accept($unitname, $unit, :$main, :$run, :$evalmode, :$repl) { #OK not used
- downcall("safemode") if $.safemode;
+method accept($unit, :$filename, :$run, :$evalmode, :$repl) {
if $run {
- downcall("setnames", $*PROGRAM_NAME // '???',
- $*orig_file // '(eval)') unless $repl;
+ downcall("setnames", $*PROGRAM_NAME // '???', $filename) unless $repl;
downcall("run_unit", $unit, ?$evalmode, @$!run_args);
if $repl {
$*repl_outer_frame = $unit.replrun;
View
29 src/NieczaCompiler.pm6
@@ -1,7 +1,5 @@
class NieczaCompiler;
-use JSYNC;
-
has $.module_finder;
has $.backend;
has $.stages;
@@ -12,21 +10,26 @@ has $!discount-time = 0;
has %.units;
-method !compile($unitname, $filename, $modtime, $source, $main, $run, $end , $evalmode, $outer, $outer_frame, $repl) { #OK
+method !compile(:$unitname, :$filename, :$source, :$main, :$run, :$evalmode, :$outer, :$outer_frame, :$repl) {
# FIXME this is a bit of a fudge
$unitname := 'CORE' if $!frontend.lang eq 'NULL';
+ # send information to NieczaGrammar for creating the root sub
my $*niecza_outer_ref = $outer;
my $*niecza_outer_frame = $outer_frame;
+
+ # useful references
my $*compiler = self;
my $*verbose = $.verbose;
my $*backend = $.backend;
+
+ # tells parser not to exit when parse fails
my $*in_repl = $repl;
my @*INC;
my $start = times[0] - $!discount-time;
- my $ast = $!frontend.parse(:$unitname, :$filename, :$modtime,
+ my $ast = $!frontend.parse(:$unitname, :$filename,
:$source, :$outer, :$main, :$run, :$evalmode, :$repl);
my $time = times[0] - $!discount-time - $start;
@@ -41,22 +44,22 @@ method !compile($unitname, $filename, $modtime, $source, $main, $run, $end , $ev
$ast;
}
-method compile_module($module, $stop = "") {
- my ($filename, $modtime, $source) = $.module_finder.load_module($module);
- self!compile($module, $filename, $modtime, $source, False, False, $stop, False, Any, Any, False);
+method compile_module($unitname) {
+ my ($filename, $source) = $.module_finder.load_module($unitname);
+ self!compile(:$unitname, :$filename, :$source);
}
method !main_name() {
my $i = $!main-sn++;
$i ?? "MAIN_$i" !! "MAIN";
}
-method compile_file($file, $run, $stop = "") {
- my $*orig_file = $file; # XXX
- my ($filename, $modtime, $source) = $.module_finder.load_file($file);
- self!compile(self!main_name, $filename, $modtime, $source, True, $run, $stop, False, Any, Any, False);
+method compile_file($file, $run) {
+ my ($filename, $source) = $.module_finder.load_file($file);
+ self!compile(unitname => self!main_name, :$filename, :$source, :main, :$run);
}
-method compile_string($source, $run, $stop = "", :$evalmode = False, :$outer, :$repl, :$outer_frame) {
- self!compile(self!main_name, "(eval)", 0, $source, True, $run, $stop, $evalmode, $outer, $outer_frame, $repl);
+method compile_string($source, $run, :$evalmode = False, :$outer, :$repl, :$outer_frame) {
+ self!compile(unitname => self!main_name, filename => "(eval)", :$source,
+ :main, :$run, :$evalmode, :$outer, :$outer_frame, :$repl);
}
View
9 src/NieczaFrontendSTD.pm6
@@ -201,11 +201,10 @@ augment class Cursor {
has $.lang;
has $.safemode;
-method parse(:$unitname, :$filename, :$modtime, :$source, :$outer, :$run, :$main, :$evalmode, :$repl) {
+method parse(:$unitname, :$filename, :$source, :$outer, :$run, :$main, :$evalmode, :$repl) {
my $*SAFEMODE = $.safemode;
my $*UNITNAME = $unitname;
- my $*modtime = $modtime;
my $lang = $!lang;
if $unitname eq 'CORE' {
@@ -253,11 +252,11 @@ method parse(:$unitname, :$filename, :$modtime, :$source, :$outer, :$run, :$main
$*unit.abs_pkg('GLOBAL', :auto);
$*unit.abs_pkg('PROCESS', :auto);
- my $ast = NieczaGrammar.parse($source, actions => NieczaActions).ast;
+ NieczaGrammar.parse($source, actions => NieczaActions);
@STD::herestub_queue = @save_herestub;
- $*backend.accept($unitname, $ast, :$main, :$run, :$evalmode, :$repl);
+ $*backend.accept($*unit, :$filename, :$run, :$evalmode, :$repl);
- $evalmode ?? $ast !! Nil;
+ $evalmode ?? $*unit !! Nil;
}
View
6 src/NieczaPathSearch.pm6
@@ -2,7 +2,7 @@ class NieczaPathSearch;
has @.path;
-# Given Foo::Bar, find ($?FILE, $modtime, $text)
+# Given Foo::Bar, find ($?FILE, $?ORIG)
method load_module($name) {
my $sub = "".IO.combine($name.split('::'));
@@ -15,7 +15,7 @@ method load_module($name) {
my $text = $fn.slurp;
# check borrowed from STD to weed out Perl 5 heuristically
next if $ext eq 'pm' && $text ~~ /^^\h*package\h+\w+\s*\;/;
- return (~$fn.realpath, $fn.modified.to-posix.[0], $text);
+ return ~$fn.realpath, $text;
}
}
}
@@ -25,5 +25,5 @@ method load_module($name) {
method load_file($name) {
my $p = $name.IO;
- (~$p.realpath, $p.modified.to-posix.[0], $p.slurp);
+ (~$p.realpath, $p.slurp);
}
View
19 src/niecza
@@ -116,11 +116,10 @@ usage: niecza -e 'code' # run a one-liner
general options:
-n # short for -L CORN
-p # short for -L CORP
- -B --backend=NAME # select backend (nam, dotnet, clisp, hoopl)
+ -B --backend=NAME # select backend (dotnet)
-L --language=NAME # select your setting
-v --verbose # detailed timing info
-c --compile # don't run (implied with -C)
- --stop-after=STAGE # stop after STAGE and dump AST
--safe # disable system interaction
--help # display this message
@@ -140,8 +139,6 @@ my $verb = 0;
my @eval;
my $cmod = False;
my $comp = False;
-my $stop = "";
-my $aotc = False;
GetOptions(:!permute,
"evaluate|e=s" => sub { push @eval, $_ },
@@ -153,8 +150,6 @@ GetOptions(:!permute,
"verbose|v" => sub { $verb++ },
"compile|c" => sub { $comp = True },
"safe" => sub { $safe = True },
- "stop=s" => sub { $stop = $_ },
- "aot" => sub { $aotc = True },
"include|I=s" => sub { unshift @lib, $_.IO.realpath },
"obj-dir=s" => sub { $odir = $_ },
"help|h" => sub { say $usage; exit 0 },
@@ -178,7 +173,6 @@ my $c = NieczaCompiler.new(
lang => $lang,
safemode => $safe,
),
- stages => [ NieczaPassSimplifier.new ],
backend => $backend,
verbose => $verb,
);
@@ -193,30 +187,31 @@ if $cmod {
exit 0;
}
for @*ARGS {
- $c.compile_module($_, $stop);
+ $c.compile_module($_);
}
}
elsif @eval {
$c.backend.run_args = @*ARGS;
for @eval {
- $c.compile_string($_, !$comp, $stop);
+ $c.compile_string($_, !$comp);
}
}
elsif @*ARGS {
my $file = shift @*ARGS;
$c.backend.run_args = @*ARGS;
- $c.compile_file($file, !$comp, $stop);
+ $c.compile_file($file, !$comp);
}
else {
my $*repl_outer;
my $*repl_outer_frame;
- $c.compile_string('', !$comp, $stop);
+ $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, $stop, :repl, :evalmode,
+ $c.compile_string($l, !$comp, :repl, :evalmode,
:outer($*repl_outer), :outer_frame($*repl_outer_frame));
$ok = True;
}

0 comments on commit db7fa59

Please sign in to comment.