APX Virtual Machine v2 ====================== Experimental version of APX VM currently being implemented in c-apx. Instruction list ----------------- Each instruction starts with a single opcode byte followed by 0 or more additional bytes. +---------------+-----------------+--------+----------------------------------------+--------------------------+ | Opcode Number | Opcode Name | Size | Additional instruction bytes | Description | +===============+=================+========+========================================+==========================+ | 0 | NOP | 1 | | No operation | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 1 | PACK_PROG_HDR | 7 | 1. VersionByte0 (LSB) | pack program header | | | | | 2. VersionByte1 (MSB) | | | | | | 3. progLenType0 (LSB) | | | | | | 4. progLenType1 | | | | | | 5. progLenType2 | | | | | | 6. progLenType3 (MSB) | | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 2 | UNPACK_PROG_HDR | 7 | 1. VersionByte0 (LSB) | pack program header | | | | | 2. VersionByte1 (MSB) | | | | | | 3. progLenType0 (LSB) | | | | | | 4. progLenType1 | | | | | | 5. progLenType2 | | | | | | 6. progLenType3 (MSB) | | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 3 | PACK_U8 | 1 | | pack single uint8 | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 4 | PACK_U16 | 1 | | pack single uint16 | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 5 | PACK_U32 | 1 | | pack single uint32 | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 6 | PACK_S8 | 1 | | pack single sint8 | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 7 | PACK_S16 | 1 | | pack single sint16 | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 8 | PACK_S32 | 1 | | pack single sint32 | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 9 | PACK_STR | 3 | 1. LengthByte0(LSB) | pack string | | | | | 2. LengthByte1(MSB) | | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 10 | PACK_U8AR | 3 | 1. LengthByte0(LSB) | pack uint8 array | | | | | 2. LengthByte1(MSB) | | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 11 | PACK_U16AR | 3 | 1. LengthByte0(LSB) | pack uint16 array | | | | | 2. LengthByte1(MSB) | | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 12 | PACK_U32AR | 3 | 1. LengthByte0(LSB) | pack uint32 array | | | | | 2. LengthByte1(MSB) | | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 13 | PACK_S8AR | 3 | 1. LengthByte0(LSB) | pack uint8 array | | | | | 2. LengthByte1(MSB) | | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 14 | PACK_S16AR | 3 | 1. LengthByte0(LSB) | pack uint16 array | | | | | 2. LengthByte1(MSB) | | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 15 | PACK_S32AR | 3 | 1. LengthByte0(LSB) | pack uint32 array | | | | | 2. LengthByte1(MSB) | | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 64 | UNPACK_U8 | 1 | | unpack single uint8 | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 65 | UNPACK_U16 | 1 | | unpack single uint16 | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 66 | UNPACK_U32 | 1 | | unpack single uint32 | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 67 | UNPACK_S8 | 1 | | unpack single sint8 | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 68 | UNPACK_S16 | 1 | | unpack single sint16 | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 69 | UNPACK_S32 | 1 | | unpack single sint32 | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 70 | UNPPACK_STR | 3 | 1. LengthByte0(LSB) | unpack string | | | | | 2. LengthByte1(MSB) | | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 71 | UNPACK_U8AR | 3 | 1. LengthByte0(LSB) | unpack uint8 array | | | | | 2. LengthByte1(MSB) | | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 72 | UNPACK_U16AR | 3 | 1. LengthByte0(LSB) | unpack uint16 array | | | | | 2. LengthByte1(MSB) | | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 73 | UNPACK_U32AR | 3 | 1. LengthByte0(LSB) | unpack uint32 array | | | | | 2. LengthByte1(MSB) | | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 74 | UNPACK_S8AR | 3 | 1. LengthByte0(LSB) | unpack sint8 array | | | | | 2. LengthByte1(MSB) | | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 75 | UNPACK_S16AR | 3 | 1. LengthByte0(LSB) | unpack sint16 array | | | | | 2. LengthByte1(MSB) | | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 76 | UNPACK_S32AR | 3 | 1. LengthByte0(LSB) | unpack sint32 array | | | | | 2. LengthByte1(MSB) | | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 128 | RECORD_ENTER | 1 | | record inside of record | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 129 | RECORD_SELECT | 3 | 1. ElementIdByte0(LSB) | ID of record element | | | | | 2. ElementIdByte1(MSB) | | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 130 | RECORD_LEAVE | 1 | | | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 131 | ARRAY_ENTER | 1 | | Used for array of | | | | | | records | +---------------+-----------------+--------+----------------------------------------+--------------------------+ | 132 | ARRAY_LEAVE | 1 | | | +---------------+-----------------+--------+----------------------------------------+--------------------------+ APX Variants ------------ Variants are variables that can store values of different types. They are supported in one way or another in most programming languages. **Types of variants:** - Scalars (integers, strings) - Lists (list of variants) - Maps (key-value map to variants) Variant types are identified internally using integers according to the following table: +-------+---------------+ | Value | Name | +=======+===============+ | -1 | VTYPE_INVALID | +-------+---------------+ | 0 | VTYPE_SCALAR | +-------+---------------+ | 1 | VTYPE_LIST | +-------+---------------+ | 2 | VTYPE_MAP | +-------+---------------+ Variant Language Mapping ~~~~~~~~~~~~~~~~~~~~~~~~ Each APX implementation maps the APX variant according to what is available to the language. +-----------------------------------------------------------------+--------------+--------------+----------------------+ | Programming Language | VTYPE_SCALAR | VTYPE_LIST | VTYPE_MAP | +=================================================================+==============+==============+======================+ | C (with `dtl_type `_ library) | dtl_sv_t | dtl_av_t | dtl_hv_t | +-----------------------------------------------------------------+--------------+--------------+----------------------+ | C++ (with Qt variants) | QVariant | QVariantList | QVariantMap | +-----------------------------------------------------------------+--------------+--------------+----------------------+ | Python | (int, str) | list | dict | +-----------------------------------------------------------------+--------------+--------------+----------------------+ | Visual Basic (Excel) | Variant | Variant | Scripting.Dictionary | +-----------------------------------------------------------------+--------------+--------------+----------------------+ Instruction Details ------------------- TBD