public override void codeGen(ILGenerator generator) { if (toPrint is Identifier) { bool emitted = false; foreach (Variable v in VariableStack.variables) { if (v.name.Trim() == toPrint.val().ToString().Trim()) { if (v.lb != null) { generator.EmitWriteLine(v.lb); } else { generator.EmitWriteLine(v.value.val().ToString()); } emitted = true; break; } } if (!emitted) { throw new Exception("Undefined variable : " + toPrint.val()); } } else { if (toPrint is Number || toPrint is Str || toPrint is Bool || toPrint is BinaryOp) { generator.EmitWriteLine(toPrint.val().ToString()); } else { throw new Exception("Illegal argument in 'print' function! typeof: " + toPrint.GetType()); } } }
/// <summary> /// Shows message followed by current object from the top of the stack /// </summary> /// <param name="il"></param> /// <param name="msg"></param> public static void EmitDebugWriteLineForCurrentObject(this ILGenerator il, string msg) { il.EmitWriteLine(msg); il.Emit(OpCodes.Dup); il.EmitConsoleWriteLine(); }