diff options
| author | iamcheeseman <[email protected]> | 2026-04-07 10:46:07 -0400 |
|---|---|---|
| committer | iamcheeseman <[email protected]> | 2026-04-07 10:46:07 -0400 |
| commit | 6d30c64216cd4d0b1b2a20a167d85c7fc6534378 (patch) | |
| tree | 67d0600f9be759c2c76b3e017b286354b57ab00a /uscript/val.h | |
| parent | d39f7a08461b64c7378f007761d51208c226f4a4 (diff) | |
microscript: add arrays
Diffstat (limited to 'uscript/val.h')
| -rw-r--r-- | uscript/val.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/uscript/val.h b/uscript/val.h index 1c314e4..4a30880 100644 --- a/uscript/val.h +++ b/uscript/val.h @@ -7,6 +7,7 @@ #define get_bool(v) (v.dat.boolean) #define get_obj(v) (v.dat.obj) #define get_str(v) (v.dat.str) +#define get_arr(v) (v.dat.arr) #define get_proto(v) (v.dat.proto) #define get_func(v) (v.dat.func) #define get_upval(v) (v.dat.upval) @@ -15,6 +16,7 @@ #define create_bool(b) ((struct us_val){.type=VAL_BOOL, .dat={.boolean=(b)}}) #define create_zilch() ((struct us_val){.type=VAL_ZILCH, .dat={.number=0}}) #define wrap_str(o) ((struct us_val){.type=VAL_STR, .dat={.str=(o)}}) +#define wrap_arr(o) ((struct us_val){.type=VAL_ARR, .dat={.arr=(o)}}) #define wrap_proto(o) ((struct us_val){.type=VAL_PROTO, .dat={.proto=(o)}}) #define wrap_func(o) ((struct us_val){.type=VAL_FUNC, .dat={.func=(o)}}) #define wrap_upval(o) ((struct us_val){.type=VAL_UPVAL, .dat={.upval=(o)}}) @@ -30,6 +32,7 @@ enum val_type { // Do not place any new object types before VAL_STR. Object types are // detected by doing a comparison with VAL_STR. See val_is_obj(). VAL_STR, + VAL_ARR, VAL_PROTO, VAL_FUNC, VAL_UPVAL, @@ -42,6 +45,7 @@ struct us_val { bool boolean; struct us_obj *obj; struct us_str *str; + struct us_arr *arr; struct us_proto *proto; struct us_func *func; struct us_upval *upval; @@ -60,6 +64,11 @@ struct us_str { size_t len; }; +struct us_arr { + struct us_obj header; + struct us_val *e; // dyn_arr +}; + struct us_proto { struct us_obj header; const struct us_str *name; @@ -87,6 +96,7 @@ struct us_upval { struct us_str *take_str(char *chars, int len); struct us_str *copy_str(const char *chars, int len); +struct us_arr *create_arr(void); struct us_proto *create_proto(struct us_str *name); struct us_func *create_func(struct us_proto *proto); struct us_upval *create_upval(struct us_val *val); |
