Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move remaining [CompartmentGlobal]s into Compartment and retire Compa…

…rtmentGlobal system
  • Loading branch information...
commit c3c572b1cac87b8ff49860749aa9617de4c9f553 1 parent 2ae0f72
@sorear authored
Showing with 23 additions and 72 deletions.
  1. +1 −3 lib/Builtins.cs
  2. +4 −6 lib/Cursor.cs
  3. +7 −52 lib/Kernel.cs
  4. +11 −11 lib/NieczaCLR.cs
View
4 lib/Builtins.cs
@@ -1883,10 +1883,8 @@ public partial class Builtins {
return la.ToArray();
}
- [CompartmentGlobal]
- internal static Dictionary<string,SubInfo> setting_path;
public static Frame you_are_here(Frame th, string sname) {
- P6any to_call = Kernel.MakeSub(setting_path[sname], th);
+ P6any to_call = Kernel.MakeSub(Compartment.Top.setting_path[sname], th);
return to_call.Invoke(th, Variable.None, null);
}
View
10 lib/Cursor.cs
@@ -222,13 +222,14 @@ public sealed class RxFrame: IFreeze {
if (Cursor.Trace)
Console.WriteLine("Failing {0}@{1} after some matches",
name, from);
- if (EmptyList == null) {
+ var c = Compartment.Top;
+ if (c.EmptyList == null) {
P6opaque lst = new P6opaque(Compartment.Top.ListMO);
lst.slots[0 /*items*/] = new VarDeque();
lst.slots[1 /*rest*/ ] = new VarDeque();
- EmptyList = Kernel.NewRWListVar(lst);
+ c.EmptyList = Kernel.NewRWListVar(lst);
}
- th.caller.resultSlot = EmptyList;
+ th.caller.resultSlot = c.EmptyList;
}
return th.Return();
@@ -728,9 +729,6 @@ public sealed class RxFrame: IFreeze {
return global.CallAction(th, name, _matchObj);
}
- [CompartmentGlobal]
- public static Variable EmptyList;
-
public Frame FinalEnd(Frame th) {
if (st.pos > global.highwater)
global.IncHighwater(st.pos);
View
59 lib/Kernel.cs
@@ -398,20 +398,12 @@ public class StashEnt : IFreeze {
// changed under the direct control of Perl 6 code. They may leak some
// information such as random number seeds. They may NOT point at Perl 6
// level objects.
- //
- // [CompartmentGlobal] fields are unrestricted in usage, but are always
- // automatically saved and restored when manipulating the container stack.
- //
- // [CORESaved] fields are the same as CompartmentGlobal but are additionally
- // saved in CORE.ser.
[AttributeUsage(AttributeTargets.Field)]
class CORESavedAttribute : Attribute { }
[AttributeUsage(AttributeTargets.Field)]
class ImmutableAttribute : Attribute { }
[AttributeUsage(AttributeTargets.Field)]
- class CompartmentGlobalAttribute : Attribute { }
- [AttributeUsage(AttributeTargets.Field)]
class TrueGlobalAttribute : Attribute { }
// Boxes all per-dll state required by the code generator
@@ -820,10 +812,10 @@ public sealed class RuntimeUnit : IFreeze {
internal void RunMainline() {
RuntimeUnit csr = this;
- Builtins.setting_path = new Dictionary<string,SubInfo>();
+ Compartment.Top.setting_path = new Dictionary<string,SubInfo>();
while (csr.mainline.outer != null) {
RuntimeUnit o = csr.mainline.outer.unit;
- Builtins.setting_path[o.name] = csr.mainline;
+ Compartment.Top.setting_path[o.name] = csr.mainline;
csr = o;
}
@@ -4528,8 +4520,6 @@ public struct StashCursor {
}
class Compartment {
- [Immutable] static readonly FieldInfo[] fieldsToSave;
-
[CORESaved] public STable PairMO;
[CORESaved] public STable EnumMO;
[CORESaved] public STable EnumMapMO;
@@ -4609,28 +4599,13 @@ class Compartment {
// an eval or such.
internal RuntimeUnit containerRootUnit;
- static Compartment() {
- var typesToCheck = new Type[] {
- typeof(Kernel), typeof(RuntimeUnit), typeof(CLRWrapperProvider),
- typeof(RxFrame), typeof(Builtins)
- };
-
- List<FieldInfo> fields = new List<FieldInfo>();
- foreach (Type ty in typesToCheck) {
- foreach (FieldInfo fi in ty.GetFields(BindingFlags.NonPublic |
- BindingFlags.Public | BindingFlags.Static)) {
- foreach (object o in fi.GetCustomAttributes(true)) {
- if (o is CORESavedAttribute) goto saveme;
- if (o is CompartmentGlobalAttribute) goto saveme;
- }
- continue;
-saveme:
- fields.Add(fi);
- }
- }
- fieldsToSave = fields.ToArray();
+ internal Dictionary<string,SubInfo> setting_path;
+ internal Variable EmptyList;
+ internal Dictionary<Type, STable> wrapper_cache;
+ internal Dictionary<string, STable> named_wrapper_cache;
+ static Compartment() {
AppDomain.CurrentDomain.ProcessExit += BeforeExit;
}
@@ -4646,7 +4621,6 @@ class Compartment {
}
Compartment prev;
- object[] saved_values;
private Compartment() { }
[TrueGlobal]
@@ -4659,12 +4633,6 @@ class Compartment {
internal static void Push() {
Compartment n = new Compartment();
n.prev = Top;
- n.saved_values = new object[fieldsToSave.Length];
-
- for (int i = 0; i < fieldsToSave.Length; i++) {
- n.saved_values[i] = fieldsToSave[i].GetValue(null);
- fieldsToSave[i].SetValue(null, null);
- }
Top = n;
Kernel.InitCompartment();
@@ -4672,15 +4640,6 @@ class Compartment {
internal static void Pop() {
Top.end.Run();
-
- for (int i = 0; i < fieldsToSave.Length; i++) {
- fieldsToSave[i].SetValue(null, Top.saved_values[i]);
- }
-
- if (Compartment.Top.containerRootUnit != null) {
- foreach (RuntimeUnit ru in Compartment.Top.containerRootUnit.depended_units)
- ru.SetConstants();
- }
Top = Top.prev;
}
}
@@ -6590,10 +6549,6 @@ class LastFrameNode {
// already classified
if (fi.GetCustomAttributes(typeof(ImmutableAttribute), true).Length != 0)
continue;
- if (fi.GetCustomAttributes(typeof(CORESavedAttribute), true).Length != 0)
- continue;
- if (fi.GetCustomAttributes(typeof(CompartmentGlobalAttribute), true).Length != 0)
- continue;
if (fi.GetCustomAttributes(typeof(TrueGlobalAttribute), true).Length != 0)
continue;
// ignore effectively constant fields
View
22 lib/NieczaCLR.cs
@@ -488,17 +488,16 @@ class OverloadCandidate : MultiCandidate {
public class CLRWrapperProvider {
[TrueGlobal] static object wrapper_cache_lock = new object();
- [CompartmentGlobal] static Dictionary<Type, STable> wrapper_cache;
- [CompartmentGlobal] static Dictionary<string, STable> named_wrapper_cache;
public static STable GetWrapper(Type t) {
+ var c = Compartment.Top;
lock (wrapper_cache_lock) {
- if (wrapper_cache == null)
- wrapper_cache = new Dictionary<Type, STable>();
+ if (c.wrapper_cache == null)
+ c.wrapper_cache = new Dictionary<Type, STable>();
STable r;
- if (wrapper_cache.TryGetValue(t, out r))
+ if (c.wrapper_cache.TryGetValue(t, out r))
return r;
- wrapper_cache[t] = r = NewWrapper(t);
+ c.wrapper_cache[t] = r = NewWrapper(t);
return r;
}
}
@@ -508,19 +507,20 @@ public class CLRWrapperProvider {
}
public static STable GetNamedWrapper(string nm) {
+ var c = Compartment.Top;
lock (wrapper_cache_lock) {
- if (named_wrapper_cache == null)
- named_wrapper_cache = new Dictionary<string, STable>();
+ if (c.named_wrapper_cache == null)
+ c.named_wrapper_cache = new Dictionary<string, STable>();
STable r;
- if (named_wrapper_cache.TryGetValue(nm, out r))
+ if (c.named_wrapper_cache.TryGetValue(nm, out r))
return r;
Type ty = Type.GetType(nm.Substring(1));
if (CLROpts.Debug)
Console.WriteLine("Loading type {0} ... {1}", nm.Substring(1), ty == null ? "failed" : "succeeded");
if (ty != null) {
- named_wrapper_cache[nm] = r = GetWrapper(ty);
+ c.named_wrapper_cache[nm] = r = GetWrapper(ty);
} else {
- named_wrapper_cache[nm] = r = StashCursor.MakePackage(
+ c.named_wrapper_cache[nm] = r = StashCursor.MakePackage(
"CLR" + nm.Replace(".","::"),
StashCursor.MakeCLR_WHO(nm)).Fetch().mo;
}
Please sign in to comment.
Something went wrong with that request. Please try again.