Permalink
Browse files

misc top removal: MakePair, LHF

  • Loading branch information...
1 parent cde23d6 commit c80570d034d2065238903f29a212867e7ac58a54 @sorear committed Nov 12, 2012
Showing with 35 additions and 30 deletions.
  1. +3 −10 lib/Builtins.cs
  2. +9 −8 lib/CodeGen.cs
  3. +1 −1 lib/Cursor.cs
  4. +10 −3 lib/Kernel.cs
  5. +3 −3 lib/Printf.cs
  6. +5 −2 lib/Serialize.cs
  7. +4 −3 lib/UCD.cs
View
@@ -1769,7 +1769,7 @@ public partial class Builtins {
}
public static Variable HashIter(int mode, Variable v) {
VarDeque lv = HashIterRaw(mode, v);
- P6opaque l = new P6opaque(Compartment.Top.ListMO);
+ P6opaque l = new P6opaque(v.Fetch().mo.setting.ListMO);
l.slots[0] = lv;
l.slots[1] = new VarDeque();
return Kernel.NewRWListVar(l);
@@ -2010,15 +2010,8 @@ public partial class Builtins {
return InvokeSub(sub).Fetch();
}
- public static P6any MakePair(Variable key, Variable value) {
- P6any l = new P6opaque(Compartment.Top.PairMO);
- l.SetSlot(Compartment.Top.EnumMO, "$!key", key);
- l.SetSlot(Compartment.Top.EnumMO, "$!value", value);
- return l;
- }
-
- public static Variable pair(Variable key, Variable value) {
- return MakePair(key, value);
+ [ImplicitConsts] public static Variable pair(Constants c, Variable key, Variable value) {
+ return c.setting.MakePair(key, value);
}
public static VarDeque start_iter(Variable thing) {
View
@@ -3682,11 +3682,12 @@ public class DowncallReceiver : CallReceiver {
return Builtins.UnboxLoS(bv.v);
}
public static object unit_use_perl5_module(object[] args) {
- string name = (string)args[2];
- Variable code = Kernel.BoxAnyMO<string>("Niecza::Helpers::use_module('"+name+"')", Compartment.Top.StrMO);
- string sub = Kernel.UnboxAny<string>(Builtins.eval_perl5(code).Fetch());
- return sub;
- }
+ RuntimeUnit ru = (RuntimeUnit)Handle.Unbox(args[1]);
+ string name = (string)args[2];
+ Variable code = Kernel.BoxAnyMO<string>("Niecza::Helpers::use_module('"+name+"')", ru.setting.StrMO);
+ string sub = Kernel.UnboxAny<string>(Builtins.eval_perl5(code).Fetch());
+ return sub;
+ }
public static object unit_need_unit(object[] args) {
// LinkUnit state is owned by the root
RuntimeUnit ru = (RuntimeUnit)Handle.Unbox(args[1]);
@@ -3787,7 +3788,7 @@ public class DowncallReceiver : CallReceiver {
}
public static object value_to_sub(object[] args) {
var v = ((Variable)Handle.Unbox(args[1])).Fetch();
- return Handle.Wrap(v.Isa(Compartment.Top.CodeMO) ? Kernel.GetInfo(v) : null);
+ return Handle.Wrap(v.Isa(v.mo.setting.CodeMO) ? Kernel.GetInfo(v) : null);
}
public static object value_to_string(object[] args) {
return Builtins.ToStr((Variable)Handle.Unbox(args[1]));
@@ -3805,9 +3806,9 @@ public class DowncallReceiver : CallReceiver {
}
public static object value_starts_with_pair(object[] args) {
var ob = ((Variable)Handle.Unbox(args[1])).Fetch();
- if (ob.Isa(Compartment.Top.PairMO))
+ if (ob.Isa(ob.mo.setting.PairMO))
return true;
- if (ob.Isa(Compartment.Top.ParcelMO) && Kernel.UnboxAny<Variable[]>(ob)[0].Fetch().Isa(Compartment.Top.PairMO))
+ if (ob.Isa(ob.mo.setting.ParcelMO) && Kernel.UnboxAny<Variable[]>(ob)[0].Fetch().Isa(ob.mo.setting.PairMO))
return true;
return false;
}
View
@@ -987,7 +987,7 @@ public partial class Builtins {
if (!it.cap.Fetch().Isa(s.MatchMO))
continue;
foreach (string name in it.names)
- dq.Unshift(pair(s.MakeStr(name), it.cap));
+ dq.Unshift(s.MakePair(s.MakeStr(name), it.cap));
}
P6opaque lst = new P6opaque(s.ListMO);
View
@@ -3871,7 +3871,7 @@ class KeySlicer : IndexHandler {
switch (mode) {
case 0: return key;
case 1: return setting.MakeParcel(key, bas.Get(obj, key));
- default: return Builtins.pair(key, bas.Get(obj, key));
+ default: return setting.MakePair(key, bas.Get(obj, key));
}
}
}
@@ -4780,6 +4780,13 @@ public class Compartment {
return Kernel.BoxAnyMO<Complex>(z, ComplexMO);
}
+ public P6any MakePair(Variable key, Variable value) {
+ P6any l = new P6opaque(PairMO);
+ l.SetSlot(EnumMO, "$!key", key);
+ l.SetSlot(EnumMO, "$!value", value);
+ return l;
+ }
+
public Variable MakeParcel(params Variable[] bits) {
return Kernel.NewRWListVar(Kernel.BoxRaw(bits, ParcelMO));
}
@@ -4981,7 +4988,7 @@ public class Kernel {
internal static void InitCompartment() {
var c = Compartment.Top;
- c.reg = new ObjectRegistry();
+ c.reg = new ObjectRegistry(c);
c.AutoThreadSubSI = new SubInfo("KERNEL AutoThreadSub",
SubInfo.AutoThreadSubC);
@@ -6754,7 +6761,7 @@ class LastFrameNode {
RewriteUnits(root, root, new HashSet<RuntimeUnit>());
// reset for writability
- Compartment.Top.reg = new ObjectRegistry();
+ Compartment.Top.reg = new ObjectRegistry(Compartment.Top);
root.dll_name = exename + ".exe";
root.asm_name = exename;
View
@@ -10,7 +10,7 @@ public partial class Builtins {
public static Variable sprintf(Variable[] args) {
char[] fmt = args[0].Fetch().mo.mro_raw_Str.Get(args[0]).ToCharArray();
List<PrintfFormat> fmtlist = ParseFormatString(fmt);
- return RenderFormat(fmtlist, args);
+ return args[0].Fetch().mo.setting.MakeStr(RenderFormat(fmtlist, args));
}
private enum PrintfDirective {
@@ -297,7 +297,7 @@ private struct PrintfFormat {
}
}
- private static Variable RenderFormat(List<PrintfFormat> formatlist, Variable[] args) {
+ private static string RenderFormat(List<PrintfFormat> formatlist, Variable[] args) {
string result = "";
int argi = 0;
foreach (PrintfFormat format in formatlist) {
@@ -328,7 +328,7 @@ private struct PrintfFormat {
throw new NieczaException("index out of range");
}
}
- return Kernel.BoxAnyMO(result, Compartment.Top.StrMO);
+ return result;
}
}
View
@@ -59,6 +59,7 @@ struct ObjRef {
public SerUnit unit;
public int id;
}
+ Compartment setting;
Dictionary<object,ObjRef> byref = new Dictionary<object,ObjRef>();
Dictionary<string,SerUnit> units =
@@ -74,6 +75,8 @@ struct ObjRef {
static readonly string signature = "Niecza-Serialized-Module";
static readonly int version = 31;
+ public ObjectRegistry(Compartment s) { setting = s; }
+
// Routines for use by serialization code
public bool CheckWriteObject(SerUnit into, object o,
out SerUnit lui, out int id) {
@@ -141,7 +144,7 @@ struct ObjRef {
if (fake) {
if (name.StartsWith("CLR,"))
- CLRWrapperProvider.LoadWrapper(Compartment.Top, name.Substring(4));
+ CLRWrapperProvider.LoadWrapper(setting, name.Substring(4));
else
throw new ThawException("No handler for fake unit name " + name);
@@ -156,7 +159,7 @@ struct ObjRef {
su.name = name;
su.hash = NewHash().ComputeHash(bytes);
- ThawBuffer tb = new ThawBuffer(Compartment.Top, this, su, bytes);
+ ThawBuffer tb = new ThawBuffer(setting, this, su, bytes);
units[name] = su;
bool success = false;
View
@@ -73,8 +73,9 @@ class LimitedProperty : Property {
public override int[] GetRanges(Variable filter) {
bool[] cfilter = new bool[values.Length];
+ var setting = filter.Fetch().mo.setting;
// minor hack to make :BoolProp work - converts to True/False
- if (filter.Fetch().Isa(Compartment.Top.BoolMO))
+ if (filter.Fetch().Isa(setting.BoolMO))
filter = filter.Fetch().mo.mro_Str.Get(filter);
for (int i = 0; i < values.Length; i++) {
foreach (string s in values[i]) {
@@ -644,8 +645,8 @@ static class DataSet {
public static object CompileCClass(Variable pair) {
P6any pairo = pair.Fetch();
- Variable tbl = (Variable)pairo.GetSlot(Compartment.Top.EnumMO, "$!key");
- Variable sm = (Variable)pairo.GetSlot(Compartment.Top.EnumMO, "$!value");
+ Variable tbl = (Variable)pairo.GetSlot(pairo.mo.setting.EnumMO, "$!key");
+ Variable sm = (Variable)pairo.GetSlot(pairo.mo.setting.EnumMO, "$!value");
Property p = (Property)DataSet.GetTable(
tbl.Fetch().mo.mro_raw_Str.Get(tbl));
int[] rranges = p.GetRanges(sm);

0 comments on commit c80570d

Please sign in to comment.