Пример #1
0
        private String ilSType(int type)
        {
            switch (type)
            {
            case Tok.TOK_FIXED:             return("int32");

            case Tok.TOK_FLOAT:             return("float32");

            case Tok.TOK_COMPLEX:   return("float64");

            case Tok.TOK_REAL:              return("float32");

            case Tok.TOK_BINARY:    return("int16");

            case Tok.TOK_DECIMAL:   return("int32");

            case Tok.TOK_VOID:              return("void");

            default:
                io.Abort("PL0401: unhandled type " + type);
                break;
            }
            return(null);
        }
Пример #2
0
        public void IL()
        {
            IAsm a = iroot;
            IAsm p;

            while (a != null)
            {
                switch (a.getIType())
                {
                case IAsm.I_INSN:
                    exe.Insn(a);
                    break;

                case IAsm.I_LABEL:
                    exe.Label(a);
                    break;

                case IAsm.I_BRANCH:
                    exe.Branch(a);
                    break;

                case IAsm.I_INSN_STORE:
                    exe.Store(a);
                    break;

                case IAsm.I_INSN_LOAD:
                    exe.Load(a);
                    break;

                case IAsm.I_INSN_LOAD_CONST:
                    exe.LoadConst(a);
                    break;

                case IAsm.I_FUNC_BEGIN:
                    exe.FuncBegin(a);
                    break;

                case IAsm.I_FUNC_END:
                    exe.FuncEnd();
                    break;

                case IAsm.I_CALL:
                    exe.Call(a);
                    break;

                case IAsm.I_RET:
                    exe.Ret(a);
                    break;

                case IAsm.I_FIELD:
                    exe.FieldDef(a);
                    break;

                case IAsm.I_LOCALDEF:
                    exe.LocalVars(localvars);
                    break;

                case IAsm.I_COMMENT:
                    break;

                default:
                    io.Abort("PL0301: unhandled instruction type " + a.getIType());
                    break;
                }
                p = a;
                a = a.getNext();
            }
        }
Пример #3
0
        void load_digits()
        {
            char last, c;
            bool O, H, B, D, got;

            O     = H = B = D = false;
            got   = false;
            value = new StringBuilder(Io.MAXSTR);
            int number = 0;

            skipWhite();
            last = '0';

            while (is_const(c = io.getNextChar()))
            {
                if (is_bin(last))
                {
                    B = true;
                }
                else
                if (is_oct(last))
                {
                    O = true;
                }
                else
                if (is_dec(last))
                {
                    D = true;
                }
                else
                if (is_hex(last))
                {
                    H = true;
                }
                value.Append(c);
                io.ReadChar();
                last = c;
            }
            if (io.getNextChar() == 'H' || io.getNextChar() == 'h')
            {
                got      = true;
                token_id = TOK_S_HEX;
                io.ReadChar();
            }
            if ((!got) && (io.getNextChar() == 'O' || io.getNextChar() == 'o'))
            {
                if ((O || B) && (!H) && (!D))
                {
                    got      = true;
                    token_id = TOK_S_OCT;
                    io.ReadChar();
                }
                else
                {
                    io.Abort("PL0201: invalid octal constant");
                }
            }
            if ((!got) && (last == 'D' || last == 'd'))
            {
                if ((O || B || D) && (!H))
                {
                    got      = true;
                    token_id = TOK_S_DEC;
                }
                else
                {
                    io.Abort("PL0202: invalid decimal constant");
                }
            }
            if ((!got) && (last == 'B' || last == 'b'))
            {
                if ((B) && (!H) && (!O) && (!D))
                {
                    got      = true;
                    token_id = TOK_S_BIN;
                    value.Remove(value.Length - 1, 1);
                }
                else
                {
                    io.Abort("PL0203: invalid binary constant");
                }
            }
            if ((!got))
            {
                if ((O || B || D) && (!H))
                {
                    got      = true;
                    token_id = TOK_S_DEC;
                }
                else
                {
                    io.Abort("PL0204: invalid decimal constant");
                }
            }
            skipWhite();

            switch (token_id)
            {
            case TOK_S_HEX:             number = Number.FromRadix(value.ToString(), 16); break;

            case TOK_S_OCT:             number = Number.FromRadix(value.ToString(), 8); break;

            case TOK_S_DEC:             number = Number.FromRadix(value.ToString(), 10); break;

            case TOK_S_BIN:             number = Number.FromRadix(value.ToString(), 2); break;
            }
            value = new StringBuilder();
            value.Append(number.ToString());

            token_id = TOK_DIGITS;
        }
Пример #4
0
 void typeCheckAssign(int exprType, int varType)
 {
     if (varType >= exprType)
     {
         return;
     }
     if ((varType < Tok.TOK_FLOAT) && (exprType >= Tok.TOK_FLOAT))
     {
         io.Abort("PL0101: invalid typecast (float to int)");
     }
     if ((varType == Tok.TOK_BINARY) && (exprType > Tok.TOK_BINARY))
     {
         io.Abort("PL0102: invalid typecast (long int to short int)");
     }
     if ((varType < Tok.TOK_COMPLEX) && (exprType == Tok.TOK_COMPLEX))
     {
         io.Abort("PL0103: invalid typecast (long float to short float)");
     }
 }