51 lines
796 B
C
51 lines
796 B
C
|
#include <stdint.h>
|
||
|
#include <stdlib.h>
|
||
|
#include <assert.h>
|
||
|
|
||
|
struct stack;
|
||
|
|
||
|
enum node_tag {
|
||
|
NODE_APP,
|
||
|
NODE_NUM,
|
||
|
NODE_GLOBAL,
|
||
|
NODE_IND,
|
||
|
NODE_PACK
|
||
|
};
|
||
|
|
||
|
struct node_base {
|
||
|
enum node_tag tag;
|
||
|
};
|
||
|
|
||
|
struct node_app {
|
||
|
struct node_base base;
|
||
|
struct node_base* left;
|
||
|
struct node_base* right;
|
||
|
};
|
||
|
|
||
|
struct node_num {
|
||
|
struct node_base base;
|
||
|
int32_t value;
|
||
|
};
|
||
|
|
||
|
struct node_global {
|
||
|
struct node_base base;
|
||
|
void (*function)(struct stack*);
|
||
|
};
|
||
|
|
||
|
struct node_ind {
|
||
|
struct node_base base;
|
||
|
struct node_base* next;
|
||
|
};
|
||
|
|
||
|
struct node_data {
|
||
|
struct node_base base;
|
||
|
int8_t tag;
|
||
|
struct node_base** array;
|
||
|
};
|
||
|
|
||
|
struct node_base* alloc_node() {
|
||
|
node_base* new_node = malloc(sizeof(struct node_app));
|
||
|
assert(new_node != NULL);
|
||
|
return new_node;
|
||
|
}
|