From 60b3369ab24f9bd2a4a6d638ab1b3013ebc29814 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Thu, 20 Jun 2024 16:00:34 +0100 Subject: pass State *S everywhere contains changes from a million years ago that i don't remember much about --- val.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'val.h') diff --git a/val.h b/val.h index 3cf3251..d742c14 100644 --- a/val.h +++ b/val.h @@ -8,6 +8,7 @@ typedef struct _val Val; typedef struct _obj Obj; +typedef struct _state State; typedef enum { @@ -42,11 +43,15 @@ typedef struct { Obj obj; size_t len; uint32_t hash; - char *b; + char *d; } ObjString; -ObjString *objstring_copy(char *src, size_t len); -ObjString *objstring_take(char *src, size_t len); +// Constructs a new objstring from the given C string, +// creating its own fresh copy of the data. +ObjString *objstring_copy(State *S, char *src, size_t len); +// Constructs a new objstring from the given C string, +// taking ownership of the provided data. +ObjString *objstring_take(State *S, char *src, size_t len); #define IS_NIL(x) (x.ty == NIL) @@ -61,7 +66,7 @@ ObjString *objstring_take(char *src, size_t len); #define AS_OBJ(x) (x.as.o) #define AS_STRING(x) ((ObjString*)AS_OBJ(x)) -#define AS_CSTRING(x) (AS_STRING(x)->b) +#define AS_CSTRING(x) (AS_STRING(x)->d) #define VAL_NIL ((Val){.ty=TY_NIL}) #define VAL_NUM(x) ((Val){.ty=TY_NUM, .as.d=(x) }) -- cgit v1.2.3