public void Emit(CompilerErrorCollection errors, MethodBuilder m) { //Set the parameters //ParameterBuilder[] parms = new ParameterInfo[args.Length]; for (int i = 0; i < args.Length; i++) { m.DefineParameter(i + 1, ParameterAttributes.None, args[i].Name); } ILGenerator gen = m.GetILGenerator(); //Define the IT variable LocalRef it = locals["IT"] as LocalRef; DefineLocal(gen, it); statements.Process(this, errors, gen); statements.Emit(this, gen); //Cast the IT variable to our return type and return it if (m.ReturnType != typeof(void)) { gen.Emit(OpCodes.Ldloc, it.Local); Expression.EmitCast(gen, it.Type, m.ReturnType); } gen.Emit(OpCodes.Ret); }
public void DefineLocal(ILGenerator gen, LocalRef l) { l.Local = gen.DeclareLocal(l.Type); if (program.compileropts.IncludeDebugInformation) { l.Local.SetLocalSymInfo(l.Name); } }
public LOLMethod(FunctionRef info, LOLProgram prog) { this.info = info; this.args = new ArgumentRef[info.Arity + (info.IsVariadic ? 1 : 0)]; this.program = prog; this.locals = new Scope(prog.globals); LocalRef it = new LocalRef("IT"); locals.AddSymbol(it); }