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.GetFieldInstruction, index) { 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); }