/// <summary> /// Save to a local variable /// </summary> /// <param name="id">Variable</param> public void EmitSaveVariable(ScopeVariable var) { GetMethodProcessor().Emit(OpCodes.Stloc, var.Var); }
/// <summary> /// Declare a local variable in the current subscope /// </summary> /// <param name="name">Variable name</param> /// <param name="typeName">Variable type as string</param> /// <param name="type">Variable type as TypeReference</param> /// <returns></returns> public ScopeVariable Introduce(string typeName, TypeReference type, string name = null) { if (name == null || name == "") name = CreateNewName(); if (Exists(name)) throw new CompilerException(String.Format(Resources.errVariableRedefinition, name)); var actualVariable = new VariableDefinition(name, type); var local = new ScopeVariable(name, typeName, actualVariable); Method.Body.Variables.Add(actualVariable); Data.Peek().Add(name, local); return local; }
/// <summary> /// Load a variable address /// </summary> /// <param name="id">Variable</param> public void EmitLoadVariableAddress(ScopeVariable var) { GetMethodProcessor().Emit(OpCodes.Ldloca, var.Var); }