bloglang/07/runtime.c

51 lines
796 B
C
Raw Normal View History

2019-10-26 20:30:29 -07:00
#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;
}