コード例 #1
0
        public override string GetExpressionType(CompilationModel model)
        {
            var fullName = string.Format("{0}:{1}", Method, String.Join(":", Parameters.Select(e => e.GetExpressionType(model))));

            if (Expression != null)
            {
                return model.GetClass(Expression.GetExpressionType(model)).GetMethod(fullName).Type;
            }

            return model.GetClass(FindParent<Class>().Name).GetMethod(fullName).Type;
        }
コード例 #2
0
 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;
 }
コード例 #3
0
 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;
 }
コード例 #4
0
 public override string GetExpressionType(CompilationModel model)
 {
     var method = FindParent<Method>();
     var @class = (Class)method.Parent;
     var methodModel = model.GetClass(@class.Name).GetMethod(method.FullName);
     try
     {
         return methodModel.GetVariableType(Variable);
     }
     catch (Exception)
     {
         return Variable; // in this case it's static call
     }
 }
コード例 #5
0
ファイル: LetStatement.cs プロジェクト: HEm3R/MI-RUN-COMPILER
        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;
        }
コード例 #6
0
        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;
        }
コード例 #7
0
 public override string GetExpressionType(CompilationModel model)
 {
     var @class = model.GetClass(Expression.GetExpressionType(model));
     return @class.GetFieldType(Property);
 }
コード例 #8
0
        private ClassModel GetCorrectParent(CompilationModel model)
        {
            var className = FindParent<Class>().Name;
            var classModel = model.GetClass(className);

            if (ParentClass == "parent")
            {
                return classModel.ParentClassModel;
            }

            if (ParentClass != "this" && ParentClass != className)
            {
                var parents = new List<ClassModel>(); // add this

                while (classModel.Name != "Any")
                {
                    classModel = classModel.ParentClassModel;
                    parents.Add(classModel);
                }

                classModel = parents.SingleOrDefault(c => c.Name == ParentClass);

                if (classModel == null)
                {
                    throw new Exception(string.Format("Class with name {0} does not inherit from {1}!", className, ParentClass));
                }
            }

            return classModel;
        }
コード例 #9
0
        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;
        }
コード例 #10
0
 public override string GetExpressionType(CompilationModel model)
 {
     var @class = FindParent<Class>();
     var classModel = model.GetClass(@class.Name);
     return classModel.GetFieldType(Property);
 }