Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Top removal: more smart constructors

  • Loading branch information...
commit 48d66de4fbd418d2b64a7f47fd1beba463d1ee0b 1 parent 202e700
@sorear authored
Showing with 64 additions and 58 deletions.
  1. +20 −56 lib/Builtins.cs
  2. +1 −0  lib/CodeGen.cs
  3. +2 −2 lib/JSYNC.cs
  4. +41 −0 lib/Kernel.cs
View
76 lib/Builtins.cs
@@ -1726,26 +1726,6 @@ public partial class Builtins {
return c.setting.MakeInt(ix);
}
- public static Variable MakeJunction(int type, Variable[] elems) {
- if (type >= 8) {
- type -= 8;
- foreach (Variable e in elems)
- if (e.List) goto need_flatten;
- goto flat_enough;
-need_flatten:;
- VarDeque iter = new VarDeque(elems);
- VarDeque into = new VarDeque();
- while (Kernel.IterHasFlat(iter, true))
- into.Push(iter.Shift());
- elems = into.CopyAsArray();
-flat_enough:;
- }
- P6opaque nj = new P6opaque(Compartment.Top.JunctionMO);
- nj.slots[0] = Kernel.BoxRaw(type, Compartment.Top.IntMO);
- nj.slots[1] = Kernel.BoxRaw(elems, Compartment.Top.ParcelMO);
- return nj;
- }
-
public static Variable Make(Frame fr, Variable v) {
if (fr.info.name == "CORE make")
fr = fr.caller;
@@ -1757,24 +1737,25 @@ public partial class Builtins {
public static VarDeque HashIterRaw(int mode, Variable v) {
P6any o = NominalCheck("$x", v);
VarHash d = Kernel.UnboxAny<VarHash>(o);
+ var s = o.mo.setting;
VarDeque lv = new VarDeque();
foreach (KeyValuePair<string,Variable> kv in d) {
switch (mode) {
case 0:
- lv.Push(Kernel.BoxAnyMO<string>(kv.Key, Compartment.Top.StrMO));
+ lv.Push(s.MakeStr(kv.Key));
break;
case 1:
lv.Push(kv.Value);
break;
case 2:
- lv.Push(Kernel.BoxAnyMO<string>(kv.Key, Compartment.Top.StrMO));
+ lv.Push(s.MakeStr(kv.Key));
lv.Push(kv.Value);
break;
case 3:
- P6opaque p = new P6opaque(Compartment.Top.PairMO);
- p.slots[0] = Kernel.BoxAnyMO<string>(kv.Key, Compartment.Top.StrMO);
+ P6opaque p = new P6opaque(s.PairMO);
+ p.slots[0] = s.MakeStr(kv.Key);
p.slots[1] = kv.Value;
lv.Push(p);
break;
@@ -1965,27 +1946,6 @@ public partial class Builtins {
return PosixWrapper.getuid() == (uint)stat[5];
}
- public static P6any MakeList(VarDeque items, VarDeque rest) {
- P6any l = new P6opaque(Compartment.Top.ListMO);
- l.SetSlot(Compartment.Top.ListMO, "$!rest", rest);
- l.SetSlot(Compartment.Top.ListMO, "$!items", items);
- return l;
- }
-
- public static P6any MakeArray(VarDeque items, VarDeque rest) {
- P6any l = new P6opaque(Compartment.Top.ArrayMO);
- l.SetSlot(Compartment.Top.ListMO, "$!rest", rest);
- l.SetSlot(Compartment.Top.ListMO, "$!items", items);
- return l;
- }
-
- public static Variable BoxLoS(string[] los) {
- VarDeque items = new VarDeque();
- foreach (string i in los)
- items.Push(Kernel.BoxAnyMO(i, Compartment.Top.StrMO));
- return Kernel.NewRWListVar(MakeList(items, new VarDeque()));
- }
-
public static string[] UnboxLoS(Variable args) {
List<string> la = new List<string>();
VarDeque iter = start_iter(args);
@@ -2065,12 +2025,12 @@ public partial class Builtins {
return new VarDeque(thing);
}
- public static Variable array_constructor(Variable bits) {
+ [ImplicitConsts] public static Variable array_constructor(Constants c, Variable bits) {
VarDeque rest = start_iter(bits);
VarDeque items = new VarDeque();
while (Kernel.IterHasFlat(rest, true))
items.Push(Kernel.NewMuScalar(rest.Shift().Fetch()));
- return MakeArray(items, rest);
+ return c.setting.MakeArray(items, rest);
}
public static string frame_subname(Frame fr) {
@@ -2519,7 +2479,7 @@ class CrossSource: ItemSource {
[ImplicitConsts] public static Variable sysquery(Constants c, int ix) {
var s = c.setting;
switch (ix) {
- case 0: return BoxLoS(Kernel.commandArgs);
+ case 0: return s.BoxLoS(Kernel.commandArgs);
case 1: return s.MakeStr(programName ?? AppDomain.CurrentDomain.FriendlyName);
case 2: return s.MakeStr(execName);
case 3: return s.MakeStr(AppDomain.CurrentDomain.BaseDirectory);
@@ -2672,7 +2632,7 @@ class CrossSource: ItemSource {
return ret;
}
- public static Variable dir(string s) {
+ [ImplicitConsts] public static Variable dir(Constants c, string s) {
string[] raw = Directory.GetFileSystemEntries(s);
string[] forperl = new string[raw.Length + 2];
forperl[0] = "."; forperl[1] = "..";
@@ -2680,7 +2640,7 @@ class CrossSource: ItemSource {
int ix = raw[i].LastIndexOf(Path.DirectorySeparatorChar);
forperl[i+2] = (ix >= 0) ? raw[i].Substring(ix+1) : raw[i];
}
- return BoxLoS(forperl);
+ return c.setting.BoxLoS(forperl);
}
public static Thread start_p6_thread(P6any sub) {
@@ -2926,10 +2886,10 @@ public class Blackhole : Variable {
return new Blackhole(o.Fetch());
}
- public static Variable sig_params(P6any sig) {
+ [ImplicitConsts] public static Variable sig_params(Constants c, P6any sig) {
VarDeque items = new VarDeque();
items.PushN(((Signature)sig).parms);
- return Kernel.NewRWListVar(MakeList(items, new VarDeque()));
+ return Kernel.NewRWListVar(c.setting.MakeList(items, new VarDeque()));
}
public static string code_name(P6any obj) {
@@ -2951,15 +2911,15 @@ public class Blackhole : Variable {
} else {
items.Push(sub);
}
- return Kernel.NewRWListVar(MakeList(items, new VarDeque()));
+ return Kernel.NewRWListVar(si.setting.MakeList(items, new VarDeque()));
}
public static int param_flags(P6any param) {
return ((Parameter)param).flags;
}
- public static Variable param_names(P6any param) {
- return BoxLoS(((Parameter)param).names ?? new string[0]);
+ [ImplicitConsts] public static Variable param_names(Constants c, P6any param) {
+ return c.setting.BoxLoS(((Parameter)param).names ?? new string[0]);
}
[ImplicitConsts] public static Variable param_type(Constants c, P6any param) {
@@ -2986,7 +2946,7 @@ public class Blackhole : Variable {
items.Push((Variable)o);
}
}
- return Kernel.NewRWListVar(MakeList(items, new VarDeque()));
+ return Kernel.NewRWListVar(param.mo.setting.MakeList(items, new VarDeque()));
}
public static string param_name(P6any param) {
@@ -3111,4 +3071,8 @@ public class Blackhole : Variable {
[ImplicitConsts] public static Variable newhash(Constants c) {
return c.setting.CreateHash();
}
+
+ public static Variable MakeJunction(Constants c, int type, Variable[] args) {
+ return c.setting.MakeJunction(type, args);
+ }
}
View
1  lib/CodeGen.cs
@@ -2635,6 +2635,7 @@ class NamProcessor {
handlers["makejunction"] = delegate(NamProcessor th, object[] zyg) {
return CpsOp.MethodCall(
Tokens.Builtins.GetMethod("MakeJunction"),
+ CpsOp.Constants(),
CpsOp.IntLiteral(JScalar.I(zyg[1])),
CpsOp.NewArray(Tokens.Variable, JScalar.A<CpsOp>(2, zyg, th.Scan)));
};
View
4 lib/JSYNC.cs
@@ -340,7 +340,7 @@ public class JsyncReader {
}
SkipWhite(true);
SkipChar(']');
- return Builtins.MakeArray(q, new VarDeque());
+ return setting.MakeArray(q, new VarDeque());
} else if (look == '{') {
VarHash q = new VarHash();
int ct = 0;
@@ -495,7 +495,7 @@ public class JsyncReader {
Variable GetFromArray() {
SkipCharWS('[');
VarDeque kids = new VarDeque();
- P6any obj = Builtins.MakeArray(kids, new VarDeque());
+ P6any obj = setting.MakeArray(kids, new VarDeque());
bool comma = false;
string a_tag = null;
View
41 lib/Kernel.cs
@@ -4696,6 +4696,26 @@ public class Compartment {
return Kernel.NewRWListVar(v);
}
+ public P6any MakeList(VarDeque items, VarDeque rest) {
+ P6any l = new P6opaque(ListMO);
+ l.SetSlot(ListMO, "$!rest", rest);
+ l.SetSlot(ListMO, "$!items", items);
+ return l;
+ }
+
+ public P6any MakeArray(VarDeque items, VarDeque rest) {
+ P6any l = new P6opaque(ArrayMO);
+ l.SetSlot(ListMO, "$!rest", rest);
+ l.SetSlot(ListMO, "$!items", items);
+ return l;
+ }
+
+ public Variable BoxLoS(string[] los) {
+ VarDeque items = new VarDeque();
+ foreach (string i in los) items.Push(MakeStr(i));
+ return Kernel.NewRWListVar(MakeList(items, new VarDeque()));
+ }
+
public Variable MakeAppropriateVar(string name) {
if (name.Length >= 1 && name[0] == '@')
return CreateArray();
@@ -4792,6 +4812,26 @@ public class Compartment {
public Variable MakeParcel(params Variable[] bits) {
return Kernel.NewRWListVar(Kernel.BoxRaw(bits, ParcelMO));
}
+
+ public Variable MakeJunction(int type, Variable[] elems) {
+ if (type >= 8) {
+ type -= 8;
+ foreach (Variable e in elems)
+ if (e.List) goto need_flatten;
+ goto flat_enough;
+ need_flatten:;
+ VarDeque iter = new VarDeque(elems);
+ VarDeque into = new VarDeque();
+ while (Kernel.IterHasFlat(iter, true))
+ into.Push(iter.Shift());
+ elems = into.CopyAsArray();
+ flat_enough:;
+ }
+ P6opaque nj = new P6opaque(JunctionMO);
+ nj.slots[0] = Kernel.BoxRaw(type, IntMO);
+ nj.slots[1] = Kernel.BoxRaw(elems, ParcelMO);
+ return nj;
+ }
}
class PhaserList {
@@ -6449,6 +6489,7 @@ class LastFrameNode {
// TODO: possibly should make X::AdHoc?
if (type == SubInfo.ON_DIE) {
payload = Kernel.NewRWListVar(Builtins.array_constructor(
+ new Constants { setting = s },
(Variable)payload).Fetch());
}
Please sign in to comment.
Something went wrong with that request. Please try again.