/// <summary> /// Makes a new static field slot. Type is ignored. If we ever change ignoring type then we /// need to make BuiltinWrapper generic and update StaticFieldBuiltinSlot to get the correct /// type. /// </summary> public override Slot MakeSlot(Name name, Type type) { StaticFieldSlot fs; object builtin; if (!fields.TryGetValue(name, out fs)) { if (!TypeCache.Builtin.TryGetSlot(DefaultContext.Default, SymbolTable.StringToId(name.GetString()), out builtin)) { // name does not collide w/ a built-in name, define a real field. FieldBuilder fb = typeGen.myType.DefineField(name.GetString(), typeof(object), FieldAttributes.Public | FieldAttributes.Static); fs = new StaticFieldSlot(fb); } else { // name collides w/ a built-in name. Our field becomes strongly typed to // BuiltinWrapper. We then return a // StaticFieldBuiltinSlot which checks the value to see if it's a built-in or // not. FieldBuilder fb = typeGen.myType.DefineField(name.GetString(), typeof(BuiltinWrapper), FieldAttributes.Public | FieldAttributes.Static); fs = new StaticFieldBuiltinSlot(fb); } fields[name] = fs; } return(fs); }
public Slot GetOrMakeConstant(object value, Type type) { Slot ret; if (constants.TryGetValue(value, out ret)) { return(ret); } // Create a name like "c$3.141592$712" string symbolicName = value.ToString(); if (symbolicName.Length > 20) { symbolicName = symbolicName.Substring(0, 20); } string name = "c$" + symbolicName + "$" + constants.Count; FieldBuilder fb = myType.DefineField(name, type, FieldAttributes.Static | FieldAttributes.InitOnly); ret = new StaticFieldSlot(fb); GetOrMakeInitializer().EmitConstantBoxed(value); initGen.EmitFieldSet(fb); constants[value] = ret; return(ret); }