Browse files

Fix over-eager caching of method handlers, colomon++

  • Loading branch information...
1 parent b344401 commit d8852de8b0b30ed2b96601e5ab21aa07ecb5a330 @sorear committed Sep 22, 2012
Showing with 83 additions and 81 deletions.
  1. +56 −0 lib/Kernel.cs
  2. +27 −81 lib/ObjModel.cs
View
56 lib/Kernel.cs
@@ -4615,6 +4615,35 @@ class Compartment {
internal Dictionary<Type, STable> wrapper_cache;
internal Dictionary<string, STable> named_wrapper_cache;
+ /// well-known context handlers {{{
+ public ContextHandler<Variable> CallStr;
+ public ContextHandler<Variable> CallBool;
+ public ContextHandler<Variable> CallNumeric;
+ public ContextHandler<Variable> CallDefined;
+ public ContextHandler<Variable> CallIterator;
+ public ContextHandler<Variable> CallItem;
+ public ContextHandler<Variable> CallList;
+ public ContextHandler<Variable> CallHash;
+ public ContextHandler<Variable> CallShift;
+ public ContextHandler<Variable> CallPop;
+ public ContextHandler<P6any> CallPred;
+ public ContextHandler<P6any> CallSucc;
+ public ContextHandler<string> RawCallStr;
+ public ContextHandler<bool> RawCallBool;
+ public ContextHandler<double> RawCallNumeric;
+ public ContextHandler<bool> RawCallDefined;
+ public ContextHandler<VarDeque> RawCallIterator;
+ public ContextHandler<Variable[]> RawCallReify;
+ public IndexHandler CallAtPos;
+ public IndexHandler CallAtKey;
+ public IndexHandler CallExistsKey;
+ public IndexHandler CallDeleteKey;
+ public IndexHandler CallLISTSTORE;
+ public InvokeHandler CallINVOKE;
+ public PushyHandler CallPush;
+ public PushyHandler CallUnshift;
+ /// }}}
+
static Compartment() {
AppDomain.CurrentDomain.ProcessExit += BeforeExit;
}
@@ -4865,6 +4894,33 @@ public class Kernel {
2, 3, SubInfo.ON_REDO, 1, 0,
2, 3, SubInfo.ON_LAST, 3, 0,
}, new string[] { "" }, 0);
+
+ c.CallStr = new CtxCallMethod("Str");
+ c.CallBool = new CtxCallMethod("Bool");
+ c.CallNumeric = new CtxCallMethod("Numeric");
+ c.CallDefined = new CtxCallMethod("defined");
+ c.CallIterator = new CtxCallMethod("iterator");
+ c.CallItem = new CtxCallMethod("item");
+ c.CallList = new CtxCallMethod("list");
+ c.CallHash = new CtxCallMethod("hash");
+ c.CallShift = new CtxCallMethod("shift");
+ c.CallPop = new CtxCallMethod("pop");
+ c.CallPred = new CtxCallMethodFetch("pred");
+ c.CallSucc = new CtxCallMethodFetch("succ");
+ c.RawCallStr = new CtxCallMethodUnbox<string>("Str");
+ c.RawCallBool = new CtxCallMethodUnboxBool("Bool");
+ c.RawCallNumeric = new CtxCallMethodUnboxNumeric("Numeric");
+ c.RawCallDefined = new CtxCallMethodUnboxBool("defined");
+ c.RawCallIterator = new CtxCallMethodUnbox<VarDeque>("iterator");
+ c.RawCallReify = new CtxCallMethodUnbox<Variable[]>("reify");
+ c.CallAtPos = new IxCallMethod("postcircumfix:<[ ]>", null);
+ c.CallAtKey = new IxCallMethod("postcircumfix:<{ }>", null);
+ c.CallExistsKey = new IxCallMethod("postcircumfix:<{ }>", "exists");
+ c.CallDeleteKey = new IxCallMethod("postcircumfix:<{ }>", "delete");
+ c.CallLISTSTORE = new IxCallMethod("LISTSTORE", null);
+ c.CallINVOKE = new InvokeCallMethod();
+ c.CallPush = new PushyCallMethod("push");
+ c.CallUnshift = new PushyCallMethod("unshift");
}
public static P6any MakeSub(SubInfo info, Frame outer) {
View
108 lib/ObjModel.cs
@@ -834,61 +834,6 @@ public class DispatchSet {
// (Although due to quirks of the C# implementation, Cursor and
// BoxObject can share the P6opaque STable)
public class STable: IFreeze {
- /// well-known context handlers {{{
- public static readonly ContextHandler<Variable> CallStr
- = new CtxCallMethod("Str");
- public static readonly ContextHandler<Variable> CallBool
- = new CtxCallMethod("Bool");
- public static readonly ContextHandler<Variable> CallNumeric
- = new CtxCallMethod("Numeric");
- public static readonly ContextHandler<Variable> CallDefined
- = new CtxCallMethod("defined");
- public static readonly ContextHandler<Variable> CallIterator
- = new CtxCallMethod("iterator");
- public static readonly ContextHandler<Variable> CallItem
- = new CtxCallMethod("item");
- public static readonly ContextHandler<Variable> CallList
- = new CtxCallMethod("list");
- public static readonly ContextHandler<Variable> CallHash
- = new CtxCallMethod("hash");
- public static readonly ContextHandler<Variable> CallShift
- = new CtxCallMethod("shift");
- public static readonly ContextHandler<Variable> CallPop
- = new CtxCallMethod("pop");
- public static readonly ContextHandler<P6any> CallPred
- = new CtxCallMethodFetch("pred");
- public static readonly ContextHandler<P6any> CallSucc
- = new CtxCallMethodFetch("succ");
- public static readonly ContextHandler<string> RawCallStr
- = new CtxCallMethodUnbox<string>("Str");
- public static readonly ContextHandler<bool> RawCallBool
- = new CtxCallMethodUnboxBool("Bool");
- public static readonly ContextHandler<double> RawCallNumeric
- = new CtxCallMethodUnboxNumeric("Numeric");
- public static readonly ContextHandler<bool> RawCallDefined
- = new CtxCallMethodUnboxBool("defined");
- public static readonly ContextHandler<VarDeque> RawCallIterator
- = new CtxCallMethodUnbox<VarDeque>("iterator");
- public static readonly ContextHandler<Variable[]> RawCallReify
- = new CtxCallMethodUnbox<Variable[]>("reify");
- public static readonly IndexHandler CallAtPos
- = new IxCallMethod("postcircumfix:<[ ]>", null);
- public static readonly IndexHandler CallAtKey
- = new IxCallMethod("postcircumfix:<{ }>", null);
- public static readonly IndexHandler CallExistsKey
- = new IxCallMethod("postcircumfix:<{ }>", "exists");
- public static readonly IndexHandler CallDeleteKey
- = new IxCallMethod("postcircumfix:<{ }>", "delete");
- public static readonly IndexHandler CallLISTSTORE
- = new IxCallMethod("LISTSTORE", null);
- public static readonly InvokeHandler CallINVOKE
- = new InvokeCallMethod();
- public static readonly PushyHandler CallPush
- = new PushyCallMethod("push");
- public static readonly PushyHandler CallUnshift
- = new PushyCallMethod("unshift");
- /// }}}
-
/// "true" state {{{
public P6how mo;
@@ -981,34 +926,35 @@ public class STable: IFreeze {
}
internal void SetupVTables() {
- mro_push = _GetVT("push") as PushyHandler ?? CallPush;
- mro_unshift = _GetVT("unshift") as PushyHandler ?? CallUnshift;
- mro_shift = _GetVT("shift") as ContextHandler<Variable> ?? CallShift;
- mro_pop = _GetVT("pop") as ContextHandler<Variable> ?? CallPop;
- mro_at_key = _GetVTi("postcircumfix:<{ }>", 0) as IndexHandler ?? CallAtKey;
- mro_at_pos = _GetVTi("postcircumfix:<[ ]>", 0) as IndexHandler ?? CallAtPos;
+ var s = Compartment.Top;
+ mro_push = _GetVT("push") as PushyHandler ?? s.CallPush;
+ mro_unshift = _GetVT("unshift") as PushyHandler ?? s.CallUnshift;
+ mro_shift = _GetVT("shift") as ContextHandler<Variable> ?? s.CallShift;
+ mro_pop = _GetVT("pop") as ContextHandler<Variable> ?? s.CallPop;
+ mro_at_key = _GetVTi("postcircumfix:<{ }>", 0) as IndexHandler ?? s.CallAtKey;
+ mro_at_pos = _GetVTi("postcircumfix:<[ ]>", 0) as IndexHandler ?? s.CallAtPos;
mro_bind_key = _GetVTi("postcircumfix:<{ }>", 3) as BindHandler;
mro_bind_pos = _GetVTi("postcircumfix:<[ ]>", 3) as BindHandler;
- mro_LISTSTORE = _GetVT("LISTSTORE") as IndexHandler ?? CallLISTSTORE;
- mro_Bool = _GetVT("Bool") as ContextHandler<Variable> ?? CallBool;
- mro_defined = _GetVT("defined") as ContextHandler<Variable> ?? CallDefined;
- mro_delete_key = _GetVTi("postcircumfix:<{ }>", 2) as IndexHandler ?? CallDeleteKey;
- mro_exists_key = _GetVTi("postcircumfix:<{ }>", 1) as IndexHandler ?? CallExistsKey;
- mro_hash = _GetVT("hash") as ContextHandler<Variable> ?? CallHash;
- mro_INVOKE = _GetVT("postcircumfix:<( )>") as InvokeHandler ?? CallINVOKE;
- mro_item = _GetVT("item") as ContextHandler<Variable> ?? CallItem;
- mro_iterator = _GetVT("iterator") as ContextHandler<Variable> ?? CallIterator;
- mro_list = _GetVT("list") as ContextHandler<Variable> ?? CallList;
- mro_Numeric = _GetVT("Numeric") as ContextHandler<Variable> ?? CallNumeric;
- mro_pred = _GetVTU("pred") as ContextHandler<P6any> ?? CallPred;
- mro_raw_Bool = _GetVTU("Bool") as ContextHandler<bool> ?? RawCallBool;
- mro_raw_defined = _GetVTU("defined") as ContextHandler<bool> ?? RawCallDefined;
- mro_raw_iterator = _GetVTU("iterator") as ContextHandler<VarDeque> ?? RawCallIterator;
- mro_raw_Numeric = _GetVTU("Numeric") as ContextHandler<double> ?? RawCallNumeric;
- mro_raw_reify = _GetVT("reify") as ContextHandler<Variable[]> ?? RawCallReify;
- mro_raw_Str = _GetVTU("Str") as ContextHandler<string> ?? RawCallStr;
- mro_Str = _GetVT("Str") as ContextHandler<Variable> ?? CallStr;
- mro_succ = _GetVTU("succ") as ContextHandler<P6any> ?? CallSucc;
+ mro_LISTSTORE = _GetVT("LISTSTORE") as IndexHandler ?? s.CallLISTSTORE;
+ mro_Bool = _GetVT("Bool") as ContextHandler<Variable> ?? s.CallBool;
+ mro_defined = _GetVT("defined") as ContextHandler<Variable> ?? s.CallDefined;
+ mro_delete_key = _GetVTi("postcircumfix:<{ }>", 2) as IndexHandler ?? s.CallDeleteKey;
+ mro_exists_key = _GetVTi("postcircumfix:<{ }>", 1) as IndexHandler ?? s.CallExistsKey;
+ mro_hash = _GetVT("hash") as ContextHandler<Variable> ?? s.CallHash;
+ mro_INVOKE = _GetVT("postcircumfix:<( )>") as InvokeHandler ?? s.CallINVOKE;
+ mro_item = _GetVT("item") as ContextHandler<Variable> ?? s.CallItem;
+ mro_iterator = _GetVT("iterator") as ContextHandler<Variable> ?? s.CallIterator;
+ mro_list = _GetVT("list") as ContextHandler<Variable> ?? s.CallList;
+ mro_Numeric = _GetVT("Numeric") as ContextHandler<Variable> ?? s.CallNumeric;
+ mro_pred = _GetVTU("pred") as ContextHandler<P6any> ?? s.CallPred;
+ mro_raw_Bool = _GetVTU("Bool") as ContextHandler<bool> ?? s.RawCallBool;
+ mro_raw_defined = _GetVTU("defined") as ContextHandler<bool> ?? s.RawCallDefined;
+ mro_raw_iterator = _GetVTU("iterator") as ContextHandler<VarDeque> ?? s.RawCallIterator;
+ mro_raw_Numeric = _GetVTU("Numeric") as ContextHandler<double> ?? s.RawCallNumeric;
+ mro_raw_reify = _GetVT("reify") as ContextHandler<Variable[]> ?? s.RawCallReify;
+ mro_raw_Str = _GetVTU("Str") as ContextHandler<string> ?? s.RawCallStr;
+ mro_Str = _GetVT("Str") as ContextHandler<Variable> ?? s.CallStr;
+ mro_succ = _GetVTU("succ") as ContextHandler<P6any> ?? s.CallSucc;
mro_to_clr = _GetVT("to-clr") as ContextHandler<object>;
if (Compartment.Top.ComplexMO != null && HasType(Compartment.Top.ComplexMO))

0 comments on commit d8852de

Please sign in to comment.