-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache.h
67 lines (48 loc) · 1.76 KB
/
cache.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef CACHE_H
#define CACHE_H
#include "cons.h"
#include "symtable.h"
#include <stdint.h>
#define CCACHE_BLOCK_BYTES (32 * sizeof(cons))
#define CCACHE_BLOCK_INDEX(__block, __c) ((__c - __block) / sizeof(cons))
#define VCACHE_BLOCK_BYTES (32 * sizeof(value))
#define VCACHE_BLOCK_INDEX(__block, __v) ((__v - __block) / sizeof(value))
#define SYMCACHE_BLOCK_BYTES (32 * sizeof(symbol))
#define SYMCACHE_BLOCK_INDEX(__block, __s) ((__s - __block) / sizeof(symbol))
typedef struct ccache_block {
uint32_t mask;
uint32_t mark;
cons block[32];
struct ccache_block *next;
} ccache_block;
typedef struct vcache_block {
uint32_t mask;
uint32_t mark;
value block[32];
struct vcache_block *next;
} vcache_block;
typedef struct symcache_block {
uint32_t mask;
uint32_t mark;
symbol block[32];
struct symcache_block *next;
} symcache_block;
#define CCACHE_BLOCK(__next) &(ccache_block){ .mask = 0, .mark = 0, .block = { [0 ... 31] = {.car = WORD(0), .cdr = WORD(0)}}, .next = __next }
#define CCACHE_BLOCK_END (ccache_block *)0
#define VCACHE_BLOCK(__next) &(vcache_block){ .mask = 0, .mark = 0, .block = { [0 ... 31] = {.type = t_nil}}, .next = __next }
#define VCACHE_BLOCK_END (vcache_block *)0
#define SYMCACHE_BLOCK(__next) &(symcache_block){ .mask = 0, .mark = 0, .block = { [0 ... 31] = {.name = (char *)0, .lifetime = t_static, .v = (value *)0, .next = (symbol *)0 }}, .next = __next }
#define SYMCACHE_BLOCK_END (symcache_block *)0
cons *cons_alloc();
void cons_free(cons *c);
void cons_free_rec(cons *c);
value *value_alloc();
void value_free(value *v);
void value_free_rec(value *v);
symbol *symbol_alloc();
void symbol_free(symbol *s);
void symbol_free_rec(symbol *s);
void mark_reset();
void mark(symbol *table);
void sweep();
#endif