Skip to content

Commit a1fcb7d

Browse files
authored
Update value.h
1 parent 8ec50c7 commit a1fcb7d

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

value.h

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,16 @@ typedef enum {
1616
} ValueType;
1717
#endif
1818

19+
typedef struct Object Object;
1920
typedef struct Value Value;
2021

21-
typedef struct Object {
22-
struct Object* next;
22+
struct Object {
23+
Object* next;
2324
bool marked;
2425
Value value;
25-
} Object;
26+
};
2627

27-
#ifndef VALUE_DEFINED
28-
#define VALUE_DEFINED
29-
typedef struct {
28+
struct Value {
3029
ValueType type;
3130
union {
3231
bool bool_val;
@@ -35,30 +34,29 @@ typedef struct {
3534
const char* str_val;
3635
Object* obj;
3736
} data;
38-
} Value;
39-
#endif
37+
};
4038

4139
#define NIL_VAL ((Value){ TYPE_NIL, { .int_val = 0 } })
42-
#define BOOL_VAL(v) ((Value){ TYPE_BOOL, { .bool_val = v } })
43-
#define INT_VAL(v) ((Value){ TYPE_INT, { .int_val = v } })
44-
#define NUMBER_VAL(v) ((Value){ TYPE_FLOAT, { .float_val = v } })
45-
#define STRING_VAL(s) ((Value){ TYPE_STRING, { .str_val = s } })
40+
#define BOOL_VAL(v) ((Value){ TYPE_BOOL, { .bool_val = (v) } })
41+
#define INT_VAL(v) ((Value){ TYPE_INT, { .int_val = (v) } })
42+
#define NUMBER_VAL(v) ((Value){ TYPE_FLOAT, { .float_val = (v) } })
43+
#define STRING_VAL(s) ((Value){ TYPE_STRING, { .str_val = (s) } })
4644

4745
#define IS_BOOL(v) ((v).type == TYPE_BOOL)
4846
#define IS_NIL(v) ((v).type == TYPE_NIL)
4947
#define IS_INT(v) ((v).type == TYPE_INT)
5048
#define IS_FLOAT(v) ((v).type == TYPE_FLOAT)
5149
#define IS_STRING(v) ((v).type == TYPE_STRING)
5250
#define IS_NUMBER(v) (IS_INT(v) || IS_FLOAT(v))
53-
#define IS_OBJ(v) ((v).type == TYPE_OBJ)
51+
#define IS_OBJ(v) ((v).type == TYPE_OBJ)
5452

5553
#define AS_BOOL(v) ((v).data.bool_val)
5654
#define AS_INT(v) ((v).data.int_val)
5755
#define AS_FLOAT(v) ((v).data.float_val)
5856
#define AS_STRING(v) ((v).data.str_val)
5957
#define AS_OBJ(v) ((v).data.obj)
6058

61-
void print_value(Value value);
59+
void print_value(Value* value);
6260
void* reallocate(void* pointer, size_t oldSize, size_t newSize);
6361

6462
#endif

0 commit comments

Comments
 (0)