Skip to content

Commit

Permalink
Miscellaneous fixes, setting completely compiled
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Oct 6, 2011
1 parent 7c3e0f7 commit 4648202
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 16 deletions.
24 changes: 13 additions & 11 deletions lib/CodeGen.cs
Expand Up @@ -225,7 +225,7 @@ class Unit {
for (int i = 0; i < xref.Length; i++) {
if (xref[i] == null) continue;
object[] xr = (object[]) xref[i];
if (Backend.Verbose > 0)
if (Config.CGVerbose > 0)
Console.WriteLine("Loading {0} {1}...", JScalar.S(xr[0]),i);
if (JScalar.S(xr[0]) == "sub") {
xref[i] = new StaticSub(this, xr, (code != null &&
Expand Down Expand Up @@ -1242,7 +1242,7 @@ class CgContext {
}

if (ix >= Tokens.NumInt32 &&
(Backend.Verifiable || t.IsValueType)) {
(Config.CGVerifiable || t.IsValueType)) {
il.Emit(OpCodes.Unbox_Any, t);
}
}
Expand Down Expand Up @@ -2324,7 +2324,7 @@ class ClrResult : ClrOp {
return;
cx.il.Emit(OpCodes.Ldarg_0);
cx.il.Emit(OpCodes.Ldfld, Tokens.Frame_resultSlot);
if (Backend.Verifiable || Returns.IsValueType)
if (Config.CGVerifiable || Returns.IsValueType)
cx.il.Emit(OpCodes.Unbox_Any, Returns);
}
}
Expand Down Expand Up @@ -3664,7 +3664,7 @@ class NamProcessor {
thandlers["_pushleave"] = Methody(null, Tokens.Frame.GetMethod("PushLeave"));
handlers["_makesub"] = delegate(NamProcessor th, object[] z) {
return CpsOp.MethodCall(Tokens.Kernel_MakeSub,
CpsOp.GetSField(((StaticSub)z[1]).subinfo),
Backend.currentUnit.SubConstant((SubInfo)z[1]),
CpsOp.CallFrame()); };
handlers["_newlabel"] = delegate(NamProcessor th, object[] z) {
return CpsOp.MethodCall(Tokens.Kernel_NewLabelVar,
Expand Down Expand Up @@ -4356,10 +4356,10 @@ class NamProcessor {
throw new Exception("Unhandled nam operator " + tag);
handlers[tag] = handler = MakeTotalHandler(Methody(null, mi));
}
if (Backend.Verbose > 1)
if (Config.CGVerbose > 1)
Console.WriteLine("enter " + tag);
CpsOp r = handler(this, rnode);
if (Backend.Verbose > 1)
if (Config.CGVerbose > 1)
Console.WriteLine("exit " + tag);
return r;
}
Expand Down Expand Up @@ -4388,10 +4388,6 @@ public class Backend {
// internal List<CpsOp> thaw = new List<CpsOp>();

[ThreadStatic] internal static RuntimeUnit currentUnit;
public static int Verbose =
int.Parse(Environment.GetEnvironmentVariable("NIECZA_CODEGEN_TRACE") ?? "0");
public static bool Verifiable =
Environment.GetEnvironmentVariable("NIECZA_CODEGEN_UNVERIFIABLE") != null ? false : true;

// Backend(string dir, string mobname, string filename) {
// dynamic = (filename == null);
Expand Down Expand Up @@ -4903,7 +4899,13 @@ class Handle: MarshalByRefObject {
public class DowncallReceiver : CallReceiver {
public override object this[object i] {
set { }
get { return Call((object[]) i); }
get {
try {
return Call((object[]) i);
} catch (Exception ex) {
return new Exception(ex.ToString());
}
}
}
static bool TraceDown = Environment.GetEnvironmentVariable("NIECZA_TRACE_DOWNCALLS") != null;

Expand Down
15 changes: 12 additions & 3 deletions lib/Kernel.cs
Expand Up @@ -298,6 +298,8 @@ class IdentityComparer : IEqualityComparer<object> {
NamProcessor[] ths = new NamProcessor[our_subs.Count];
for (int i = 0; i < ths.Length; i++) {
SubInfo z = our_subs[i];
if (Config.CGVerbose > 0)
Console.WriteLine("generating code for: {0}", z.name);
ths[i] = new NamProcessor(
new CpsBuilder(this, "C" + i + z.name, true), z);
ths[i].MakeBody(Reader.Read(z.nam_str, z.nam_refs));
Expand Down Expand Up @@ -328,6 +330,9 @@ class IdentityComparer : IEqualityComparer<object> {
internal CpsOp TypeConstant(STable s) {
return RefConstant(s == null ? "" : s.name, s, Tokens.STable);
}
internal CpsOp SubConstant(SubInfo s) {
return RefConstant(s == null ? "" : s.name, s, Tokens.SubInfo);
}

internal CpsOp RefConstant(string name, object val, Type nty) {
if (val == null)
Expand Down Expand Up @@ -417,7 +422,7 @@ class IdentityComparer : IEqualityComparer<object> {
}

internal CpsOp CCConst(int[] cc) {
StringBuilder code = new StringBuilder();
StringBuilder code = new StringBuilder("CC");
foreach (int x in cc) {
code.Append((char)x);
code.Append((char)(x>>16));
Expand All @@ -426,7 +431,7 @@ class IdentityComparer : IEqualityComparer<object> {
}

internal CpsOp StringListConst(string[] sl) {
StringBuilder code = new StringBuilder();
StringBuilder code = new StringBuilder("SL");
foreach (string s in sl) {
code.Append((char)(s.Length >> 16));
code.Append((char)(s.Length));
Expand All @@ -436,7 +441,7 @@ class IdentityComparer : IEqualityComparer<object> {
}

internal CpsOp CCListConst(int[][] ccl) {
StringBuilder code = new StringBuilder();
StringBuilder code = new StringBuilder("CL");
foreach (int[] cc in ccl) {
code.Append((char)(cc.Length >> 16));
code.Append((char)(cc.Length));
Expand Down Expand Up @@ -5354,6 +5359,10 @@ class LastFrameNode {
}

public class Config {
public static int CGVerbose =
int.Parse(Environment.GetEnvironmentVariable("NIECZA_CODEGEN_TRACE") ?? "0");
public static bool CGVerifiable =
Environment.GetEnvironmentVariable("NIECZA_CODEGEN_UNVERIFIABLE") != null ? false : true;
public static readonly bool C3Trace =
Environment.GetEnvironmentVariable("NIECZA_C3_TRACE") != null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/CompilerBlob.cs
Expand Up @@ -133,11 +133,11 @@ public class Downcaller {
string s = Kernel.UnboxAny<string>(o);
sb.Append('"');
foreach (char c in s) {
if (c >= ' ' && c <= '~')
if (c >= ' ' && c <= '~' && c != '\\' && c != '"')
sb.Append(c);
else {
sb.Append("\\u");
sb.AppendFormat("{0:4X}", (int)c);
sb.AppendFormat("{0:X4}", (int)c);
}
}
sb.Append('"');
Expand Down
59 changes: 59 additions & 0 deletions src/niecza
Expand Up @@ -824,6 +824,65 @@ method parameter($/) {
:$optional, :$slurpy, :$rw, tclass => $type,
:$slurpycap, rwtrans => $rwt, is_copy => $copy, |$p.ast);
}
method package_def ($/) {
my $sub = $*CURLEX<!sub>;
my $obj = $sub.body_of;

my $bodyvar = self.gensym;
$sub.outer.add_my_sub($bodyvar, $sub);
my $ast = ($<blockoid> // $<statementlist>).ast;

if defined $*AUGMENT_BUFFER {
# generate an INIT block to do the augment
my $ph = $*unit.create_sub(
outer => $sub,
cur_pkg => $sub.cur_pkg,
name => "phaser-$sub.name()",
class => 'Code',
run_once => $sub.run_once);

my @ops;
for @( $*AUGMENT_BUFFER ) -> $mode, $name, $sym {
push @ops, CgOp._addmethod(CgOp.letvar('!mo'), $mode,
CgOp.str($name), CgOp.fetch(CgOp.scopedlex($sym)));
}
my $fin = CgOp.letn('!mo', CgOp.class_ref('mo', $obj),
@ops, CgOp._invalidate(CgOp.letvar('!mo')), CgOp.corelex('Nil'));

$ph.finish(::Op::CgOp.new(op => $fin));
$sub.create_static_pad;
$ph.set_phaser(+::Metamodel::Phaser::INIT);

make ::Op::CallSub.new(|node($/), invocant => mklex($/, $bodyvar));
}
else {
if $<stub> {
$*unit.stub_stash($/.from, $obj);

make mklex($/, $*CURLEX<!sub>.outervar);
}
else {
$/.CURSOR.trymop({ $obj.close; });

if $obj.kind eq 'prole' {
# return the frame object so that role instantiation can
# find the cloned methods
$ast = ::Op::StatementList.new(|node($/), children => [
$ast, mkcall($/, '&callframe') ]);
$sub.create_static_pad;
$obj.set_instantiation_block($sub);

make mklex($/, $*CURLEX<!sub>.outervar);
} else {
make ::Op::StatementList.new(|node($/), children => [
::Op::CallSub.new(invocant => mklex($/, $bodyvar)),
::Op::Lexical.new(name => $*CURLEX<!sub>.outervar) ]);
}
}
}

$sub.finish($ast);
}

}

Expand Down

0 comments on commit 4648202

Please sign in to comment.