school

thing1's amazing school repo
Log | Files | Refs | Submodules | README

types.h (1705B)


      1 #include <stdint.h>
      2 
      3 typedef enum types {
      4 	TI32 = 0,
      5 	TI64 = 1,
      6 	TU32 = 2,
      7 	TU64 = 3,
      8 
      9 	TChar = 4,
     10 	Tfloat = 5,
     11 	TArr = 6,
     12 	TVDef = 7,
     13 } types;
     14 
     15 // int types
     16 typedef struct I32 {
     17 	int32_t data;
     18 } I32;
     19 
     20 typedef struct I64 {
     21 	int64_t data;
     22 } I64;
     23 
     24 // uint types
     25 typedef struct U32 {
     26 	uint32_t data;
     27 } U32;
     28 
     29 typedef struct U64 {
     30 	uint64_t data;
     31 } U64;
     32 
     33 typedef struct Char {
     34 	char data;
     35 } Char;
     36 
     37 typedef struct Float {
     38 	float data;
     39 } Float;
     40 
     41 typedef struct Arr {
     42 	union literal *arr;
     43 	long len;
     44 } Arr;
     45 
     46 typedef struct Vdef {
     47 	char *id;
     48 	types type;	
     49 } Vdef;
     50 
     51 typedef union literal {
     52 	I32 *i32;
     53 	I64 *i64;
     54 	U32 *u32;
     55 	I64 *u64;
     56 	Char *ch;
     57 	Float *fl;
     58 
     59 	Arr *arr;
     60 	Vdef *vdef;
     61 } literal;
     62 
     63 typedef struct var {
     64 	literal *value;
     65 	types type;
     66 	char *id;
     67 } var;
     68 
     69 // built in functions
     70 typedef enum builtInFuncs {
     71 	// general
     72 	DEFUN = 0,
     73 	LET = 1,
     74 	SET = 2,
     75 	IF = 3,
     76 	ELIF = 4,
     77 	ELSE = 5,
     78 	FOR = 6,
     79 	WHILE = 7,
     80 	SYMBOL = 8,
     81 	
     82 	// arithmetic
     83 	ADD = 10,
     84 	SUB = 11,
     85 	MUL = 12,
     86 	DIV = 13,
     87 	
     88 	// comparison
     89 	EQ = 14,
     90 	NEQ = 15,
     91 	GT = 16,
     92 	LT = 17,
     93 	GTEQ = 18,
     94 	LTEQ = 19,
     95 
     96 	// misc
     97 	CAST = 20,
     98 	TYPEOF = 21,
     99 	EXIT = 22,
    100 	RETURN = 23, 
    101 	WRITE = 24,
    102 	NIL = -1,
    103 } builtInFuncs;
    104 
    105 // function type
    106 typedef struct functionToken { 
    107 	int id; // a function id to avoid strings
    108 	char *name; // the code for the function
    109 	builtInFuncs builtInFunc; // a built in functions
    110 } functionToken;
    111 
    112 typedef struct ast_node ast_node;
    113 
    114 typedef struct ast_node {
    115 	functionToken *func; // if it's not builtin then use this
    116 	literal **literalArgs; // the args of the node, this will be an array of literal values
    117 	ast_node **args; // the non litteral tokens
    118 	// if litteralArgs[x] is real then args[x] should be NULL, and vice versa
    119 } ast_node;