AVTOORecompilable.avt

Переключить прокрутку окна
Загрузить этот исходный код

/*
    Компилятор языка программирования
    Объектно-ориентированный продвинутый векторный транслятор

    Copyright © 2021, 2024 Малик Разработчик

    Это свободная программа: вы можете перераспространять ее и/или изменять
    ее на условиях Стандартной общественной лицензии GNU в том виде,
    в каком она была опубликована Фондом свободного программного обеспечения;
    либо версии 3 лицензии, либо (по вашему выбору) любой более поздней версии.

    Эта программа распространяется в надежде, что она будет полезной,
    но БЕЗО ВСЯКИХ ГАРАНТИЙ; даже без неявной гарантии ТОВАРНОГО ВИДА
    или ПРИГОДНОСТИ ДЛЯ ОПРЕДЕЛЕННЫХ ЦЕЛЕЙ. Подробнее см. в Стандартной
    общественной лицензии GNU.

    Вы должны были получить копию Стандартной общественной лицензии GNU
    вместе с этой программой. Если это не так, см.
    <https://www.gnu.org/licenses/>.
*/

package ru.malik.elaborarer.avtoo.lang;

public service AVTOORecompilable(Object, AVTOOConstants)
{
    /*<fold типы констант>*/
    public static final short CONST_Z  = (short) (' ' << 0o10 | 'Z'); /* boolean */
    public static final short CONST_C  = (short) (' ' << 0o10 | 'C'); /* char */
    public static final short CONST_R  = (short) (' ' << 0o10 | 'R'); /* real */
    public static final short CONST_D  = (short) (' ' << 0o10 | 'D'); /* double */
    public static final short CONST_D2 = (short) ('D' << 0o10 | '2'); /* double2 */
    public static final short CONST_D4 = (short) ('D' << 0o10 | '4'); /* double4 */
    public static final short CONST_D8 = (short) ('D' << 0o10 | '8'); /* double8 */
    public static final short CONST_F  = (short) (' ' << 0o10 | 'F'); /* float */
    public static final short CONST_F2 = (short) ('F' << 0o10 | '2'); /* float2 */
    public static final short CONST_F4 = (short) ('F' << 0o10 | '4'); /* float4 */
    public static final short CONST_F8 = (short) ('F' << 0o10 | '8'); /* float8 */
    public static final short CONST_B  = (short) (' ' << 0o10 | 'B'); /* byte */
    public static final short CONST_B2 = (short) ('B' << 0o10 | '2'); /* byte2 */
    public static final short CONST_B4 = (short) ('B' << 0o10 | '4'); /* byte4 */
    public static final short CONST_B8 = (short) ('B' << 0o10 | '8'); /* byte8 */
    public static final short CONST_S  = (short) (' ' << 0o10 | 'S'); /* short */
    public static final short CONST_S2 = (short) ('S' << 0o10 | '2'); /* short2 */
    public static final short CONST_S4 = (short) ('S' << 0o10 | '4'); /* short4 */
    public static final short CONST_S8 = (short) ('S' << 0o10 | '8'); /* short8 */
    public static final short CONST_I  = (short) (' ' << 0o10 | 'I'); /* int */
    public static final short CONST_I2 = (short) ('I' << 0o10 | '2'); /* int2 */
    public static final short CONST_I4 = (short) ('I' << 0o10 | '4'); /* int4 */
    public static final short CONST_I8 = (short) ('I' << 0o10 | '8'); /* int8 */
    public static final short CONST_J  = (short) (' ' << 0o10 | 'J'); /* long */
    public static final short CONST_J2 = (short) ('J' << 0o10 | '2'); /* long2 */
    public static final short CONST_J4 = (short) ('J' << 0o10 | '4'); /* long4 */
    public static final short CONST_J8 = (short) ('J' << 0o10 | '8'); /* long8 */
    public static final short CONST_ST = (short) ('S' << 0o10 | 'T'); /* строка (String) */
    public static final short CONST_PK = (short) ('P' << 0o10 | 'K'); /* пакет (Package) */
    public static final short CONST_TP = (short) ('T' << 0o10 | 'P'); /* тип (Type) */
    public static final short CONST_FL = (short) ('F' << 0o10 | 'L'); /* поле (Field) */
    public static final short CONST_PR = (short) ('P' << 0o10 | 'R'); /* свойство (Property) */
    public static final short CONST_CL = (short) ('C' << 0o10 | 'L'); /* вызываемый (Callable) */
    /* null — по нулевому индексу */
    /*</fold>*/

    /*<fold типы кусков>*/
    public static final int CHUNK_VERS = 'v' << 0o30 | 'e' << 0o20 | 'R' << 0o10 | 's';
    public static final int CHUNK_CONS = 'c' << 0o30 | 'o' << 0o20 | 'N' << 0o10 | 's';
    public static final int CHUNK_SURC = 's' << 0o30 | 'u' << 0o20 | 'R' << 0o10 | 'c';
    public static final int CHUNK_PACK = 'p' << 0o30 | 'a' << 0o20 | 'C' << 0o10 | 'k';
    public static final int CHUNK_TYPE = 't' << 0o30 | 'y' << 0o20 | 'P' << 0o10 | 'e';
    public static final int CHUNK_CFLD = 'c' << 0o30 | 'f' << 0o20 | 'L' << 0o10 | 'd';
    public static final int CHUNK_SFLD = 's' << 0o30 | 'f' << 0o20 | 'L' << 0o10 | 'd';
    public static final int CHUNK_METH = 'm' << 0o30 | 'e' << 0o20 | 'T' << 0o10 | 'h';
    public static final int CHUNK_OPER = 'o' << 0o30 | 'p' << 0o20 | 'E' << 0o10 | 'r';
    public static final int CHUNK_PROP = 'p' << 0o30 | 'r' << 0o20 | 'O' << 0o10 | 'p';
    public static final int CHUNK_CODE = 'c' << 0o30 | 'o' << 0o20 | 'D' << 0o10 | 'e';
    public static final int CHUNK_IEND = 'I' << 0o30 | 'E' << 0o20 | 'N' << 0o10 | 'D';
    /*</fold>*/

    /*<fold инструкции>*/
    public static final int INST_METHOD_ENTER        = 0x8000;
    public static final int INST_SWAP                = 0x8100;
    public static final int INST_BOUND               = 0x8200;
    public static final int INST_THROW               = 0x8300;
    public static final int INST_LOAD_STATIC         = 0x8400;
    public static final int INST_LOAD_STATICW        = 0x8500;
    public static final int INST_LOAD_LOCAL          = 0x8600;
    public static final int INST_LOAD_LOCALW         = 0x8700;
    public static final int INST_LOAD_CONST          = 0x8800;
    public static final int INST_LOAD_CONSTW         = 0x8900;
    public static final int INST_READ_ELEMENT        = 0x8a00;
    public static final int INST_READ_ELEMENTI       = 0x8b00;
    public static final int INST_READ_COMPONENT      = 0x8c00;
    public static final int INST_READ_FIELD          = 0x8d00;
    public static final int INST_READ_SPECIAL        = 0x8e00;
    public static final int INST_READ_PROPERTY       = 0x8f00;
    public static final int INST_STORE_STATIC        = 0x9000;
    public static final int INST_STORE_STATIC_NULL   = 0x9100;
    public static final int INST_STORE_STATIC_SHORT  = 0x9200;
    public static final int INST_STORE_STATIC_INT    = 0x9300;
    public static final int INST_STORE_LOCAL         = 0x9400;
    public static final int INST_STORE_LOCAL_NULL    = 0x9500;
    public static final int INST_STORE_LOCAL_SHORT   = 0x9600;
    public static final int INST_STORE_LOCAL_INT     = 0x9700;
    public static final int INST_INC_PRED_LOAD_LOCAL = 0x9800;
    public static final int INST_INC_POST_LOAD_LOCAL = 0x9900;
    public static final int INST_DEC_PRED_LOAD_LOCAL = 0x9a00;
    public static final int INST_DEC_POST_LOAD_LOCAL = 0x9b00;
    public static final int INST_WRITE_COMPONENT     = 0x9c00;
    public static final int INST_WRITE_FIELD         = 0x9d00;
    public static final int INST_WRITE_SPECIAL       = 0x9e00;
    public static final int INST_WRITE_PROPERTY      = 0x9f00;
    public static final int INST_SWITCH_TABLE        = 0xa000;
    public static final int INST_SWITCH_LOOKUP       = 0xa100;
    public static final int INST_JUMP                = 0xa200;
    public static final int INST_LOAD_INTERRUPT      = 0xa300;
    public static final int INST_LOAD_CONST_BYTE     = 0xa400;
    public static final int INST_LOAD_CONST_NULL     = 0xa500;
    public static final int INST_LOAD_CONST_SHORT    = 0xa600;
    public static final int INST_LOAD_CONST_INT      = 0xa700;
    public static final int INST_REF_EQ              = 0xa800;
    public static final int INST_REF_EQW             = 0xa900;
    public static final int INST_REF_NE              = 0xaa00;
    public static final int INST_REF_NEW             = 0xab00;
    public static final int INST_REF_IS_NULL         = 0xac00;
    public static final int INST_REF_IS_NULLW        = 0xad00;
    public static final int INST_REF_IS_OBJECT       = 0xae00;
    public static final int INST_REF_IS_OBJECTW      = 0xaf00;
    public static final int INST_CLINIT_TRY_LOCK     = 0xb000;
    public static final int INST_CLINIT_UNLOCK       = 0xb100;
    public static final int INST_MONITOR_ENTER       = 0xb200;
    public static final int INST_MONITOR_LEAVE       = 0xb300;
    public static final int INST_FINALLY_ENTER       = 0xb400;
    public static final int INST_FINALLY_LEAVE       = 0xb500;
    public static final int INST_NEW_ARRAY           = 0xb600;
    public static final int INST_INVOKE_FINALLY      = 0xb700;
    public static final int INST_INVOKE_STATIC       = 0xb800;
    public static final int INST_INVOKE_STATICD      = 0xb900;
    public static final int INST_INVOKE_SPECIAL      = 0xba00;
    public static final int INST_INVOKE_SPECIALD     = 0xbb00;
    public static final int INST_INVOKE_VIRTUAL      = 0xbc00;
    public static final int INST_INVOKE_VIRTUALD     = 0xbd00;
    public static final int INST_INVOKE_SERVICE      = 0xbe00;
    public static final int INST_INVOKE_SERVICED     = 0xbf00;
    public static final int INST_VECT_DIV            = 0xc000;
    public static final int INST_VECT_PCK            = 0xc100;
    public static final int INST_VECT_LUP            = 0xc200;
    public static final int INST_VECT_UUP            = 0xc300;
    public static final int INST_VECT_MUL            = 0xc400;
    public static final int INST_VECT_SHL            = 0xc500;
    public static final int INST_VECT_SHR            = 0xc600;
    public static final int INST_VECT_SHRU           = 0xc700;
    public static final int INST_VECT_ADD            = 0xc800;
    public static final int INST_VECT_SUB            = 0xc900;
    public static final int INST_VECT_EQ             = 0xca00;
    public static final int INST_VECT_NE             = 0xcb00;
    public static final int INST_VECT_GT             = 0xcc00;
    public static final int INST_VECT_GE             = 0xcd00;
    public static final int INST_VECT_LT             = 0xce00;
    public static final int INST_VECT_LE             = 0xcf00;
    public static final int INST_SCAL_DIV            = 0xd000;
    public static final int INST_SCAL_DIVU           = 0xd100;
    public static final int INST_SCAL_REM            = 0xd200;
    public static final int INST_SCAL_REMU           = 0xd300;
    public static final int INST_SCAL_MUL            = 0xd400;
    public static final int INST_SCAL_SHL            = 0xd500;
    public static final int INST_SCAL_SHR            = 0xd600;
    public static final int INST_SCAL_SHRU           = 0xd700;
    public static final int INST_SCAL_ADD            = 0xd800;
    public static final int INST_SCAL_SUB            = 0xd900;
    public static final int INST_SCAL_EQ             = 0xda00;
    public static final int INST_SCAL_NE             = 0xdb00;
    public static final int INST_SCAL_GT             = 0xdc00;
    public static final int INST_SCAL_GE             = 0xdd00;
    public static final int INST_SCAL_LT             = 0xde00;
    public static final int INST_SCAL_LE             = 0xdf00;
    public static final int INST_VECT_NEG            = 0xe000;
    public static final int INST_CAST_TO             = 0xe100;
    public static final int INST_INC_LOCAL           = 0xe200;
    public static final int INST_DEC_LOCAL           = 0xe300;
    public static final int INST_BIT_NOT             = 0xe400;
    public static final int INST_BIT_AND             = 0xe500;
    public static final int INST_BIT_OR              = 0xe600;
    public static final int INST_BIT_XOR             = 0xe700;
    public static final int INST_DUP1                = 0xe800;
    public static final int INST_DUP2                = 0xe900;
    public static final int INST_VECT_HMUL           = 0xea00;
    public static final int INST_VECT_HMULU          = 0xeb00;
    public static final int INST_VECT_SADD           = 0xec00;
    public static final int INST_VECT_SADDU          = 0xed00;
    public static final int INST_VECT_SSUB           = 0xee00;
    public static final int INST_VECT_SSUBU          = 0xef00;
    public static final int INST_SCAL_NEG            = 0xf000;
    public static final int INST_INSTANCE_OF         = 0xf100;
    public static final int INST_TEST_EQZ            = 0xf200;
    public static final int INST_TEST_NEZ            = 0xf300;
    public static final int INST_NEW_VECTOR          = 0xf400;
    public static final int INST_NEW_INSTANCE        = 0xf500;
    public static final int INST_NEW_ARRAY_MONO      = 0xf600;
    public static final int INST_NEW_ARRAY_MULTI     = 0xf700;
    public static final int INST_DUP1X1              = 0xf800;
    public static final int INST_DUP1X2              = 0xf900;
    public static final int INST_METHOD_LEAVE        = 0xfa00;
    public static final int INST_EXCEPT_ENTER        = 0xfb00;
    public static final int INST_EXCEPT_TRY          = 0xfc00;
    public static final int INST_EXCEPT_CATCH        = 0xfd00;
    public static final int INST_EXCEPT_FINALLY      = 0xfe00;
    public static final int INST_EXCEPT_LEAVE        = 0xff00;
    /*</fold>*/

    /*<fold флаги инструкций>*/
    public static final int FLAG_WEAK         = 0x0100; /* флаг работы со слабой ссылкой          */
    public static final int FLAG_DISCARD      = 0x0100; /* флаг отброса результата метода         */
    public static final int FLAG_BOOLEAN_JUMP = 0x0080; /* флаг ветвления по логическому значению */
    /*</fold>*/

    /*<fold необязательные операнды>*/
    public static final int OPERAND_NONE     = 0; /* нет операнда          */
    public static final int OPERAND_CONSTANT = 1; /* константа             */
    public static final int OPERAND_GLOBAL   = 2; /* глобальная переменная */
    public static final int OPERAND_LOCAL    = 3; /* локальная переменная  */
    /*</fold>*/

    /*<fold способы сохранения значения в локальной переменной>*/
    public static final int STORE_NORMAL        = 1; /* простое присвоение значения        */
    public static final int STORE_DECLARE_LOCAL = 2; /* объявление для нормального доступа */
    public static final int STORE_DECLARE_WITH  = 3; /* объявление для быстрого доступа    */
    /*</fold>*/

    /*<fold поддерживаемая версия>*/
    public static final int VERSION_AVTR = 1 << 0x10 | 1;
    /*</fold>*/

    /*<fold сигнатура>*/
    public static final long SIGNATURE_AVTR = 0x415654520d0a1a0aL;
    /*</fold>*/

    /*<fold флаги данных>*/
    private static final int FLAG_NEXT  = 0x8000; /* флаг следующей инструкции */
    private static final int FLAG_LONG  = 0x4000; /* флаг длинного номера      */
    private static final int FLAG_LABEL = 0x2000; /* флаг метки                */
    /*</fold>*/

    public static boolean isLongEncoded(int encoded) { return encoded < 0 || encoded > 0xffff; }

    public static boolean isLongNumber(int encoded) { return (encoded & FLAG_LONG) != 0; }

    public static boolean isInstruction(int encoded) { return (encoded & 0x8000) != 0; }

    public static boolean isNext(int encoded) { return (encoded & FLAG_NEXT) != 0; }

    public static boolean decodeDeclareLabel(int encoded) { return (encoded & FLAG_LABEL) != 0; }

    public static int decodeDeclareNumber(int encoded) { return isLongEncoded(encoded) ? encoded << 3 >> 3 : encoded << 19 >> 19; }

    public static int decodeUsing(int encoded) { return isLongEncoded(encoded) ? encoded << 2 >> 2 : encoded << 18 >> 18; }

    public static int decodeType(int encoded) { return (encoded & 0x1f) + VOID; }

    public static int decodeStore(int encoded) { return (encoded = (encoded >> 5) & 3) < STORE_NORMAL ? STORE_NORMAL : encoded; }

    public static int decodeOperand(int encoded) { return (encoded >> 5) & 3; }

    public static int decodeVectorIndex(int encoded) { return (encoded >> 5) & 7; }

    public static int encodeDeclare(boolean label, int number) throws UnencodableDataException {
        if(number < -0x10000000 || number > 0x0fffffff)
        {
            throw new UnencodableDataException(String.format(package.getResourceString("binary-source.format.order-number-too-large"), new Object[] { Int.toString(number) }));
        }
        return number < -0x1000 || number > 0x0fff ? (label ? (FLAG_LONG | FLAG_LABEL) << 0x10 : FLAG_LONG << 0x10) | number & 0x1fffffff : (label ? FLAG_LABEL : 0) | number & 0x1fff;
    }

    public static int encodeNext() { return FLAG_NEXT; }

    public static int encodeUsing(int number) throws UnencodableDataException {
        if(number < -0x10000000 || number > 0x0fffffff)
        {
            throw new UnencodableDataException(String.format(package.getResourceString("binary-source.format.order-number-too-large"), new Object[] { Int.toString(number) }));
        }
        return number < -0x2000 || number > 0x1fff ? FLAG_LONG << 0x10 | number & 0x3fffffff : number & 0x3fff;
    }

    public static int encodeType(int kind) { return kind - VOID; }

    public static int encodeType(Type type) { return type == null ? REF - VOID : type.kind - VOID; }

    public static int encodeStore(int store) { return store << 5; }

    public static int encodeOperand(TableItem operand) {
        return operand instanceof Constant ? OPERAND_CONSTANT << 5 : operand instanceof Field ? OPERAND_GLOBAL << 5 : operand instanceof Local ? OPERAND_LOCAL << 5 : OPERAND_NONE << 5;
    }

    public static int encodeVectorIndex(int index) { return (index & 7) << 5; }
}