lli.h (942B)
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #include <stdbool.h> 5 #include <stdint.h> 6 7 typedef enum ttype { 8 BLIT, 9 SLIT, 10 ILIT, 11 STRLIT, 12 LABEL, 13 PAD, 14 15 /* defining all the values is un-needed, but it makes debugging from hexdump easier to see all the values */ 16 17 PUSH = 10, 18 PUSHA = 11, 19 20 DELB = 12, 21 DELS = 13, 22 DELI = 14, 23 24 STOREB = 15, 25 STORES = 16, 26 STOREI = 17, 27 28 DUPB = 18, 29 DUPS = 19, 30 DUPI = 20, 31 32 LOADB = 21, 33 LOADS = 22, 34 LOADI = 23, 35 36 ADD = 24, 37 SUB = 25, 38 DIV = 26, 39 MUL = 27, 40 41 JMP = 28, 42 JNZ = 29, 43 CALL = 30, 44 CALLNZ = 31, 45 RET = 32, 46 47 B2S = 33, 48 B2I = 34, 49 S2B = 35, 50 S2I = 36, 51 I2B = 37, 52 I2S = 38, 53 54 EQU = 39, 55 NEQ = 40, 56 LT = 42, 57 GT = 43, 58 LTE = 44, 59 GTE = 45, 60 61 HALT = 100, 62 } ttype; 63 64 typedef struct tval { 65 ttype type; 66 char *val; 67 } tval; 68 69 typedef struct stack { 70 int cap; /* in bytes */ 71 uint8_t *arr, *sptr; 72 } stack; 73 74 void 75 errormsg(const char *msg) { 76 fprintf(stderr, "error: %s\n", msg); 77 exit(1); 78 }