-
Notifications
You must be signed in to change notification settings - Fork 6
/
object.h
52 lines (42 loc) · 1.44 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
#ifndef OBJECT_H
#define OBJECT_H
#include "dict.h"
typedef struct object object_t;
typedef struct value value_t;
typedef struct func func_t;
typedef value_t (*native_func_t)(value_t parent_scope, value_t arg);
enum object_type {
object_type_dict,
object_type_list,
object_type_string,
object_type_func,
};
struct func {
struct compiled_func *compiled; // null if native
native_func_t native; // null if not native
// If the function is compiled, the parent_scope must be a dict
// with an optional `<parent>` property.
// If the function is native, it is user-defined and can be anything.
value_t parent_scope;
};
struct object {
enum object_type type;
object_t *prev, *next; // Garbage collection junk
int marked, ref_count; // More garbage collection junk
union {
dict_t dict; // This is also used for lists. No, I’m not kidding.
char *string;
func_t func;
};
};
void free_object_unsafe(object_t *o);
object_t *new_string_object(const char *cs);
object_t *new_dict_object(void);
object_t *new_list_object(void);
object_t *new_native_func_object(native_func_t func);
object_t *new_compiled_func_object(struct compiled_func *compiled);
// These global variables are used by the garbage collector.
extern object_t *big_linked_list; // Contains every allocated object.
extern unsigned long object_count;
extern unsigned long allocation_count_since_last_gc;
#endif /* OBJECT_H */