private void CompileFuncall(Symbol fnSym, Cons paramList, LexicalScope lexScope) { if(lexScope.IsBound(fnSym, Symbol.FunctionSlot)) { GenLexSymValue(lexScope, fnSym, Symbol.FunctionSlot); } else { FieldInfo functionSlotFld = typeof(Symbol).GetField("FunctionSlot"); if(functionSlotFld == null) { throw new CompilerError("Unable to find VM.Types.Symbol.FunctionSlot field"); } GenDynSymValue(fnSym, functionSlotFld); } MethodInfo invokeMethInfo = typeof(Function).GetMethod("Invoke"); if(invokeMethInfo == null) { throw new CompilerError("Unable to find VM.Function.Invoke method"); } var paramCount = ConsAux.Reduce(paramList, (x, counter) => counter + 1, 0); _gen.Emit(OpCodes.Newarr, paramCount); ConsAux.Reduce(paramList, (x, counter) => { _gen.Emit(OpCodes.Dup); _gen.Emit(OpCodes.Ldc_I4, counter + 1); CompileForm(x, lexScope); _gen.Emit(OpCodes.Stelem_Ref); return counter + 1; }, 0); _gen.Emit(OpCodes.Call, invokeMethInfo); }
private void CompileVariable(Symbol sym, LexicalScope lexScope) { if(lexScope.IsBound(sym, Symbol.ValueSlot)) { GenLexSymValue(lexScope, sym, Symbol.ValueSlot); } else { FieldInfo valueSlotFld = typeof(Symbol).GetField("ValueSlot"); if(valueSlotFld == null) { throw new CompilerError("Unable to find VM.Types.Symbol.FunctionSlot field"); } GenDynSymValue(sym, valueSlotFld); } }