-
Notifications
You must be signed in to change notification settings - Fork 0
/
object.h
63 lines (46 loc) · 1.11 KB
/
object.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
/*
* Contains code for creating and managing objects
* Heap management and the sweep portion of the garbage collecter are here
*/
#pragma once
#include <stdbool.h>
// GENERIC Derplang value
typedef enum {
TYPE_OBJECT,
TYPE_ARRAY,
TYPE_FN_REF,
TYPE_INTEGER,
TYPE_FLOAT,
TYPE_STRING,
TYPE_BOOLEAN
} Derp_data_type;
// forward declaration placeholders
struct derp_obj;
typedef struct derp_obj {
Derp_data_type type;
bool marked; // good ol' mark and sweep
unsigned char flags; // first slot: frozen
union {
// unimplemented, will be used as pointer to class object
void* klass;
struct {
struct derp_obj** vec;
int len;
} arr_val;
struct FnBytecode* fn_ref_val;
// 'native' or 'primitive' types
int int_val;
double float_val;
char* str_val;
bool bool_val;
};
} Derp_obj;
#include "vm.h"
#define OBJ_IS_NATIVE(obj) (obj->type != TYPE_OBJECT)
#define FLAG_FROZEN (1 << 0)
#define OBJ_IS_FROZEN(obj) (obj->flags & FLAG_FROZEN)
void object_init(Derp_obj* object);
Derp_obj* object_create();
void object_sweep();
void derp_obj_freeze(Derp_obj *obj);
void object_destroy(Derp_obj *obj);