summaryrefslogtreecommitdiff
path: root/uscript/val.h
diff options
context:
space:
mode:
authoriamcheeseman <[email protected]>2026-04-17 22:48:52 -0400
committeriamcheeseman <[email protected]>2026-04-17 22:48:52 -0400
commitf328d3b2bea11f6b89bf4b3707205ecd8496b93d (patch)
tree6d3fdb155a7d4c19332f54790b1d6ae89ae0b04f /uscript/val.h
parentde5d3ebdbc674bf8f1e324ee5b43c51af288a286 (diff)
microscript: add maps
Diffstat (limited to 'uscript/val.h')
-rw-r--r--uscript/val.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/uscript/val.h b/uscript/val.h
index 5deb64c..3c579af 100644
--- a/uscript/val.h
+++ b/uscript/val.h
@@ -9,6 +9,7 @@
#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_map(o) ((struct us_val){.type=VAL_MAP, .dat={.map=(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_cfunc(o) ((struct us_val){.type=VAL_CFUNC, .dat={.cfunc=(o)}})
@@ -19,6 +20,7 @@
#define get_obj(v) (v.dat.obj)
#define get_str(v) (v.dat.str)
#define get_arr(v) (v.dat.arr)
+#define get_map(v) (v.dat.map)
#define get_proto(v) (v.dat.proto)
#define get_func(v) (v.dat.func)
#define get_cfunc(v) (v.dat.cfunc)
@@ -40,6 +42,7 @@ enum val_type {
// detected by doing a comparison with VAL_STR. See val_is_obj().
VAL_STR,
VAL_ARR,
+ VAL_MAP,
VAL_PROTO,
VAL_FUNC,
VAL_CFUNC,
@@ -54,6 +57,7 @@ struct us_val {
struct us_obj *obj;
struct us_str *str;
struct us_arr *arr;
+ struct us_map *map;
struct us_proto *proto;
struct us_func *func;
struct us_cfunc *cfunc;
@@ -78,6 +82,19 @@ struct us_arr {
struct us_val *e; // dyn_arr
};
+struct us_map_kv {
+ struct us_val key;
+ struct us_val val;
+};
+
+struct us_map {
+ struct us_obj header;
+ struct us_map_kv *e;
+ struct us_val locked;
+ int len;
+ int cap;
+};
+
struct us_proto {
struct us_obj header;
const struct us_str *name;
@@ -115,6 +132,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_map *create_map(void);
struct us_proto *create_proto(struct us_str *name);
struct us_func *create_func(struct us_proto *proto);
struct us_cfunc *create_cfunc(struct us_str *name, us_cfunc_sig func, int argc);
@@ -127,5 +145,6 @@ void proto_add_const(struct us_proto *func, struct us_val v);
bool vals_eql(struct us_val a, struct us_val b);
char *val_to_str(struct us_val v, int *len_out);
+bool val_as_bool(struct us_val v);
#endif // __USCRIPT_VAL_H__