Skip to content

Commit

Permalink
Generate slot mappings at compose time
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Sep 10, 2010
1 parent e893836 commit 63628e6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 18 deletions.
1 change: 1 addition & 0 deletions lib/CORE.setting
Expand Up @@ -8,6 +8,7 @@ sub slurp($path) {
}
my class IO is Cool {
has $!value;
}
my class TextReader is IO {
Expand Down
45 changes: 27 additions & 18 deletions lib/Kernel.cs
Expand Up @@ -303,19 +303,14 @@ public List<DynMetaObject> superclasses
= new List<DynMetaObject>();
public Dictionary<string, IP6> local
= new Dictionary<string, IP6>();
public Dictionary<string, IP6> local_attr
= new Dictionary<string, IP6>();
public List<string> local_attr = new List<string>();

public Dictionary<string, int> slotMap = new Dictionary<string, int>();
public int nslots = 0;

public int FindSlot(string name) {
int v;
//Kernel.LogNameLookup(name);
if (slotMap.TryGetValue(name, out v))
return v;
else
return slotMap[name] = nslots++;
return slotMap[name];
}

public Dictionary<string, List<DynObject>> multiregex;
Expand Down Expand Up @@ -391,13 +386,15 @@ public List<DynMetaObject> superclasses
}

public void AddAttribute(string name) {
local_attr[name] = null;
local_attr.Add(name);
}

public void AddSuperclass(DynMetaObject other) {
superclasses.Add(other);
}

// this gets called more than once for Scalar, ClassHOW, and Sub
// just be sure that the attrib list doesn't change
public void Complete() {
List<List<DynMetaObject>> toMerge = new List<List<DynMetaObject>>();
mro = new List<DynMetaObject>();
Expand Down Expand Up @@ -453,7 +450,14 @@ public List<DynMetaObject> superclasses
throw new Exception("C3 MRO inconsistency detected");
}
}
return;
break;
}

nslots = 0;
foreach (DynMetaObject k in mro) {
foreach (string an in k.local_attr) {
slotMap[an] = nslots++;
}
}
}
}
Expand Down Expand Up @@ -483,15 +487,11 @@ public class DynObject: IP6 {
}

public void SetSlot(string name, object obj) {
int ix = klass.FindSlot(name);
if (ix >= slots.Length)
Array.Resize(ref slots, ix+1);
slots[klass.FindSlot(name)] = obj;
}

public object GetSlot(string name) {
int ix = klass.FindSlot(name);
return (ix >= slots.Length) ? null : slots[ix];
return slots[klass.FindSlot(name)];
}

public override bool IsDefined() {
Expand Down Expand Up @@ -813,7 +813,7 @@ public class Kernel {
List<DynMetaObject> mro = n.klass.mro;

for (int i = mro.Count - 1; i >= 0; i--) {
foreach (string s in mro[i].local_attr.Keys) {
foreach (string s in mro[i].local_attr) {
n.SetSlot(s, NewRWScalar(AnyP));
}
}
Expand All @@ -839,7 +839,7 @@ public class Kernel {
public static IP6 AnyP;
public static IP6 ArrayP;
public static IP6 HashP;
public static IP6 StrP = new DynObject(new DynMetaObject("proto-Str"));
public static IP6 StrP;
public static DynMetaObject CallFrameMO;

public static Variable PackageLookup(IP6 parent, string name) {
Expand Down Expand Up @@ -909,12 +909,21 @@ public class Kernel {
public static IP6 ProcessO;

static Kernel() {
DynMetaObject pStrMO = new DynMetaObject("protoStr");
pStrMO.AddAttribute("value");
pStrMO.Complete();
StrP = new DynObject(pStrMO);

SubMO = new DynMetaObject("Sub");
SubMO.OnInvoke = new DynMetaObject.InvokeHandler(SubInvoke);
SubMO.local["INVOKE"] = MakeSub(SubInvokeSubSI, null);
SubMO.AddAttribute("outer");
SubMO.AddAttribute("info");
SubMO.Complete();
SubMO.AddMethod("INVOKE", MakeSub(SubInvokeSubSI, null));

ScalarMO = new DynMetaObject("Scalar");
ScalarMO.FindSlot("value");
ScalarMO.AddAttribute("value");
ScalarMO.Complete();
ScalarMO.OnFetch = new DynMetaObject.FetchHandler(SCFetch);
ScalarMO.OnStore = new DynMetaObject.StoreHandler(SCStore);

Expand Down
1 change: 1 addition & 0 deletions lib/SAFE.setting
Expand Up @@ -76,6 +76,7 @@ PRE-INIT {
chhow [null DynObject]
chhvar [null Variable]
[rawcall (l chdmo) AddAttribute (s value)]
[rawcall (l chdmo) Complete]

[l chhow (rawnew DynObject (l chdmo))]
[l chhvar (ns (l chhow))]
Expand Down
1 change: 1 addition & 0 deletions lib/Threads.pm6
Expand Up @@ -22,6 +22,7 @@ my class Monitor is export {
sub lock($m,$f) is export { $m.lock($f); }

my class Thread is export {
has $!value;
method new($func) {
Q:CgOp { (box Thread (rawsccall
Kernel.StartP6Thread:c,System.Threading.Thread (@ (l $func)))) }
Expand Down

0 comments on commit 63628e6

Please sign in to comment.