Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement auto-compilation of referenced modules
  • Loading branch information
sorear committed Oct 25, 2011
1 parent 5f9e2f8 commit 2664568
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
13 changes: 11 additions & 2 deletions lib/CodeGen.cs
Expand Up @@ -3648,8 +3648,17 @@ public class DowncallReceiver : CallReceiver {
//RuntimeUnit ru = (RuntimeUnit)Handle.Unbox(args[1]);
string oname = (string)args[2];

RuntimeUnit tg = (RuntimeUnit)
RuntimeUnit.reg.LoadUnit(oname).root;
RuntimeUnit tg;
try {
tg = (RuntimeUnit) RuntimeUnit.reg.LoadUnit(oname).root;
} catch (Exception) {
// assume stale at first
object r1 = Builtins.UpCall(new object[] {
"compile_unit", oname });
if (r1 != null)
return r1;
tg = (RuntimeUnit) RuntimeUnit.reg.LoadUnit(oname).root;
}
string err = Kernel.containerRootUnit.LinkUnit(tg);
return err == null ? (object)new Handle(tg) : new Exception(err);
} else if (cmd == "unit_anon_stash") {
Expand Down
25 changes: 24 additions & 1 deletion src/NieczaBackendDotnet.pm6
Expand Up @@ -9,15 +9,34 @@ has $.safemode = False;
has $.obj_dir;
has $.run_args = [];


sub upcalled(*@args) {
my $v = $*compiler.verbose;
given @args[0] {
when "eval" {
my $*IN_EVAL = True;
say "eval: @args[1] from @args[2].name()" if $v;
return $*compiler.compile_string(@args[1], True, :evalmode,
:outer(@args[2]), :outer_frame(@args[3]));
}
when "check_dated" {
return "ok"; #TODO
shift @args;
for @args -> $module, $hash {
my ($file, $modt, $src) = #OK
$*compiler.module_finder.load_module($module);
my $trueh = gethash($src);
say "check-dated $module: was $hash now $trueh" if $v;
return "no" unless $hash eq $trueh;
}
return "ok";
}
when "compile_unit" {
say "autocompiling @args[1]..." if $v;
say "[auto-compiling setting]" if @args[1] eq 'CORE' && !$v;
$*compiler.compile_module(@args[1]);
say "[done]" if @args[1] eq 'CORE' && !$v;
say "done compiling @args[1]." if $v;
return;
}
say "upcall: @args.join('|')";
die "ERROR";
Expand All @@ -37,6 +56,10 @@ sub downcall(*@args) {
Q:CgOp { (rawscall Niecza.Downcaller,CompilerBlob.DownCall {@args}) }
}

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;
if $run {
Expand Down

0 comments on commit 2664568

Please sign in to comment.