Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use a blob for the SubInfo constructor
  • Loading branch information
sorear committed May 23, 2011
1 parent 04df192 commit 183a42a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 19 deletions.
47 changes: 30 additions & 17 deletions lib/CLRBackend.cs
Expand Up @@ -340,22 +340,34 @@ class Unit {
}

public void EmitStr(string s) {
if (s == null) { EmitUShort(0xFFFF); return; }
EmitUShort(s.Length);
foreach(char c in s) EmitUShort((int)c);
}

public void EmitIntArray(int[] s) {
if (s == null) { EmitInt(-1); return; }
EmitInt(s.Length);
foreach(int c in s) EmitInt(c);
}

public void EmitStrArray(string[] s) {
if (s == null) { EmitInt(-1); return; }
EmitInt(s.Length);
foreach(string c in s) EmitStr(c);
}

public void EmitLADArr(object lad) {
object[] lada = (object[]) lad;
EmitUShort(lada.Length);
foreach(object o in lada) EmitLAD(o);
}

public void EmitLAD(object lad) {
if (lad == null) {
EmitByte(0);
return;
}
object[] body = (object[]) lad;
string head = JScalar.S(body[0]);

Expand Down Expand Up @@ -3612,19 +3624,25 @@ class NamProcessor {
}

public CpsOp SubInfoCtor() {
CpsOp[] args = new CpsOp[10];
args[0] = CpsOp.StringLiteral(sub.unit.name + " " +
(sub.name == "ANON" ? cpb.mb.Name : sub.name));
args[1] = CpsOp.NewIntArray(Tokens.Int32, cpb.cx.lineBuffer.ToArray());
CpsOp[] args = new CpsOp[4];

int b = sub.unit.thaw_heap.Count;

args[0] = CpsOp.GetSField(sub.unit.rtunit);
args[1] = CpsOp.IntLiteral(b);
args[2] = CpsOp.DBDLiteral(cpb.mb);
args[3] = (sub.outer != null) ?
CpsOp.GetSField(sub.outer.Resolve<StaticSub>().subinfo) :
CpsOp.Null(Tokens.SubInfo);
args[4] = (sub.ltm != null) ? ProcessLAD(sub.ltm) :
CpsOp.Null(Tokens.LAD);
args[5] = CpsOp.NewIntArray(Tokens.Int32, cpb.cx.ehspanBuffer.ToArray() );
args[6] = CpsOp.StringArray( true, cpb.cx.ehlabelBuffer.ToArray() );
args[7] = CpsOp.IntLiteral( cpb.Spills() );

sub.unit.EmitStr(sub.unit.name + " " +
(sub.name == "ANON" ? cpb.mb.Name : sub.name));
sub.unit.EmitIntArray(cpb.cx.lineBuffer.ToArray());
sub.unit.EmitLAD(sub.ltm);
sub.unit.EmitIntArray(cpb.cx.ehspanBuffer.ToArray());
sub.unit.EmitStrArray(cpb.cx.ehlabelBuffer.ToArray());
sub.unit.EmitInt(cpb.Spills());

List<string> dylexn = new List<string>();
List<int> dylexi = new List<int>();
foreach (KeyValuePair<string, Lexical> kv in sub.lexicals) {
Expand All @@ -3635,15 +3653,10 @@ class NamProcessor {
dylexi.Add(index);
}
}
if (dylexn.Count > 0) {
args[8] = CpsOp.StringArray(true, dylexn.ToArray());
args[9] = CpsOp.NewIntArray(Tokens.Int32, dylexi.ToArray());
} else {
args[8] = CpsOp.Null(typeof(string[]));
args[9] = CpsOp.Null(typeof(int[]));
}
sub.unit.EmitStrArray(dylexn.ToArray());
sub.unit.EmitIntArray(dylexi.ToArray());

return CpsOp.ConstructorCall(Tokens.SubInfo_ctor, args);
return CpsOp.MethodCall(typeof(RuntimeUnit).GetMethod("LoadSubInfo"), args);
}

void EnterCode(List<object> frags) {
Expand Down
30 changes: 28 additions & 2 deletions lib/Kernel.cs
Expand Up @@ -215,17 +215,43 @@ public sealed class RuntimeUnit {
}

public int[] ReadIntArray(ref int from) {
int[] r = new int[ReadInt(ref from)];
int l = ReadInt(ref from);
if (l == -1) return null;
int[] r = new int[l];
for (int i = 0; i < r.Length; i++) r[i] = ReadInt(ref from);
return r;
}

public string[] ReadStrArray(ref int from) {
int l = ReadInt(ref from);
if (l == -1) return null;
string[] r = new string[l];
for (int i = 0; i < r.Length; i++) r[i] = ReadStr(ref from);
return r;
}

public string ReadStr(ref int from) {
char[] r = new char[ReadShort(ref from)];
int l = ReadShort(ref from);
if (l == 0xffff) return null;
char[] r = new char[l];
for (int i = 0; i < r.Length; i++) r[i] = (char)ReadShort(ref from);
return new string(r);
}

public SubInfo LoadSubInfo(int from, DynBlockDelegate code, SubInfo outer) {
return new SubInfo(
ReadStr(ref from), /*name*/
ReadIntArray(ref from), /*lines*/
code,
outer,
ReadLAD(ref from),
ReadIntArray(ref from), /*ehspan*/
ReadStrArray(ref from), /*ehlabel*/
ReadInt(ref from), /*nspill*/
ReadStrArray(ref from), /*dylexn*/
ReadIntArray(ref from)); /*dylexi*/
}

public LAD LoadLAD(int from) {
return ReadLAD(ref from);
}
Expand Down

0 comments on commit 183a42a

Please sign in to comment.