61 lines
733 B
C
61 lines
733 B
C
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
// common types
|
|
typedef uintptr_t U;
|
|
typedef intptr_t I;
|
|
|
|
typedef uint8_t U8;
|
|
typedef uint32_t U32;
|
|
typedef int32_t I32;
|
|
typedef size_t Z;
|
|
|
|
// objects
|
|
typedef uintptr_t O;
|
|
|
|
// cons pair
|
|
typedef struct C C;
|
|
struct C {
|
|
O head, tail;
|
|
};
|
|
|
|
// symbol
|
|
typedef struct S S;
|
|
struct S {
|
|
U8 *data;
|
|
U32 hash;
|
|
Z len;
|
|
};
|
|
|
|
// symbol table
|
|
typedef struct St St;
|
|
struct St {
|
|
I count;
|
|
Z capacity;
|
|
S **data;
|
|
};
|
|
|
|
// gc header
|
|
typedef struct H H;
|
|
struct H {
|
|
I type;
|
|
Z len;
|
|
};
|
|
|
|
// heap
|
|
typedef struct E E;
|
|
struct E {
|
|
struct {
|
|
U8 *start, *end;
|
|
U8 *free;
|
|
} from, to;
|
|
|
|
I root_count;
|
|
Z root_capacity;
|
|
O **roots;
|
|
};
|
|
|
|
extern E heap;
|
|
extern St syms;
|
|
|
|
S *intern(const char *str, I len);
|