public static bool Neg(Instruction instruction, CompileContext compileContext) { var value = compileContext.Pop(); compileContext.Push(value.type, CompileContext.Format("-({0})", value)); return(true); }
public override string Generate(CompileContext outer) { using (TextWriter writer = new StringWriter()) { bool first = true; foreach (var block in blocks) { EvaluationStack unhandled = null; if (block.condition != null) { string nothing = outer.GenerateWithoutWriting(block.condition.first, block.condition.last, ref unhandled); Debug.Assert(string.IsNullOrEmpty(nothing)); if (unhandled == null) { unhandled = outer.GetEvaluationStack(); } writer.WriteLine(CompileContext.Format(first ? "if({0} == 0)" : "else if({0} == 0)", unhandled.Pop())); } else { writer.WriteLine("else"); } writer.WriteLine(CompileContext.Format("{{{0}}}", outer.GenerateWithoutWriting(block.body.first, block.body.last, ref unhandled))); first = false; } return(writer.ToString()); } }
public static bool Bgt(Instruction instruction, CompileContext compileContext) { var b = compileContext.Pop(); var a = compileContext.Pop(); compileContext.Push(typeof(int).GetTypeDefinition(), CompileContext.Format("int({0} > {1})", a, b)); return(true); }
public static bool Rem(Instruction instruction, CompileContext compileContext) { var b = compileContext.Pop(); var a = compileContext.Pop(); compileContext.Push(new Value(a.type, CompileContext.Format("mod({0}, {1})", a, b))); return(true); }
public static bool Blt_S(Instruction instruction, CompileContext compileContext) { // blt.s target - Branch to target if less than, short for var b = compileContext.Pop(); var a = compileContext.Pop(); compileContext.Push(typeof(int).GetTypeDefinition(), CompileContext.Format("int({0} < {1})", a, b)); return(true); }
public static bool Ble(Instruction instruction, CompileContext compileContext) { // ble target - Branch to target if less than or equal to. var b = compileContext.Pop(); var a = compileContext.Pop(); compileContext.Push(typeof(int).GetTypeDefinition(), CompileContext.Format("int({0} <= {1})", a, b)); return(true); }
public override string Generate(CompileContext outer) { // Condition EvaluationStack unhandled = null; string nothing = outer.GenerateWithoutWriting(this.condition.first, this.condition.last, ref unhandled); Debug.Assert(string.IsNullOrEmpty(nothing)); if (unhandled == null) { unhandled = outer.GetEvaluationStack(); } var condition = unhandled.Pop(); string body = outer.GenerateWithoutWriting(this.body.first, this.body.last, ref unhandled); Debug.Assert(unhandled == null); return(CompileContext.Format("while({0} != 0) {{\n{1}\n}}\n", condition, body)); }
public static bool Operator(Instruction instruction, CompileContext compileContext, string @operator, TypeReference type = null) { var b = compileContext.Pop(); var a = compileContext.Pop(); string pattern; if (type != null) { pattern = "{3}({0} {1} {2})"; } else { pattern = "({0} {1} {2})"; } compileContext.Push(new Value(type != null ? type : a.type, CompileContext.Format(pattern, a, @operator, b, type))); return(true); }
public static bool Conv_R4(Instruction instruction, CompileContext compileContext) { compileContext.Push(typeof(float).GetTypeDefinition(), CompileContext.Format("float({0})", compileContext.Pop())); return(true); }
public static bool Brfalse(Instruction instruction, CompileContext compileContext) { compileContext.Push(typeof(int).GetTypeDefinition(), CompileContext.Format("int({0} == 0)", compileContext.Pop())); return(true); }
public static bool Brtrue(Instruction instruction, CompileContext compileContext) { // brtrue target - Branch to target if value is non-zero (true). compileContext.Push(typeof(int).GetTypeDefinition(), CompileContext.Format("int({0} == 1)", compileContext.Pop())); return(true); }