symbol interning

This commit is contained in:
Lobo 2026-01-06 12:27:53 -03:00
parent 5e6bc2679d
commit d64b0f0a6f
6 changed files with 174 additions and 10 deletions

61
wscm.h Normal file
View file

@ -0,0 +1,61 @@
#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);