Permalink
Browse files

Checkpoint of global-variable inventory

  • Loading branch information...
1 parent 8edc022 commit cdb4548c8308e6984605ca958696e4a5f344a8e7 @sorear committed Oct 23, 2011
Showing with 77 additions and 95 deletions.
  1. +2 −2 lib/BigInteger.cs
  2. +9 −8 lib/Builtins.cs
  3. +9 −29 lib/CodeGen.cs
  4. +12 −9 lib/Cursor.cs
  5. +1 −1 lib/JSYNC.cs
  6. +30 −40 lib/Kernel.cs
  7. +5 −2 lib/NieczaCLR.cs
  8. +7 −4 lib/Serialize.cs
  9. +2 −0 lib/Utils.cs
View
4 lib/BigInteger.cs
@@ -71,8 +71,8 @@ public struct BigInteger : IComparable, IFormattable, IComparable<BigInteger>, I
readonly uint[] data;
readonly short sign;
- static readonly uint[] ZERO = new uint [1];
- static readonly uint[] ONE = new uint [1] { 1 };
+ [Immutable] static readonly uint[] ZERO = new uint [1];
+ [Immutable] static readonly uint[] ONE = new uint [1] { 1 };
public BigInteger (short sign, uint[] data)
{
View
17 lib/Builtins.cs
@@ -961,10 +961,8 @@ public partial class Builtins {
return Kernel.NewROScalar(n1);
}
- static IForeignInterpreter p5_interpreter;
+ [TrueGlobal] static IForeignInterpreter p5_interpreter;
public static Variable eval_perl5(Variable v) {
-
- // Cargo culted to get the string from the argument
P6any o1 = v.Fetch();
string r = o1.mo.mro_raw_Str.Get(v);
@@ -1520,6 +1518,7 @@ public partial class Builtins {
return MakeParcel(ret);
}
+ [TrueGlobal]
private static Random rng = new Random();
public static Variable rand() {
@@ -1614,6 +1613,7 @@ public partial class Builtins {
return la.ToArray();
}
+ [ContainerGlobal]
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);
@@ -1624,9 +1624,9 @@ public partial class Builtins {
System.Diagnostics.Process.Start(file, args).WaitForExit();
}
- internal static AppDomain up_domain;
- internal static RuntimeUnit eval_result;
- static System.Collections.IDictionary upcall_receiver;
+ [TrueGlobal] internal static AppDomain up_domain;
+ [TrueGlobal] internal static RuntimeUnit eval_result;
+ [TrueGlobal] static System.Collections.IDictionary upcall_receiver;
internal static object UpCall(object[] args) {
if (upcall_receiver == null)
upcall_receiver = (System.Collections.IDictionary)
@@ -1725,6 +1725,7 @@ public partial class Builtins {
class ItemSource {
protected ItemSource() {}
+ [Immutable]
public static ItemSource Empty = new ItemSource();
public virtual bool TryGet(out Variable[] r, bool block) {
r = null;
@@ -2102,8 +2103,8 @@ class CrossSource: ItemSource {
}
// Used mostly to initialize $*PID et al
- public static string programName;
- public static string execName;
+ [TrueGlobal] public static string programName;
+ [TrueGlobal] public static string execName;
public static Variable getenv(string str) {
return Kernel.BoxAnyMO(Environment.GetEnvironmentVariable(str), Kernel.StrMO);
View
38 lib/CodeGen.cs
@@ -353,28 +353,6 @@ sealed class Tokens {
CC.GetConstructor(new Type[] { typeof(int[]) });
public static readonly ConstructorInfo SC_ctor =
StashCursor.GetConstructor(new Type[] { typeof(Frame), typeof(int) });
- public static readonly Dictionary<string,int> LADcodes
- = _LADcodes();
- private static Dictionary<string,int> _LADcodes() {
- Dictionary<string,int> n =
- new Dictionary<string,int>();
- n["CC"] = 1;
- n["Str"] = 2;
- n["Param"] = 3;
- n["Method"] = 4;
- n["Dispatcher"] = 5;
- n["StrNoCase"] = 6;
- n["Imp"] = 7;
- n["Dot"] = 8;
- n["None"] = 9;
- n["Null"] = 10;
- n["Plus"] = 11;
- n["Star"] = 12;
- n["Opt"] = 13;
- n["Sequence"] = 14;
- n["Any"] = 15;
- return n;
- }
public static readonly MethodInfo P6any_InvokeMethod =
P6any.GetMethod("InvokeMethod");
@@ -563,10 +541,12 @@ sealed class Tokens {
typeof(Frame).GetField("resultSlot");
public static readonly FieldInfo Frame_lexn =
typeof(Frame).GetField("lexn");
+ [Immutable]
public static readonly FieldInfo[] Frame_lexi32 = new FieldInfo[] {
typeof(Frame).GetField("lexi0"),
typeof(Frame).GetField("lexi1")
};
+ [Immutable]
public static readonly FieldInfo[] Frame_lexobj = new FieldInfo[] {
typeof(Frame).GetField("lex0"),
typeof(Frame).GetField("lex1"),
@@ -1034,7 +1014,7 @@ class ClrNoop : ClrOp {
HasCases = false;
}
public override void CodeGen(CgContext cx) { }
- public static ClrNoop Instance = new ClrNoop();
+ [Immutable] public static ClrNoop Instance = new ClrNoop();
}
class ClrEhSpan : ClrOp {
@@ -1121,7 +1101,7 @@ class ClrSync : ClrOp {
cx.il.MarkLabel(cx.cases[cx.next_case++]);
cx.save_line();
}
- public static ClrSync Instance = new ClrSync();
+ [Immutable] public static ClrSync Instance = new ClrSync();
}
// only used in ClrOperator.Sink, and assumes it in the HasCases=false
@@ -1489,7 +1469,7 @@ class ClrCpsFrame : ClrOp {
public override void CodeGen(CgContext cx) {
cx.il.Emit(OpCodes.Ldarg_0);
}
- public static ClrCpsFrame Instance = new ClrCpsFrame();
+ [Immutable] public static ClrCpsFrame Instance = new ClrCpsFrame();
}
class ClrNullLiteral : ClrOp {
@@ -2420,9 +2400,9 @@ class NamProcessor {
: Scan(z);
}
- static Dictionary<string, Func<NamProcessor, object[], CpsOp>> handlers;
- static Dictionary<string, Func<CpsOp[], CpsOp>> thandlers;
- static Dictionary<string, Type> namtypes;
+ [Immutable] static Dictionary<string, Func<NamProcessor, object[], CpsOp>> handlers;
+ [Immutable] static Dictionary<string, Func<CpsOp[], CpsOp>> thandlers;
+ [Immutable] static Dictionary<string, Type> namtypes;
static Type namtype(object z) {
string name = JScalar.S(z);
@@ -3494,7 +3474,7 @@ public class DowncallReceiver : CallReceiver {
}
}
}
- static bool TraceDown = Environment.GetEnvironmentVariable("NIECZA_TRACE_DOWNCALLS") != null;
+ static readonly bool TraceDown = Environment.GetEnvironmentVariable("NIECZA_TRACE_DOWNCALLS") != null;
object AddLexical(object[] args, LexInfo li) {
li.owner = (SubInfo)Handle.Unbox(args[1]);
View
21 lib/Cursor.cs
@@ -42,9 +42,9 @@ public sealed class GState {
highwater = (orig_a.Length < 100 || !Cursor.HwTrace) ?
int.MaxValue : 0;
}
- public static string BailAt =
+ public static readonly string BailAt =
Environment.GetEnvironmentVariable("NIECZA_DIE_AT_PCT");
- public static int BailAtI;
+ public static readonly int BailAtI;
static GState() {
if (!int.TryParse(BailAt, out BailAtI))
BailAtI = 101;
@@ -488,6 +488,7 @@ public sealed class RxFrame: IFreeze {
return global.CallAction(th, name, _matchObj);
}
+ [ContainerGlobal]
public static Variable EmptyList;
public Frame FinalEnd(Frame th) {
@@ -532,9 +533,9 @@ public sealed class RxFrame: IFreeze {
// this does double duty backing Match; note that Cursor and Match need to be
// treated polymorphically in a couple places
public class Cursor : P6any {
- public static bool Trace =
+ public static readonly bool Trace =
Environment.GetEnvironmentVariable("NIECZA_RX_TRACE") != null;
- public static bool HwTrace =
+ public static readonly bool HwTrace =
Environment.GetEnvironmentVariable("NIECZA_HIGHWATER_TRACE") != null;
// common fields
@@ -799,13 +800,14 @@ public sealed class CC : IFreeze {
public const int MAlNum = MAlpha | MNum;
- public static readonly CC Word = new CC(new int[] { 0, MAlNum,
+ [Immutable] public static readonly CC Word = new CC(new int[] { 0, MAlNum,
'_', MAll, '_'+1, MAlNum });
- public static readonly CC All = new CC(MAll);
- public static readonly CC None = new CC(0);
- public static readonly CC AlNum = new CC(MAlNum);
+ [Immutable] public static readonly CC All = new CC(MAll);
+ [Immutable] public static readonly CC None = new CC(0);
+ [Immutable] public static readonly CC AlNum = new CC(MAlNum);
+ [Immutable]
private static readonly int[] masks = new int[] {
MAll, (MAll & ~MOther), 0x71F,
0x1F, 0xE0, 0x700, 0x3800, 0x3C000, 0x1FC0000, 0x1E000000,
@@ -815,6 +817,7 @@ public sealed class CC : IFreeze {
(1<<16), (1<<17), (1<<18), (1<<19), (1<<20), (1<<21), (1<<22), (1<<23),
(1<<24), (1<<25), (1<<26), (1<<27), (1<<28), (1<<29),
};
+ [Immutable]
private static readonly string[] masknames = new string[] {
"ALL", "Assigned", "Alnum",
"Alpha", "Mark", "Num", "Space", "Control", "Punct", "Symbol",
@@ -1604,7 +1607,7 @@ public class Lexer {
int[] fatebuffer;
int usedfates;
- public static bool LtmTrace =
+ public static readonly bool LtmTrace =
Environment.GetEnvironmentVariable("NIECZA_LTM_TRACE") != null;
public static Lexer GetLexer(Frame fromf, STable kl, LAD[] lads, string title) {
View
2 lib/JSYNC.cs
@@ -4,7 +4,7 @@
using System.Text;
public class JsyncWriter {
- internal static bool FailSoft =
+ internal static readonly bool FailSoft =
Environment.GetEnvironmentVariable("NIECZA_JSYNC_WRITER_FAILSOFT") != null;
StringBuilder o = new StringBuilder();
Dictionary<object,int> anchors = new Dictionary<object,int>();
View
70 lib/Kernel.cs
@@ -74,6 +74,7 @@ public abstract class Variable : IFreeze {
// note: callers need to make sure type is set up properly if null
public Variable() { }
+ [Immutable]
public static readonly Variable[] None = new Variable[0];
}
@@ -767,7 +768,7 @@ class IdentityComparer : IEqualityComparer<object> {
for (int i = 0; i < dep.Length; i++) {
srcinfo[i*2] = dep[i].name;
srcinfo[i*2+1] = Utils.HashToStr(
- ObjectRegistry.hash.ComputeHash(
+ ObjectRegistry.NewHash().ComputeHash(
new UTF8Encoding().GetBytes(dep[i].source)));
}
fb.Strings(srcinfo);
@@ -1308,6 +1309,7 @@ public class UsedInScopeInfo {
public int[] edata;
public string[] label_names;
+ [Immutable]
private static string[] controls = new string[] { "unknown", "next",
"last", "redo", "return", "die", "succeed", "proceed", "goto",
"nextsame/nextwith", "varlookup", "warning" };
@@ -2266,6 +2268,7 @@ public class Frame: P6any, IFixup {
return (Frame) coro_return;
}
+ [TrueGlobal]
private static List<string> spacey = new List<string>();
public string DepthMark() {
Frame f = this;
@@ -2998,6 +3001,7 @@ class CtxStrSuccish : ContextHandler<P6any> {
protected override void SetData(object[] o) { succ = (bool) o[0]; }
// note that most of this table is katakana. Perhaps there
// is a better way.
+ [Immutable]
static ushort[] table = {
48, 57, 57, 48, 65, 90, 90, 65, 97, 122, 122, 97, 913, 929,
937, 931, 931, 937, 929, 913, 945, 961, 969, 963, 963, 969,
@@ -3869,34 +3873,8 @@ public class Kernel {
}
}
- internal static HashSet<string> ModulesStarted = new HashSet<string>();
- internal static Dictionary<string,RuntimeUnit> ModulesFinished =
- new Dictionary<string,RuntimeUnit>();
-
- public static Variable BootModule(string name, DynBlockDelegate dgt) {
- if (ModulesFinished.ContainsKey(name))
- return AnyMO.typeVar;
- if (ModulesStarted.Contains(name))
- throw new NieczaException("Recursive module graph detected at " + name + ": " + JoinS(" ", ModulesStarted));
- ModulesStarted.Add(name);
- Variable r = Kernel.RunInferior(Kernel.GetInferiorRoot().
- MakeChild(null, new SubInfo("boot-" + name, dgt), AnyP));
- if (!ModulesFinished.ContainsKey(name))
- ModulesFinished[name] = null;
- return r;
- }
-
public static void DoRequire(string name) {
- if (ModulesFinished.ContainsKey(name))
- return;
- Assembly a = Assembly.Load(name);
- Type t = a.GetType(name);
- if (t == null) throw new NieczaException("Load module must have a type of the same name");
- MethodInfo mi = t.GetMethod("BOOT");
- if (mi == null) throw new NieczaException("Load module must have a BOOT method");
- BootModule(name, delegate (Frame fr) {
- return (Frame) mi.Invoke(null, new object[] { fr });
- });
+ throw new NotImplementedException(); // TODO reimplement
}
public static T UnboxAny<T>(P6any o) {
@@ -4067,8 +4045,8 @@ public class MMDParameter {
public bool constrained;
public bool required;
- public static MMDParameter TOP = new MMDParameter();
- public static MMDParameter BOTTOM = new MMDParameter();
+ [Immutable] public static MMDParameter TOP = new MMDParameter();
+ [Immutable] public static MMDParameter BOTTOM = new MMDParameter();
// XXX Should requiredness be factored in?
// 2: narrower 0: tied 1: less narrow 3: incomparable
@@ -4365,6 +4343,7 @@ public class MMDCandidateLongname {
return Lexer.MakeDispatcher(name, lp.ToArray());
}
+ [TrueGlobal]
public static bool SaferMode;
private static Frame SaferTrap(Frame th) {
@@ -4494,6 +4473,7 @@ public class MMDCandidateLongname {
return nv;
}
+ [TrueGlobal]
public static string[] commandArgs;
public static VarDeque SortHelper(Frame th, P6any cb, VarDeque from) {
@@ -5093,9 +5073,9 @@ class ExitRunloopException : Exception {
public const int TRACE_CUR = 1;
public const int TRACE_ALL = 2;
- public static int TraceFreq;
- public static int TraceCount;
- public static int TraceFlags;
+ [TrueGlobal] public static int TraceFreq;
+ [TrueGlobal] public static int TraceCount;
+ [TrueGlobal] public static int TraceFlags;
private static void DoTrace(Frame cur) {
TraceCount = TraceFreq;
@@ -5212,7 +5192,7 @@ class LastFrameNode {
}
}
- [ThreadStatic]
+ [ContainerGlobal]
public static Dictionary<string, StashEnt> currentGlobals;
public static Variable GetGlobal(string key) {
@@ -5671,6 +5651,15 @@ class LastFrameNode {
BindingFlags.Public | BindingFlags.NonPublic)) {
if (fi.GetCustomAttributes(typeof(CompilerGeneratedAttribute), true).Length != 0)
continue;
+ // already classified
+ if (fi.GetCustomAttributes(typeof(ImmutableAttribute), true).Length != 0)
+ continue;
+ if (fi.GetCustomAttributes(typeof(CORESavedAttribute), true).Length != 0)
+ continue;
+ if (fi.GetCustomAttributes(typeof(ContainerGlobalAttribute), true).Length != 0)
+ continue;
+ if (fi.GetCustomAttributes(typeof(TrueGlobalAttribute), true).Length != 0)
+ continue;
// ignore effectively constant fields
if (fi.IsLiteral)
continue;
@@ -5681,14 +5670,15 @@ class LastFrameNode {
if (fi.IsInitOnly && (ft.IsPrimitive ||
ft == typeof(BigInteger) ||
ft == typeof(Type) ||
+ ft == typeof(Assembly) ||
ft == typeof(FieldInfo) ||
ft == typeof(ConstructorInfo) ||
ft == typeof(MethodInfo) ||
typeof(Delegate).IsAssignableFrom(ft) ||
- ft.IsSealed && ft.GetFields(
- BindingFlags.Instance |
- BindingFlags.Public |
- BindingFlags.NonPublic).Length == 0 ||
+ //ft.IsSealed && ft.GetFields(
+ // BindingFlags.Instance |
+ // BindingFlags.Public |
+ // BindingFlags.NonPublic).Length == 0 ||
typeof(ReflectObj).IsAssignableFrom(ft) ||
ft == typeof(string)))
continue;
@@ -5711,9 +5701,9 @@ class LastFrameNode {
}
public class Config {
- public static int CGVerbose =
+ public static readonly int CGVerbose =
int.Parse(Environment.GetEnvironmentVariable("NIECZA_CODEGEN_TRACE") ?? "0");
- public static bool CGVerifiable =
+ public static readonly bool CGVerifiable =
Environment.GetEnvironmentVariable("NIECZA_CODEGEN_UNVERIFIABLE") != null ? false : true;
public static readonly bool C3Trace =
Environment.GetEnvironmentVariable("NIECZA_C3_TRACE") != null;
View
7 lib/NieczaCLR.cs
@@ -378,15 +378,15 @@ class OverloadCandidate : MultiCandidate {
}
const int NUM_NUMTYPES = 12;
- static Type[] num_types = new Type[] {
+ [Immutable] static Type[] num_types = new Type[] {
typeof(sbyte), typeof(byte), typeof(short), typeof(ushort),
typeof(int), typeof(uint), typeof(long), typeof(ulong),
typeof(char), typeof(float), typeof(double), typeof(decimal),
};
// +1 if Y is a signed type shorter-or-equal to unsigned X, or
// Y is implicitly convertable to X
- static sbyte[,] num_preced = new sbyte[,] {
+ [Immutable] static sbyte[,] num_preced = new sbyte[,] {
//sb ub ss us si ui sl ul ch sf df dc
{ 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1 }, //sbyte
{ 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1 }, //byte
@@ -430,8 +430,10 @@ class OverloadCandidate : MultiCandidate {
public class CLRWrapperProvider {
// wrapper_cache serves as the lock-bearer for both
+ [ContainerGlobal]
static Dictionary<Type, STable> wrapper_cache
= new Dictionary<Type, STable>();
+ [ContainerGlobal]
static Dictionary<string, STable> named_wrapper_cache
= new Dictionary<string, STable>();
@@ -516,6 +518,7 @@ public class CLRWrapperProvider {
public static void dv8<T0,T1,T2,T3,T4,T5,T6,T7>(P6any f, T0 a0, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7) { Callback(f, typeof(void), new object[] { a0,a1,a2,a3,a4,a5,a6,a7, }, new Type[] { typeof(T0),typeof(T1),typeof(T2),typeof(T3),typeof(T4),typeof(T5),typeof(T6),typeof(T7), }); }
public static TR dnv9<TR,T0,T1,T2,T3,T4,T5,T6,T7,T8>(P6any f, T0 a0, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7, T8 a8) { return (TR)Callback(f, typeof(TR), new object[] { a0,a1,a2,a3,a4,a5,a6,a7,a8, }, new Type[] { typeof(T0),typeof(T1),typeof(T2),typeof(T3),typeof(T4),typeof(T5),typeof(T6),typeof(T7),typeof(T8), }); }
public static void dv9<T0,T1,T2,T3,T4,T5,T6,T7,T8>(P6any f, T0 a0, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6, T7 a7, T8 a8) { Callback(f, typeof(void), new object[] { a0,a1,a2,a3,a4,a5,a6,a7,a8, }, new Type[] { typeof(T0),typeof(T1),typeof(T2),typeof(T3),typeof(T4),typeof(T5),typeof(T6),typeof(T7),typeof(T8), }); }
+ [Immutable]
static MethodInfo[] delegate_methods;
static CLRWrapperProvider() {
delegate_methods = new MethodInfo[20];
View
11 lib/Serialize.cs
@@ -60,7 +60,8 @@ struct ObjRef {
Dictionary<string,SerUnit> units =
new Dictionary<string,SerUnit>();
- internal static readonly HashAlgorithm hash = SHA256.Create();
+ internal static HashAlgorithm NewHash() { return new SHA256Managed(); }
+
static readonly string signature = "Niecza-Serialized-Module";
static readonly int version = 1;
@@ -116,7 +117,7 @@ struct ObjRef {
su = new SerUnit();
su.name = name;
- su.hash = hash.ComputeHash(bytes);
+ su.hash = NewHash().ComputeHash(bytes);
ThawBuffer tb = new ThawBuffer(this, su, bytes);
@@ -175,7 +176,7 @@ struct ObjRef {
fb.ObjRef(root);
byte[] data = fb.GetData();
- su.hash = hash.ComputeHash(data);
+ su.hash = NewHash().ComputeHash(data);
File.WriteAllBytes(file, data);
success = true;
} finally {
@@ -424,19 +425,21 @@ public class FreezeBuffer {
}
}
+ [Immutable]
internal static Type[] boxTypes = new Type[] {
null, typeof(Rat), typeof(FatRat), typeof(Complex),
typeof(double), typeof(int), typeof(string), typeof(VarHash),
typeof(Variable[]), typeof(VarDeque), typeof(STable),
};
+ [Immutable]
internal static Func<P6opaque>[] boxCreate = new Func<P6opaque>[] {
P6opaque.Create, BoxObject<Rat>.Create, BoxObject<FatRat>.Create,
BoxObject<Complex>.Create, BoxObject<double>.Create,
BoxObject<int>.Create, BoxObject<string>.Create,
BoxObject<VarHash>.Create, BoxObject<Variable[]>.Create,
BoxObject<VarDeque>.Create, BoxObject<STable>.Create,
};
-
+ [Immutable]
static Type[] anyTypes = new Type[] {
typeof(string), typeof(P6any[]), typeof(Variable[]),
typeof(string[]), typeof(CC[]),
View
2 lib/Utils.cs
@@ -166,6 +166,7 @@ public sealed class VarHash : IEnumerable<KeyValuePair<string,Variable>>,
const int INITIAL = 5;
const int THRESHOLD = 11;
+ [Immutable]
static int[] grow = new int[] {
5, 11, 17, 37, 67, 131, 257, 521, 1031, 2053, 4099, 8209, 16411,
32771, 65537, 131101, 262147, 524309, 1048583, 2097169, 4194319,
@@ -588,6 +589,7 @@ public sealed class Complex : IFreeze {
this.re = re; this.im = im;
}
+ [Immutable]
public static readonly Complex i = new Complex(0, 1);
public static Complex operator- (Complex left) {

0 comments on commit cdb4548

Please sign in to comment.