summaryrefslogtreecommitdiff
path: root/src/memory.h
blob: f78003449eba5c9e6852d499398735670c29e6b3 (plain)
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
#ifndef __MEMORY_H
#define __MEMORY_H

#include <stdint.h>
#include "multiboot.h"

enum cell_type {
	FREE_CELL,
	CONS_CELL,
	INT_CELL,
	BIGINT_CELL,
	CHAR_CELL,
	FLOAT_CELL,
	VIRTUAL_CELL,
	SYMBOL_CELL,
	ARRAY_CELL,
	ARRAY_MEMBER,
	SYS_ARRAY,
	APIOFORM
};

struct cell {
	int car : 29;
	int cdr : 29;
	int type : 4;
	int gc_mark : 1;
} __attribute((packed));

uint32_t memory_available;

void init_memory(multiboot_info_t *mb);
struct cell *alloc_cell(enum cell_type t);
enum cell_type get_cell_type(const struct cell *c);
void set_cell_type(struct cell *c, enum cell_type t);

static inline uint32_t car(struct cell *c) {
	return c->car << 3;
}
static inline uint32_t cdr(struct cell *c) {
	return c->cdr << 3;
}
static inline struct cell *car_cell(struct cell *c) {
	return (struct cell *) car(c);
}
static inline struct cell *cdr_cell(struct cell *c) {
	return (struct cell *) cdr(c);
}
static inline void set_car(struct cell *c, uint32_t val) {
	c->car = val >> 3;
}
static inline void set_cdr(struct cell *c, uint32_t val) {
	c->cdr = val >> 3;
}

#endif