summaryrefslogtreecommitdiffhomepage
path: root/ast.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2020-09-02 21:51:48 +0200
committerJo-Philipp Wich <jo@mein.io>2020-09-02 21:51:48 +0200
commite810a0e763d363a6a8991bd6610608c024d9e787 (patch)
tree695abc00ae9c9439897b1f30954349dac5551e28 /ast.c
parentff2fde1752a1acd5fb6d784e8d462de4598e1810 (diff)
ast, eval: add tagged object handling
In order to implement prototype chains later on, introduce a tagged object value type and use it when processing object declarations. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'ast.c')
-rw-r--r--ast.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/ast.c b/ast.c
index 5d42b56..bba1316 100644
--- a/ast.c
+++ b/ast.c
@@ -132,6 +132,40 @@ json_object_new_null_obj(void) {
return d;
}
+static void
+obj_free(struct json_object *v, void *ud)
+{
+ struct ut_tagvalue *tag = json_object_get_userdata(v);
+
+ json_object_put(tag->proto);
+ free(ud);
+}
+
+struct json_object *
+ut_new_object(struct ut_state *s, struct json_object *proto) {
+ struct json_object *val = json_object_new_object();
+ struct ut_tagvalue *tag;
+
+ if (!val)
+ return NULL;
+
+ tag = calloc(1, sizeof(*tag));
+
+ if (!tag) {
+ json_object_put(val);
+
+ return NULL;
+ }
+
+ tag->val = val;
+ tag->type = T_LBRACE;
+ tag->proto = json_object_get(proto);
+
+ json_object_set_serializer(val, NULL, tag, obj_free);
+
+ return tag->val;
+}
+
static int
func_to_string(struct json_object *v, struct printbuf *pb, int level, int flags)
{