/// <summary>Compiles all the globals in this code section (sets up their field and initialiser).</summary> public void Compile(ILGenerator gen) { if (Globals == null) { return; } for (int i = 0; i < Globals.Length; i++) { // Get the gv: GlobalVariable global = Globals[i]; // Field: Type type; FieldInfo field = global.GetField(Module, out type); object init = global.Init; if (init != null) { // Apply the initialiser now: if (init is FieldInfo) { // Global (must be imported) gen.LoadField(init as FieldInfo); } else { // Must be one of the four constant expr's: if (init is int) { gen.LoadInt32((int)init); } else if (init is long) { gen.LoadInt64((long)init); } else if (init is float) { gen.LoadSingle((float)init); } else if (init is double) { gen.LoadDouble((double)init); } } gen.StoreField(field); } } }
/// <summary> /// Pushes a reference to the ScriptEngine or WebAssembly module onto the stack. /// </summary> /// <param name="generator"> The IL generator. </param> public static void LoadRuntime(ILGenerator generator) { // Get the static ref to the runtime: generator.LoadField(generator.Runtime.ModuleInfo.GlobalRuntime); }