-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobject.h
More file actions
44 lines (30 loc) · 751 Bytes
/
object.h
File metadata and controls
44 lines (30 loc) · 751 Bytes
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
#ifndef clox_object_h
#define clox_object_h
#include "common.h"
#include "value.h"
#define OBJ_TYPE(value) (AS_OBJ(value)->type)
#define AS_STRING(value) ((ObjString*)AS_OBJ(value))
#define AS_CSTRING(value) (((ObjString*)AS_OBJ(value))->chars)
#define IS_STRING(value) isObjType(value, OBJ_STRING)
typedef enum {
OBJ_STRING,
} ObjType;
struct Obj
{
ObjType type;
struct Obj* next;
};
struct ObjString
{
Obj obj;
char* chars;
int length;
uint32_t hash;
};
static inline bool isObjType(Value value, ObjType type) {
return IS_OBJ(value) && AS_OBJ(value)->type == type;
}
ObjString* takeString(char* chars, int length);
ObjString* copyString(const char* chars, int length);
void printObj(Value value);
#endif