Make progress on compiler posts

This commit is contained in:
2019-10-26 20:30:29 -07:00
parent 6dd52ac182
commit dbc09f7ff0
26 changed files with 1403 additions and 0 deletions

50
07/runtime.c Normal file
View File

@@ -0,0 +1,50 @@
#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;
}