This commit is contained in:
cozis
2022-04-19 00:34:34 +02:00
parent a91b0308f9
commit 0d2fe6ac01
6 changed files with 275 additions and 129 deletions
+21 -17
View File
@@ -2,8 +2,8 @@ typedef double xj_f64;
typedef long long xj_i64;
typedef _Bool xj_bool;
_Static_assert(sizeof(xj_f64) == 8);
_Static_assert(sizeof(xj_i64) == 8);
_Static_assert(sizeof(xj_f64) == 8, "double isn't 8 bytes long");
_Static_assert(sizeof(xj_i64) == 8, "long long isn't 8 bytes long");
enum {
XJ_NULL,
@@ -34,23 +34,27 @@ struct xj_value {
typedef struct {
xj_bool occurred;
xj_bool truncated;
int off, row, col;
char message[128];
} xj_error;
typedef struct xj_alloc xj_alloc;
xj_alloc *xj_newAlloc(int size, int ext);
xj_alloc *xj_newAllocUsing(void *mem, int size, int ext, void (*free)(void*));
void xj_freeAlloc(xj_alloc *alloc);
void *xj_bpMalloc(xj_alloc *alloc, unsigned int size);
xj_value *xj_newNull(xj_alloc *alloc);
xj_value *xj_newBool(xj_bool val, xj_alloc *alloc);
xj_value *xj_newInt(xj_i64 val, xj_alloc *alloc);
xj_value *xj_newFloat(xj_f64 val, xj_alloc *alloc);
xj_value *xj_newArray(xj_value *head, xj_alloc *alloc);
xj_value *xj_newArray__nocheck(xj_value *head, int count, xj_alloc *alloc);
xj_value *xj_newObject(xj_value *head, xj_alloc *alloc);
xj_value *xj_newObject__nocheck(xj_value *head, int count, xj_alloc *alloc);
xj_value *xj_newString(const char *str, int len, xj_alloc *alloc);
char *xj_strdup(const char *str, int len, xj_alloc *alloc);
xj_alloc *xj_alloc_using(void *mem, int size, int ext, void (*free)(void*));
xj_alloc *xj_alloc_new(int size, int ext);
void xj_alloc_del(xj_alloc *alloc);
void *xj_bpalloc(xj_alloc *alloc, int size);
xj_value *xj_value_null(xj_alloc *alloc, xj_error *error);
xj_value *xj_value_bool(xj_bool val, xj_alloc *alloc, xj_error *error);
xj_value *xj_value_int(xj_i64 val, xj_alloc *alloc, xj_error *error);
xj_value *xj_value_float(xj_f64 val, xj_alloc *alloc, xj_error *error);
xj_value *xj_value_array(xj_value *head, xj_alloc *alloc, xj_error *error);
xj_value *xj_value_object(xj_value *head, xj_alloc *alloc, xj_error *error);
xj_value *xj_value_string(const char *str, int len, xj_alloc *alloc, xj_error *error);
xj_value *xj_value_array__nocheck(xj_value *head, int count, xj_alloc *alloc, xj_error *error);
xj_value *xj_value_object__nocheck(xj_value *head, int count, xj_alloc *alloc, xj_error *error);
char *xj_strdup(const char *str, int len, xj_alloc *alloc, xj_error *error);
xj_value *xj_decode(const char *str, int len, xj_alloc *alloc, xj_error *error);
char *xj_encode(xj_value *value, int *len);
char *xj_encode(xj_value *value, int *len);