language

some fools attempt at an interpreted language
Log | Files | Refs | README

ins_mdata.h (10663B)


      1 #ifndef INS_MDATA_H
      2 #define INS_MDATA_H
      3 
      4 /* Macro used below.
      5  * It should be self-explainitory
      6  * i.e. encode( 3, 2, 1, 0 ) = 0b11100100
      7  *             11,10,01,00   = 0xE4
      8  */
      9 #define encode(n, a0, a1, a2) \
     10 	( n << 6 | a0 << 4 | a1 << 2 | a2 );
     11 
     12 #define NAMELEN 2
     13 #define ADDRLEN 2
     14 
     15 #define A_BYTE 0
     16 #define A_NAME 1
     17 #define A_ADDR 2
     18 #define A_DYNC 3
     19 
     20 /* This definition is ran in `is.c`
     21  *
     22  *  INS_MDATA[ <opcode> ] <- encode( <number of arguements>, <type..3> )
     23  */
     24 #define INS_MDATA_DEF()                                              \
     25 /* NULL      */ INS_MDATA[0x00] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     26 /* SYNC      */ INS_MDATA[0x01] = encode(1, A_BYTE, A_BYTE, A_BYTE); \
     27 /* PRINT     */ INS_MDATA[0x02] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     28 /* DEBUG     */ INS_MDATA[0x03] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     29 /* ARGB      */ INS_MDATA[0x0E] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     30 /* LIBC      */ INS_MDATA[0x0F] = encode(1, A_ADDR, A_BYTE, A_BYTE); \
     31                                                                      \
     32 /* POP       */ INS_MDATA[0x10] = encode(1, A_BYTE, A_BYTE, A_BYTE); \
     33 /* ROT       */ INS_MDATA[0x11] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     34 /* DUP       */ INS_MDATA[0x12] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     35 /* ROT_THREE */ INS_MDATA[0x13] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     36                                                                      \
     37 /* DEC       */ INS_MDATA[0x20] = encode(3, A_BYTE, A_BYTE, A_NAME); \
     38 /* LOV       */ INS_MDATA[0x21] = encode(2, A_BYTE, A_NAME, A_BYTE); \
     39 /* STV       */ INS_MDATA[0x22] = encode(2, A_BYTE, A_NAME, A_BYTE); \
     40 /* CTV       */ INS_MDATA[0x23] = encode(3, A_BYTE, A_NAME, A_DYNC); \
     41 /* CTS       */ INS_MDATA[0x24] = encode(1, A_DYNC, A_BYTE, A_BYTE); \
     42                                                                      \
     43 /* TYPEOF    */ INS_MDATA[0x30] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     44 /* CAST      */ INS_MDATA[0x31] = encode(1, A_BYTE, A_BYTE, A_BYTE); \
     45                                                                      \
     46 /* ADD       */ INS_MDATA[0x40] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     47 /* SUB       */ INS_MDATA[0x41] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     48 /* MULT      */ INS_MDATA[0x42] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     49 /* DIV       */ INS_MDATA[0x43] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     50 /* POW       */ INS_MDATA[0x44] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     51 /* BRT       */ INS_MDATA[0x45] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     52 /* SIN       */ INS_MDATA[0x46] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     53 /* COS       */ INS_MDATA[0x47] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     54 /* TAN       */ INS_MDATA[0x48] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     55 /* ISIN      */ INS_MDATA[0x49] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     56 /* ICOS      */ INS_MDATA[0x4A] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     57 /* ITAN      */ INS_MDATA[0x4B] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     58 /* MOD       */ INS_MDATA[0x4C] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     59 /* BOR       */ INS_MDATA[0x4D] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     60 /* BXOR      */ INS_MDATA[0x4E] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     61 /* BNAND     */ INS_MDATA[0x4F] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     62                                                                      \
     63 /* GTHAN     */ INS_MDATA[0x50] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     64 /* LTHAN     */ INS_MDATA[0x51] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     65 /* G_THAN_EQ */ INS_MDATA[0x52] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     66 /* G_LHAN_EQ */ INS_MDATA[0x53] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     67 /* EQ        */ INS_MDATA[0x54] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     68 /* NE        */ INS_MDATA[0x55] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     69 /* NOT       */ INS_MDATA[0x56] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     70 /* OR        */ INS_MDATA[0x57] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     71 /* AND       */ INS_MDATA[0x58] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     72                                                                      \
     73 /* STARTL    */ INS_MDATA[0x60] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     74 /* CLOOP     */ INS_MDATA[0x61] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     75 /* BREAK     */ INS_MDATA[0x6E] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     76 /* ENDL      */ INS_MDATA[0x6F] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     77                                                                      \
     78 /* GOTO      */ INS_MDATA[0x70] = encode(1, A_ADDR, A_BYTE, A_BYTE); \
     79 /* JUMPF     */ INS_MDATA[0x71] = encode(1, A_BYTE, A_BYTE, A_BYTE); \
     80 /* IFDO      */ INS_MDATA[0x72] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     81 /* ELSE      */ INS_MDATA[0x73] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     82 /* DONE      */ INS_MDATA[0x7E] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     83 /* CALL      */ INS_MDATA[0x7F] = encode(2, A_BYTE, A_NAME, A_BYTE); \
     84                                                                      \
     85 /* GETN      */ INS_MDATA[0x80] = encode(1, A_NAME, A_BYTE, A_BYTE); \
     86 /* SETN      */ INS_MDATA[0x81] = encode(1, A_NAME, A_BYTE, A_BYTE); \
     87 /* CALLM     */ INS_MDATA[0x82] = encode(1, A_NAME, A_BYTE, A_BYTE); \
     88 /* INDEXO    */ INS_MDATA[0x83] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     89 /* MODO      */ INS_MDATA[0x84] = encode(1, A_BYTE, A_BYTE, A_BYTE); \
     90                                                                      \
     91 /* RETURN    */ INS_MDATA[0xF0] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     92 /* NEW       */ INS_MDATA[0xF1] = encode(2, A_BYTE, A_NAME, A_BYTE); \
     93 /* ENDCLASS  */ INS_MDATA[0xF2] = encode(0, A_BYTE, A_BYTE, A_BYTE); \
     94 /* DENS      */ INS_MDATA[0xFD] = encode(1, A_BYTE, A_BYTE, A_BYTE); \
     95 /* DECLASS   */ INS_MDATA[0xFE] = encode(2, A_NAME, A_DYNC, A_BYTE); \
     96 /* DEFUN     */ INS_MDATA[0xFF] = encode(3, A_NAME, A_BYTE, A_DYNC);
     97 
     98 
     99 #define BTOI 0 // Byte to Integer
    100 #define BTOT 1 // Byte to Type
    101 #define DTOL 2 // Dynamic to Byte List
    102 #define DTOV 3 // Dynamic to Variable
    103 
    104 /* This definition is ran in `is.c`
    105  *
    106  *  INS_ADATA[ <opcode> ] = encode( <number of arguements>, <type..3> )
    107  */
    108 #define INS_ADATA_DEF()                                        \
    109 /* NULL      */ INS_ADATA[0x00] = encode(0, BTOI, BTOI, BTOI); \
    110 /* SYNC      */ INS_ADATA[0x01] = encode(1, BTOI, BTOI, BTOI); \
    111 /* PRINT     */ INS_ADATA[0x02] = encode(0, BTOI, BTOI, BTOI); \
    112 /* DEBUG     */ INS_ADATA[0x03] = encode(0, BTOI, BTOI, BTOI); \
    113 /* ARGB      */ INS_ADATA[0x0E] = encode(0, BTOI, BTOI, BTOI); \
    114 /* LIBC      */ INS_ADATA[0x0F] = encode(1, BTOI, BTOI, BTOI); \
    115                                                                \
    116 /* POP       */ INS_ADATA[0x10] = encode(1, BTOI, BTOI, BTOI); \
    117 /* ROT       */ INS_ADATA[0x11] = encode(0, BTOI, BTOI, BTOI); \
    118 /* DUP       */ INS_ADATA[0x12] = encode(0, BTOI, BTOI, BTOI); \
    119 /* ROT_THREE */ INS_ADATA[0x13] = encode(0, BTOI, BTOI, BTOI); \
    120                                                                \
    121 /* DEC       */ INS_ADATA[0x20] = encode(3, BTOI, BTOT, BTOI); \
    122 /* LOV       */ INS_ADATA[0x21] = encode(2, BTOI, BTOI, BTOI); \
    123 /* STV       */ INS_ADATA[0x22] = encode(2, BTOI, BTOI, BTOI); \
    124 /* CTV       */ INS_ADATA[0x23] = encode(3, BTOI, BTOI, DTOV); \
    125 /* CTS       */ INS_ADATA[0x24] = encode(1, DTOV, BTOI, BTOI); \
    126                                                                \
    127 /* TYPEOF    */ INS_ADATA[0x30] = encode(0, BTOI, BTOI, BTOI); \
    128 /* CAST      */ INS_ADATA[0x31] = encode(1, BTOT, BTOI, BTOI); \
    129                                                                \
    130 /* ADD       */ INS_ADATA[0x40] = encode(0, BTOI, BTOI, BTOI); \
    131 /* SUB       */ INS_ADATA[0x41] = encode(0, BTOI, BTOI, BTOI); \
    132 /* MULT      */ INS_ADATA[0x42] = encode(0, BTOI, BTOI, BTOI); \
    133 /* DIV       */ INS_ADATA[0x43] = encode(0, BTOI, BTOI, BTOI); \
    134 /* POW       */ INS_ADATA[0x44] = encode(0, BTOI, BTOI, BTOI); \
    135 /* BRT       */ INS_ADATA[0x45] = encode(0, BTOI, BTOI, BTOI); \
    136 /* SIN       */ INS_ADATA[0x46] = encode(0, BTOI, BTOI, BTOI); \
    137 /* COS       */ INS_ADATA[0x47] = encode(0, BTOI, BTOI, BTOI); \
    138 /* TAN       */ INS_ADATA[0x48] = encode(0, BTOI, BTOI, BTOI); \
    139 /* ISIN      */ INS_ADATA[0x49] = encode(0, BTOI, BTOI, BTOI); \
    140 /* ICOS      */ INS_ADATA[0x4A] = encode(0, BTOI, BTOI, BTOI); \
    141 /* ITAN      */ INS_ADATA[0x4B] = encode(0, BTOI, BTOI, BTOI); \
    142 /* MOD       */ INS_ADATA[0x4C] = encode(0, BTOI, BTOI, BTOI); \
    143 /* OR        */ INS_ADATA[0x4D] = encode(0, BTOI, BTOI, BTOI); \
    144 /* XOR       */ INS_ADATA[0x4E] = encode(0, BTOI, BTOI, BTOI); \
    145 /* NAND      */ INS_ADATA[0x4F] = encode(0, BTOI, BTOI, BTOI); \
    146                                                                \
    147 /* GTHAN     */ INS_ADATA[0x50] = encode(0, BTOI, BTOI, BTOI); \
    148 /* LTHAN     */ INS_ADATA[0x51] = encode(0, BTOI, BTOI, BTOI); \
    149 /* G_THAN_EQ */ INS_ADATA[0x52] = encode(0, BTOI, BTOI, BTOI); \
    150 /* G_LHAN_EQ */ INS_ADATA[0x53] = encode(0, BTOI, BTOI, BTOI); \
    151 /* EQ        */ INS_ADATA[0x54] = encode(0, BTOI, BTOI, BTOI); \
    152 /* NEQ       */ INS_ADATA[0x55] = encode(0, BTOI, BTOI, BTOI); \
    153 /* NOT       */ INS_ADATA[0x56] = encode(0, BTOI, BTOI, BTOI); \
    154 /* OR        */ INS_ADATA[0x57] = encode(0, BTOI, BTOI, BTOI); \
    155 /* AND       */ INS_ADATA[0x58] = encode(0, BTOI, BTOI, BTOI); \
    156                                                                \
    157 /* STARTL    */ INS_ADATA[0x60] = encode(0, BTOI, BTOI, BTOI); \
    158 /* CLOOP     */ INS_ADATA[0x61] = encode(0, BTOI, BTOI, BTOI); \
    159 /* BREAK     */ INS_ADATA[0x6E] = encode(0, BTOI, BTOI, BTOI); \
    160 /* ENDL      */ INS_ADATA[0x6F] = encode(0, BTOI, BTOI, BTOI); \
    161                                                                \
    162 /* GOTO      */ INS_ADATA[0x70] = encode(1, BTOI, BTOI, BTOI); \
    163 /* JUMPF     */ INS_ADATA[0x71] = encode(1, BTOI, BTOI, BTOI); \
    164 /* IFDO      */ INS_ADATA[0x72] = encode(0, BTOI, BTOI, BTOI); \
    165 /* ELSE      */ INS_ADATA[0x73] = encode(0, BTOI, BTOI, BTOI); \
    166 /* DONE      */ INS_ADATA[0x7E] = encode(0, BTOI, BTOI, BTOI); \
    167 /* CALL      */ INS_ADATA[0x7F] = encode(2, BTOI, BTOI, BTOI); \
    168                                                                \
    169 /* GETN      */ INS_ADATA[0x80] = encode(1, BTOI, BTOI, BTOI); \
    170 /* SETN      */ INS_ADATA[0x81] = encode(1, BTOI, BTOI, BTOI); \
    171 /* CALLM     */ INS_ADATA[0x82] = encode(1, BTOI, BTOI, BTOI); \
    172 /* INDEXO    */ INS_ADATA[0x83] = encode(0, BTOI, BTOI, BTOI); \
    173 /* MODO      */ INS_ADATA[0x84] = encode(1, BTOI, BTOI, BTOI); \
    174                                                                \
    175 /* RETURN    */ INS_ADATA[0xF0] = encode(0, BTOI, BTOI, BTOI); \
    176 /* NEW       */ INS_ADATA[0xF1] = encode(2, BTOI, BTOI, BTOI); \
    177 /* ENDCLASS  */ INS_MDATA[0xF2] = encode(0, BTOI, BTOI, BTOI); \
    178 /* DENS      */ INS_ADATA[0xFD] = encode(1, BTOI, BTOI, BTOI); \
    179 /* DECLASS   */ INS_ADATA[0xFE] = encode(2, BTOI, DTOL, BTOI); \
    180 /* DEFUN     */ INS_ADATA[0xFF] = encode(3, BTOI, BTOT, DTOL);
    181 
    182 #endif