/// <summary> /// Provides a custom compiler routine for emitting CIL byte code for a specific instruction. /// </summary> /// <param name = "state">The compiler state.</param> /// <param name = "ins">The instruction to compile.</param> void ICilCompilerAware.ImplementInCil(CompilerState state, Instruction ins) { switch (ins.Arguments) { case 0: if (!ins.JustEffect) { state.Il.Emit(OpCodes.Ldstr, ""); state.EmitWrapString(); } break; case 1: state.EmitLoadLocal(state.SctxLocal); state.Il.EmitCall(OpCodes.Call, ConsolePrintLine.PValueCallToString, null); if (!ins.JustEffect) { state.Il.Emit(OpCodes.Dup); state.EmitWrapString(); state.EmitStoreTemp(0); } state.Il.EmitCall(OpCodes.Call, ConsolePrintLine.ConsoleWriteMethod, null); if (!ins.JustEffect) { state.EmitLoadTemp(0); } break; default: throw new NotSupportedException(); } }
/// <summary> /// Implements the CIL extension in CIL for the supplied arguments. The CIL compiler guarantees to always first call <see /// cref = "ICilExtension.ValidateArguments" /> in order to establish whether the extension can actually implement a particular call. /// Thus, this method does not have to verify <paramref name = "staticArgv" /> and <paramref name = "dynamicArgc" />. /// </summary> /// <param name = "state">The CIL compiler state. This object is used to emit instructions.</param> /// <param name = "ins">The instruction that "calls" the CIL extension. Usually a command call.</param> /// <param name = "staticArgv">The suffix of compile-time constant arguments, starting after the last dynamic (not compile-time constant) argument. An empty array means that there were no compile-time constant arguments at the end.</param> /// <param name = "dynamicArgc">The number of dynamic arguments preceding the supplied static arguments. The total number of arguments is determined by <code>(staticArgv.Length + dynamicArgc)</code></param> public void Implement(CompilerState state, Instruction ins, CompileTimeValue[] staticArgv, int dynamicArgc) { var text = String.Concat(staticArgv.Select(StaticPrint._ToString)); state.Il.Emit(OpCodes.Ldstr, text); if (!ins.JustEffect) { state.Il.Emit(OpCodes.Dup); } state.EmitCall(consoleWriteLineMethod_String); if (!ins.JustEffect) { state.EmitWrapString(); } }
public void Implement(CompilerState state, Instruction ins, CompileTimeValue[] staticArgv, int dynamicArgc) { var text = String.Concat(staticArgv.Select(StaticPrint._ToString)); state.EmitCall(StaticPrint._StaticPrintTextWriterGetMethod); state.Il.Emit(OpCodes.Ldstr, text); if (!ins.JustEffect) { state.Il.Emit(OpCodes.Dup); state.EmitStoreTemp(0); } state.EmitVirtualCall(_textWriterWriteLineMethod); if (!ins.JustEffect) { state.EmitLoadTemp(0); state.EmitWrapString(); } }