示例#1
0
 public DeclarationStatement(List <Identifier> Identifiers, MiniPascalType Type)
 {
     foreach (Identifier ident in Identifiers)
     {
         variables.Add(new Variable(ident, Type, false));
     }
     this.Type = Type;
 }
示例#2
0
 public void CallRead(MiniPascalType Type)
 {
     generator.Emit(OpCodes.Call, typeof(Console).GetMethod(nameof(Console.ReadLine)));
     if (Type.SimpleType.Equals(SimpleType.Integer))
     {
         generator.Emit(OpCodes.Call, typeof(int).GetMethod(nameof(int.Parse), SimpleType.String.CLRTypeArray));
     }
     else if (Type.SimpleType.Equals(SimpleType.Real))
     {
         generator.Emit(OpCodes.Call, typeof(CultureInfo).GetProperty(nameof(CultureInfo.InvariantCulture)).GetGetMethod());
         generator.Emit(OpCodes.Call, typeof(float).GetMethod(nameof(float.Parse), new[] { typeof(string), typeof(IFormatProvider) }));
     }
     else if (Type.SimpleType.Equals(SimpleType.Boolean))
     {
         generator.Emit(OpCodes.Call, typeof(bool).GetMethod(nameof(bool.Parse), SimpleType.String.CLRTypeArray));
     }
 }
示例#3
0
 public virtual MiniPascalType NodeType(Scope Current)
 {
     Type = firstExpression.NodeType(Current);
     foreach (OperatorPair <T> expr in simpleExpressions)
     {
         MiniPascalType anotherType = expr.Operand.NodeType(Current);
         if (!Type.Equals(anotherType))
         {
             throw new InvalidTypeException(anotherType, Type);
         }
         if (!Type.HasOperatorDefined(expr.Operator))
         {
             throw new UndefinedOperatorException(Type, expr.Operator);
         }
         Type = anotherType.BinaryOperation(expr.Operator).ReturnType;
     }
     return(Type);
 }
示例#4
0
 public void CallPrint(MiniPascalType Type)
 {
     if (Type.Equals(MiniPascalType.Boolean))
     {
         Label trueRes = generator.DefineLabel();
         Label end     = generator.DefineLabel();
         generator.Emit(OpCodes.Ldc_I4_1);
         generator.Emit(OpCodes.Ceq);
         generator.Emit(OpCodes.Brtrue_S, trueRes);
         PushString(bool.FalseString);
         generator.Emit(OpCodes.Br, end);
         generator.MarkLabel(trueRes);
         PushString(bool.TrueString);
         generator.MarkLabel(end);
         generator.Emit(OpCodes.Call, typeof(Console).GetMethod(nameof(Console.Write), SimpleType.String.CLRTypeArray));
     }
     else
     {
         generator.Emit(OpCodes.Call, typeof(Console).GetMethod(nameof(Console.Write), Type.SimpleType.CLRTypeArray));
     }
 }
示例#5
0
 public TypeMismatchException(MiniPascalType Expected, MiniPascalType Found)
 {
     this.Expected = Expected;
     this.Found    = Found;
 }
 public UndefinedOperatorException(MiniPascalType Type, OperatorType Operator)
 {
     this.Type     = Type;
     this.Operator = Operator;
 }
示例#7
0
 public InvalidArrayIndexTypeException(MiniPascalType Found)
 {
     this.Found = Found;
 }
示例#8
0
 public InvalidTypeException(MiniPascalType Found, params MiniPascalType[] Expected)
 {
     this.Expected = Expected;
     this.Found    = Found;
 }
 public ArrayAssigmentExpection(SimpleType Expected, MiniPascalType Found)
 {
     this.Expected = Expected;
     this.Found    = Found;
 }
示例#10
0
        public CILEmitter StartProcedure(Identifier Identifier, Parameters Parameters, MiniPascalType ReturnType)
        {
            List <Type> types = new List <Type>();

            foreach (Variable variable in Parameters.All)
            {
                Type type  = variable.Type.SimpleType.CLRType;
                bool byRef = variable.IsReference;
                bool array = variable.Type.IsArray;
                if (array)
                {
                    type = type.MakeArrayType();
                }
                if (byRef)
                {
                    type = type.MakeByRefType();
                }
                types.Add(type);
            }
            Type          ret = ReturnType == null ? null : ReturnType.SimpleType.CLRType;
            MethodBuilder mb  = mainType.DefineMethod(Identifier.ToString(), MethodAttributes.Private | MethodAttributes.Static, ret, types.ToArray());

            procedures.Add(Identifier, mb);
            return(new CILEmitter(mb.GetILGenerator(), mainType, mb, scope, Parameters, this));
        }
示例#11
0
 public void CreateSimpleVariable(Identifier Identifier, MiniPascalType Type)
 {
     CreateVariable(Identifier, Type.SimpleType.CLRType);
 }
示例#12
0
 public void CreateArrayVariable(Identifier Identifier, MiniPascalType Type)
 {
     CreateVariable(Identifier, Type.SimpleType.CLRType.MakeArrayType());
 }
示例#13
0
 public void PushArray(MiniPascalType Type)
 {
     generator.Emit(OpCodes.Newarr, Type.SimpleType.CLRType);
 }
示例#14
0
 public void LoadArrayIndexAddress(MiniPascalType Type)
 {
     generator.Emit(OpCodes.Ldelema, Type.SimpleType.CLRType);
 }
示例#15
0
 public ArrayRequiredException(MiniPascalType Found)
 {
     this.Found = Found;
 }