Skip to content
Browse files

Top removal: iterators, variables, vivihooks

  • Loading branch information...
1 parent 4c016f5 commit f43fe40cdc1376664f698c249a94b60cee545b43 @sorear committed Nov 6, 2012
Showing with 22 additions and 46 deletions.
  1. +6 −2 lib/Builtins.cs
  2. +0 −4 lib/CORE.setting
  3. +0 −25 lib/CodeGen.cs
  4. +13 −11 lib/Kernel.cs
  5. +2 −3 lib/ObjModel.cs
  6. +1 −1 lib/Serialize.cs
View
8 lib/Builtins.cs
@@ -2121,7 +2121,7 @@ public partial class Builtins {
MakeInt(i);
}
public static int get_count(P6any fcni) {
- if (!fcni.Isa(Compartment.Top.CodeMO))
+ if (!fcni.Isa(fcni.mo.setting.CodeMO))
return 1; // can't introspect fake subs (?)
return sig_count(Kernel.GetInfo(fcni).sig);
}
@@ -2182,7 +2182,7 @@ class ItemSource {
if (items.Count() == 0) return -1;
Variable v = items[0];
P6any i = v.Fetch();
- if (i.mo.HasType(Compartment.Top.IterCursorMO))
+ if (i.mo.HasType(i.mo.setting.IterCursorMO))
return 0;
if (v.List) {
items.Shift();
@@ -2934,6 +2934,10 @@ class CrossSource: ItemSource {
return (rty == P6how.ROLE || rty == P6how.CURRIED_ROLE || rty == P6how.PARAMETRIZED_ROLE) ? c.setting.TrueV : c.setting.FalseV;
}
+ [ImplicitConsts] public static Variable var_get_var(Constants c, Variable o) {
+ return Kernel.BoxAnyMO<Variable>(o, c.setting.ScalarMO);
+ }
+
public class Blackhole : Variable {
P6any value;
View
4 lib/CORE.setting
@@ -2421,10 +2421,6 @@ my class Junction is Mu {
}
# }}}
# List utilities {{{
-sub _vivify_array_at_pos(\ary, $ix) {
- Q:CgOp { (newvnewarrayvar (class_ref mo Any) {ary} (cast int (obj_getnum {$ix})) (@ {Any})) };
-}
-
my class GatherIterator is IterCursor {
has $.frame;
has $!reify;
View
25 lib/CodeGen.cs
@@ -320,14 +320,6 @@ sealed class Tokens {
STable, typeof(ViviHook), P6any });
public static readonly ConstructorInfo SubViviHook_ctor =
typeof(SubViviHook).GetConstructor(new Type[] { P6any });
- public static readonly ConstructorInfo HashViviHook_ctor =
- typeof(HashViviHook).GetConstructor(new Type[] { P6any, String });
- public static readonly ConstructorInfo ArrayViviHook_ctor =
- typeof(ArrayViviHook).GetConstructor(new Type[] { P6any, Int32 });
- public static readonly ConstructorInfo NewHashViviHook_ctor =
- typeof(NewHashViviHook).GetConstructor(new Type[] { Variable, String });
- public static readonly ConstructorInfo NewArrayViviHook_ctor =
- typeof(NewArrayViviHook).GetConstructor(new Type[] { Variable, Int32 });
public static readonly ConstructorInfo Rat_ctor =
typeof(Rat).GetConstructor(new Type[] { typeof(BigInteger), typeof(ulong) });
public static readonly ConstructorInfo BigInteger_ctor =
@@ -2916,22 +2908,6 @@ class NamProcessor {
return CpsOp.ConstructorCall(Tokens.SV_ctor, z[0],
CpsOp.ConstructorCall(Tokens.SubViviHook_ctor,
z[1]), z[2]); };
- thandlers["newvhashvar"] = delegate(CpsOp[] z) {
- return CpsOp.ConstructorCall(Tokens.SV_ctor, z[0],
- CpsOp.ConstructorCall(Tokens.HashViviHook_ctor,
- z[1], z[2]), z[3]); };
- thandlers["newvarrayvar"] = delegate(CpsOp[] z) {
- return CpsOp.ConstructorCall(Tokens.SV_ctor, z[0],
- CpsOp.ConstructorCall(Tokens.ArrayViviHook_ctor,
- z[1], z[2]), z[3]); };
- thandlers["newvnewhashvar"] = delegate(CpsOp[] z) {
- return CpsOp.ConstructorCall(Tokens.SV_ctor, z[0],
- CpsOp.ConstructorCall(Tokens.NewHashViviHook_ctor,
- z[1], z[2]), z[3]); };
- thandlers["newvnewarrayvar"] = delegate(CpsOp[] z) {
- return CpsOp.ConstructorCall(Tokens.SV_ctor, z[0],
- CpsOp.ConstructorCall(Tokens.NewArrayViviHook_ctor,
- z[1], z[2]), z[3]); };
thandlers["strbuf_append"] = delegate(CpsOp[] z) {
return CpsOp.Sink(CpsOp.MethodCall(Tokens.StringBuilder_Append_String, z)); };
thandlers["varhash_delete_key"] = delegate(CpsOp[] z) {
@@ -3141,7 +3117,6 @@ class NamProcessor {
thandlers["delete_key"] = thandlers["obj_delete_key"] = Contexty("mro_delete_key");
thandlers["cross"] = Methody(Tokens.Variable, Tokens.Builtins.GetMethod("MECross"));
thandlers["zip"] = Methody(Tokens.Variable, Tokens.Builtins.GetMethod("MEZip"));
- thandlers["var_get_var"] = Methody(null, Tokens.Variable.GetMethod("GetVar"));
thandlers["var_new_tied"] = Constructy(typeof(TiedVariable).GetConstructor(new Type[] { Tokens.P6any, Tokens.P6any, Tokens.P6any }));
thandlers["obj_typename"] = Methody(null, Tokens.P6any.GetMethod("GetTypeName"));
thandlers["fetch"] = Methody(null, Tokens.Variable_Fetch);
View
24 lib/Kernel.cs
@@ -78,10 +78,6 @@ public abstract class Variable : IFreeze {
public abstract P6any Fetch();
public abstract void Store(P6any v);
- public virtual Variable GetVar() {
- return Kernel.BoxAnyMO<Variable>(this, Compartment.Top.ScalarMO);
- }
-
public abstract void Freeze(FreezeBuffer fb);
// note: callers need to make sure type is set up properly if null
@@ -138,22 +134,25 @@ public class HashViviHook : ViviHook {
}
public class NewHashViviHook : ViviHook {
+ STable mo;
Variable hashv;
string key;
- public NewHashViviHook(Variable hashv, string key) { this.hashv = hashv; this.key = key; }
+ public NewHashViviHook(STable mo, Variable hashv, string key) { this.mo = mo; this.hashv = hashv; this.key = key; }
public override void Do(Variable toviv) {
VarHash rh = new VarHash();
rh[key] = toviv;
- hashv.Store(Kernel.BoxRaw(rh, Compartment.Top.HashMO));
+ hashv.Store(Kernel.BoxRaw(rh, mo));
}
public override void Freeze(FreezeBuffer fb) {
fb.Byte((byte)SerializationCode.NewHashViviHook);
+ fb.ObjRef(mo);
fb.ObjRef(hashv);
fb.String(key);
}
internal static IFreeze Thaw(ThawBuffer tb) {
- var n = new NewHashViviHook(null, null);
+ var n = new NewHashViviHook(null, null, null);
tb.Register(n);
+ n.mo = (STable) tb.ObjRef();
n.hashv = (Variable) tb.ObjRef();
n.key = tb.String();
return n;
@@ -165,7 +164,7 @@ public class ArrayViviHook : ViviHook {
int key;
public ArrayViviHook(P6any ary, int key) { this.ary = ary; this.key = key; }
public override void Do(Variable toviv) {
- VarDeque vd = (VarDeque) ary.GetSlot(Compartment.Top.ListMO, "$!items");
+ VarDeque vd = (VarDeque) ary.GetSlot(ary.mo.setting.ListMO, "$!items");
while (vd.Count() <= key)
vd.Push(Kernel.NewTypedScalar(null));
vd[key] = toviv;
@@ -185,27 +184,30 @@ public class ArrayViviHook : ViviHook {
}
public class NewArrayViviHook : ViviHook {
+ STable mo;
Variable ary;
int key;
- public NewArrayViviHook(Variable ary, int key) { this.ary = ary; this.key = key; }
+ public NewArrayViviHook(STable mo, Variable ary, int key) { this.mo = mo; this.ary = ary; this.key = key; }
public override void Do(Variable toviv) {
VarDeque vd = new VarDeque();
while (vd.Count() <= key)
vd.Push(Kernel.NewTypedScalar(null));
vd[key] = toviv;
- P6opaque d = new P6opaque(Compartment.Top.ArrayMO);
+ P6opaque d = new P6opaque(mo);
d.slots[0] = vd;
d.slots[1] = new VarDeque();
ary.Store(d);
}
public override void Freeze(FreezeBuffer fb) {
fb.Byte((byte)SerializationCode.NewArrayViviHook);
+ fb.ObjRef(mo);
fb.ObjRef(ary);
fb.Int(key);
}
internal static IFreeze Thaw(ThawBuffer tb) {
- var n = new NewArrayViviHook(null, 0);
+ var n = new NewArrayViviHook(null, null, 0);
tb.Register(n);
+ n.mo = (STable) tb.ObjRef();
n.ary = (Variable) tb.ObjRef();
n.key = tb.Int();
return n;
View
5 lib/ObjModel.cs
@@ -11,7 +11,6 @@ public abstract class P6any: Variable, IFreeze {
public override void Store(P6any val) {
throw new NieczaException("Writing to readonly scalar");
}
- public override Variable GetVar() { return this; }
public virtual object GetSlot(STable type, string name) {
throw new NieczaException("Representation " + ReprName() + " does not support attributes");
@@ -112,12 +111,12 @@ public abstract class IndexHandler : ReflectObj {
public Variable ViviHash(Variable obj, Variable key) {
return new RWVariable(setting.MuMO,
- new NewHashViviHook(obj, key.Fetch().mo.mro_raw_Str.Get(key)),
+ new NewHashViviHook(setting.HashMO, obj, key.Fetch().mo.mro_raw_Str.Get(key)),
setting.AnyP);
}
public Variable ViviArray(Variable obj, Variable key) {
return new RWVariable(setting.MuMO,
- new NewArrayViviHook(obj, (int)key.Fetch().mo.mro_raw_Numeric.Get(key)),
+ new NewArrayViviHook(setting.ArrayMO, obj, (int)key.Fetch().mo.mro_raw_Numeric.Get(key)),
setting.AnyP);
}
View
2 lib/Serialize.cs
@@ -72,7 +72,7 @@ struct ObjRef {
new Dictionary<string,object>();
static readonly string signature = "Niecza-Serialized-Module";
- static readonly int version = 30;
+ static readonly int version = 31;
// Routines for use by serialization code
public bool CheckWriteObject(SerUnit into, object o,

0 comments on commit f43fe40

Please sign in to comment.
Something went wrong with that request. Please try again.