public override List<InstructionModel> GetInstructions(CompilationModel model) { var instructions = new List<InstructionModel>(); var classModel = GetCorrectParent(model); // push args foreach (var param in Parameters) { instructions.AddRange(param.GetInstructions(model)); } instructions.Add(new InstructionModel(Instructions.LoadPointerInstruction, "0") { Comment = model.GetComment(this) + " - loading self" }); try { instructions.Add(new InstructionModel(Instructions.CallInstruction, string.Format("{0}::{1}::{2}", classModel.Name != FindParent<Class>().Name ? classModel.Name : string.Empty, Method, Parameters.Count())) { Comment = model.GetComment(this) + " - doing method call" }); } catch (Exception e) { if (Method != "New" && Parameters.Count() != 0) { throw e; } } return instructions; }
public override List<InstructionModel> GetInstructions(CompilationModel model) { var method = FindParent<Method>(); var @class = (Class)method.Parent; var classModel = model.GetClass(@class.Name); var index = classModel.GetFieldIndex(Property).ToString(CultureInfo.InvariantCulture); var instructions = new List<InstructionModel>(); instructions.Add(new InstructionModel(Instructions.LoadPointerInstruction, "0") { Comment = model.GetComment(this) + " - setting field" }); instructions.Add(new InstructionModel(Instructions.SetFieldInstruction, index) { Comment = model.GetComment(this) + " - setting field" }); return instructions; }
public override List<InstructionModel> GetInstructions(CompilationModel model) { var instructions = new List<InstructionModel>(); instructions.AddRange(Expression.GetInstructions(model)); instructions.Add(new InstructionModel(Instructions.LogicalNegIntInstruction) { Comment = model.GetComment(this) }); return instructions; }
public override List<InstructionModel> GetInstructions(CompilationModel model) { var instructions = new List<InstructionModel>(); instructions.Add(new InstructionModel(Instruction.Value.Replace("\"", ""))); // it ignore instrunction model, it emits what what user types instructions.Latest().Comment = model.GetComment(this); return instructions; }
public override List<InstructionModel> GetInstructions(CompilationModel model) { var instructions = new List<InstructionModel>(); var index = model.GetClass(Expression.GetExpressionType(model)).GetFieldIndex(Property).ToString(CultureInfo.InvariantCulture); instructions.AddRange(Expression.GetInstructions(model)); instructions.Add(new InstructionModel(Instructions.SetFieldInstruction, index) { Comment = model.GetComment(this) + " - setting field on expression" }); return instructions; }
public override List<InstructionModel> GetInstructions(CompilationModel model) { var instructions = new List<InstructionModel>(); // casting is not important for compiled version instructions.AddRange(Expression.GetInstructions(model)); instructions.Latest().Comment = model.GetComment(this); return instructions; }
public override List<InstructionModel> GetInstructions(CompilationModel model) { var instructions = new List<InstructionModel>(); instructions.AddRange(LeftExpression.GetInstructions(model)); instructions.AddRange(RightExpression.GetInstructions(model)); instructions.Add(new InstructionModel(Instructions.ModIntInstruction)); instructions.Latest().Comment = model.GetComment(this); return instructions; }
public override List<InstructionModel> GetInstructions(CompilationModel model) { var instructions = new List<InstructionModel> { new InstructionModel(Instructions.PushIntInstruction, Value.ToString(CultureInfo.InvariantCulture)) }; instructions.Latest().Comment = model.GetComment(this); return instructions; }
public override List<InstructionModel> GetInstructions(CompilationModel model) { var instructions = new List<InstructionModel> { new InstructionModel(Instructions.NewStringInstruction, "#" + Value.Replace("\"", "")) }; instructions.Latest().Comment = model.GetComment(this); return instructions; }
public override List<InstructionModel> GetInstructions(CompilationModel model) { var blockInstructions = Block.GetInstructions(model); var jmpTo = (blockInstructions.Count + 1).ToString(CultureInfo.InvariantCulture); var instructions = new List<InstructionModel>(); instructions.Add(new InstructionModel(Instructions.PushIntInstruction, "1")); instructions.Latest().Comment = model.GetComment(this); instructions.AddRange(Expression.GetInstructions(model)); instructions.Add(new InstructionModel(Instructions.IfIntEqInstruction, jmpTo)); instructions.AddRange(blockInstructions); return instructions; }
public override List<InstructionModel> GetInstructions(CompilationModel model) { var instructions = new List<InstructionModel>(); instructions.AddRange(LeftExpression.GetInstructions(model)); instructions.AddRange(RightExpression.GetInstructions(model)); instructions.Add(new InstructionModel(Instructions.IfIntNeqInstruction, "3")); instructions.Add(new InstructionModel(Instructions.PushIntInstruction, "1")); instructions.Add(new InstructionModel(Instructions.JumpInstruction, "2")); instructions.Add(new InstructionModel(Instructions.PushIntInstruction, "0")); instructions[instructions.Count - 3].Comment = model.GetComment(this); return instructions; }
public override List<InstructionModel> GetInstructions(CompilationModel model) { var instructions = new List<InstructionModel>(); if (Expression != null) { instructions.AddRange(Expression.GetInstructions(model)); var type = Expression.GetExpressionType(model); var instruction = new InstructionModel(type == BuiltinTypes.Integer ? Instructions.ReturnIntInstruction : Instructions.ReturnPointerInstruction); instruction.Comment = model.GetComment(this); instructions.Add(instruction); } else { var instruction = new InstructionModel(Instructions.ReturnInstruction); instruction.Comment = model.GetComment(this); instructions.Add(instruction); } return instructions; }
public override List<InstructionModel> GetInstructions(CompilationModel model) { var trueBlockInstructions = TrueBlock.GetInstructions(model); var falseBlockInstructions = TrueBlock.GetInstructions(model); var jmpToFalse = (trueBlockInstructions.Count + 2).ToString(CultureInfo.InvariantCulture); // + 1 to following + 1 added jump var jmpOver = (falseBlockInstructions.Count + 1).ToString(CultureInfo.InvariantCulture); var instructions = new List<InstructionModel>(); instructions.Add(new InstructionModel(Instructions.PushIntInstruction, "1")); instructions.Latest().Comment = model.GetComment(this); instructions.AddRange(Expression.GetInstructions(model)); instructions.Add(new InstructionModel(Instructions.IfIntEqInstruction, jmpToFalse)); instructions.AddRange(trueBlockInstructions); instructions.Add(new InstructionModel(Instructions.JumpInstruction, jmpOver)); return instructions; }
public override List<InstructionModel> GetInstructions(CompilationModel model) { var method = FindParent<Method>(); var @class = (Class) method.Parent; var methodModel = model.GetClass(@class.Name).GetMethod(method.FullName); var index = methodModel.GetVariableIndex(Variable).ToString(CultureInfo.InvariantCulture); var type = methodModel.GetVariableType(Variable); var instructions = new List<InstructionModel>(); instructions.AddRange(Expression.GetInstructions(model)); // get instructions of expression instructions.Add(new InstructionModel(type == BuiltinTypes.Integer ? // store result into local variable Instructions.StoreIntInstruction : Instructions.StorePointerInstruction, index)); instructions.Latest().Comment = model.GetComment(this); return instructions; }
public override List<InstructionModel> GetInstructions(CompilationModel model) { var instructions = new List<InstructionModel>(); var method = FindParent<Method>(); var @classs = (Class) method.Parent; var methodModel = model.GetClass(@classs.Name).GetMethod(method.FullName); var type = methodModel.GetVariableType(Variable); var index = methodModel.GetVariableIndex(Variable).ToString(CultureInfo.InvariantCulture); if (type == BuiltinTypes.Integer) { instructions.Add(new InstructionModel(Instructions.LoadIntInstruction, index)); } else { instructions.Add(new InstructionModel(Instructions.LoadPointerInstruction, index)); } instructions.Latest().Comment = model.GetComment(this); return instructions; }
public override List<InstructionModel> GetInstructions(CompilationModel model) { var instructions = new List<InstructionModel>(); bool isStaticCall = false; string tmpIndex = null; if (Expression is VariableExpression) // calling static method { var variable = (VariableExpression) Expression; var method = FindParent<Method>(); var @class = (Class) method.Parent; // first try to find it in locals in that case it would be local variable tmpIndex = model.GetClass(@class.Name).GetMethod(method.FullName).GetVariableIndex(LocalModel.TempVariable).ToString(CultureInfo.InvariantCulture); try { model.GetClass(@class.Name).GetMethod(method.FullName).GetVariableIndex(variable.Variable); } catch (Exception) { isStaticCall = true; } } // push args foreach (var param in Parameters) { instructions.AddRange(param.GetInstructions(model)); } // find on which object it will be called if (isStaticCall) { var @class = (VariableExpression) Expression; instructions.Add(new InstructionModel(Instructions.NewInstruction, @class.Variable) { Comment = model.GetComment(this) + " - creating new instance" }); instructions.Add(new InstructionModel(Instructions.StorePointerInstruction, tmpIndex) { Comment = model.GetComment(this) + " - storing in tmp variable" }); instructions.Add(new InstructionModel(Instructions.LoadPointerInstruction, tmpIndex) { Comment = model.GetComment(this) + " - loading from tmp variable" }); } else if (Expression != null) { instructions.AddRange(Expression.GetInstructions(model)); } else { instructions.Add(new InstructionModel(Instructions.LoadPointerInstruction, "0") { Comment = model.GetComment(this) + " - loading self" }); } try { instructions.Add(new InstructionModel(Instructions.CallInstruction, string.Format("::{0}::{1}", Method, Parameters.Count())) { Comment = model.GetComment(this) + " - doing method call" }); if (isStaticCall) { instructions.Add(new InstructionModel(Instructions.LoadPointerInstruction, tmpIndex) { Comment = model.GetComment(this) + " - loading from tmp variable" }); } } catch (Exception) { if (Method != "New" && Parameters.Count() != 0) { throw; } } return instructions; }