public DeclarationStatement(List <Identifier> Identifiers, MiniPascalType Type)
 {
     foreach (Identifier ident in Identifiers)
     {
         variables.Add(new Variable(ident, Type, false));
     }
     this.Type = Type;
 }
Beispiel #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));
     }
 }
Beispiel #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);
 }
Beispiel #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));
     }
 }
Beispiel #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;
 }
Beispiel #7
0
 public InvalidArrayIndexTypeException(MiniPascalType Found)
 {
     this.Found = Found;
 }
Beispiel #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;
 }
Beispiel #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));
        }
Beispiel #11
0
 public void CreateSimpleVariable(Identifier Identifier, MiniPascalType Type)
 {
     CreateVariable(Identifier, Type.SimpleType.CLRType);
 }
Beispiel #12
0
 public void CreateArrayVariable(Identifier Identifier, MiniPascalType Type)
 {
     CreateVariable(Identifier, Type.SimpleType.CLRType.MakeArrayType());
 }
Beispiel #13
0
 public void PushArray(MiniPascalType Type)
 {
     generator.Emit(OpCodes.Newarr, Type.SimpleType.CLRType);
 }
Beispiel #14
0
 public void LoadArrayIndexAddress(MiniPascalType Type)
 {
     generator.Emit(OpCodes.Ldelema, Type.SimpleType.CLRType);
 }
 public ArrayRequiredException(MiniPascalType Found)
 {
     this.Found = Found;
 }