Permalink
Browse files

Reimplement the REPL

  • Loading branch information...
1 parent 1ac3838 commit ab38e2b42c1ad29d379c5f84c24cdb1d85c29e4c @sorear committed Oct 24, 2011
Showing with 25 additions and 24 deletions.
  1. +17 −20 lib/CodeGen.cs
  2. +3 −0 lib/Kernel.cs
  3. +3 −3 src/NieczaBackendDotnet.pm6
  4. +2 −1 src/niecza
View
@@ -4069,7 +4069,8 @@ public class DowncallReceiver : CallReceiver {
// to call methods on the type in the process of defining the
// type itself.
nst.mo.superclasses.Clear();
- nst.typeObject = new P6opaque(nst, 0);
+ if (nst.typeObject == null) // AnyMO.typeObject is set up early
+ nst.typeObject = new P6opaque(nst, 0);
((P6opaque)nst.typeObject).slots = null;
nst.typeVar = Kernel.NewROScalar(nst.typeObject);
@@ -4254,26 +4255,22 @@ public class DowncallReceiver : CallReceiver {
Builtins.execName = (string)args[1];
Builtins.programName = (string)args[2];
return null;
- } else if (cmd == "replrun") {
- string ret = "";
- try {
- StashEnt b = Kernel.GetVar("::PROCESS", "$OUTPUT_USED");
- b.v = Kernel.FalseV;
- // hack to simulate a settingish environment
- Variable r = Kernel.RunInferior(
- Kernel.GetInferiorRoot().MakeChild(null,
- new SubInfo("<repl>", null),//Builtins.eval_result),
- Kernel.AnyP));
- if (!b.v.Fetch().mo.mro_raw_Bool.Get(b.v)) {
- Variable pl = Kernel.RunInferior(
- r.Fetch().InvokeMethod(Kernel.GetInferiorRoot(),
- "gist", new Variable[] { r }, null));
- Console.WriteLine(pl.Fetch().mo.mro_raw_Str.Get(pl));
- }
- } catch (Exception ex) {
- ret = ex.Message;
+ } else if (cmd == "unit_replrun") {
+ RuntimeUnit ru = (RuntimeUnit)Handle.Unbox(args[1]);
+ Frame fret = null;
+ StashEnt b = Kernel.GetVar("::PROCESS", "$OUTPUT_USED");
+ b.v = Kernel.FalseV;
+ Frame ir = Kernel.GetInferiorRoot();
+ fret = ru.mainline.protosub.Invoke(ir, Variable.None, null);
+ fret.MarkShared();
+ Variable r = Kernel.RunInferior(fret);
+ if (!b.v.Fetch().mo.mro_raw_Bool.Get(b.v)) {
+ Variable pl = Kernel.RunInferior(
+ r.Fetch().InvokeMethod(Kernel.GetInferiorRoot(),
+ "gist", new Variable[] { r }, null));
+ Console.WriteLine(pl.Fetch().mo.mro_raw_Str.Get(pl));
}
- return ret;
+ return new Handle(fret);
} else if (cmd == "safemode") {
Kernel.SaferMode = true;
return null;
View
@@ -5237,6 +5237,9 @@ class LastFrameNode {
MuMO.Invalidate();
AnyMO = new STable("Any");
+ // AnyMO.typeObject is needed very early, while setting up the
+ // root $_
+ AnyMO.typeObject = new P6opaque(AnyMO, 0);
Handler_Vonly(AnyMO, "list", new CtxAnyList(), null);
WrapIndexy(AnyMO, "postcircumfix:<[ ]>", new IxAnyAtPos(),
null, null, new IxAnyBindPos());
@@ -44,13 +44,13 @@ method accept($unitname, $unit, :$main, :$run, :$evalmode, :$repl) { #OK not use
$*orig_file // '(eval)') unless $repl;
downcall("run_unit", $unit, ?$evalmode, @$!run_args);
if $repl {
- downcall("replrun");
+ $*repl_outer_frame = $unit.replrun;
+ $*repl_outer = $unit.mainline;
}
- $*repl_outer = $unit.get_mainline if $repl;
return;
}
downcall("save_unit", $unit);
- $*repl_outer = $unit.get_mainline if $repl;
+ $*repl_outer = $unit.mainline if $repl;
}
class StaticSub {
View
@@ -604,14 +604,15 @@ elsif @*ARGS {
}
else {
my $*repl_outer;
+ my $*repl_outer_frame;
$c.compile_string('', !$comp, $stop);
while True {
print "niecza> ";
my $l = $*IN.get // last;
my $ok;
try {
$c.compile_string($l, !$comp, $stop, :repl, :evalmode,
- :outer($*repl_outer));
+ :outer($*repl_outer), :outer_frame($*repl_outer_frame));
$ok = True;
}
say $! unless $ok;

0 comments on commit ab38e2b

Please sign in to comment.