summaryrefslogtreecommitdiffhomepage
path: root/program.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2022-01-07 20:03:17 +0100
committerJo-Philipp Wich <jo@mein.io>2022-01-18 10:58:11 +0100
commit725bb75b7b66dd1e0a381908e831cede0402cb6e (patch)
treeb8ee8c737198e5b5bad6b809457c59be2a7f8bb5 /program.c
parent6b2e79af9fe6e7d05d31245fc9049540a96d5d31 (diff)
compiler, vm: use a program wide constant list
Instead of storing constant values per function, maintain a global program wide list for all constant values within the current compilation unit. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'program.c')
-rw-r--r--program.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/program.c b/program.c
index c413f38..5d3a104 100644
--- a/program.c
+++ b/program.c
@@ -15,6 +15,7 @@
*/
#include "ucode/program.h"
+#include "ucode/vallist.h"
uc_program_t *
@@ -27,6 +28,8 @@ uc_program_new(void)
prog->functions.next = &prog->functions;
prog->functions.prev = &prog->functions;
+ uc_vallist_init(&prog->constants);
+
return prog;
}
@@ -60,6 +63,7 @@ uc_program_free(uc_program_t *prog)
ucv_put(&func->header);
}
+ uc_vallist_free(&prog->constants);
free(prog);
}
@@ -101,3 +105,15 @@ uc_program_function_load(uc_program_t *prog, size_t id)
return NULL;
}
+
+uc_value_t *
+uc_program_get_constant(uc_program_t *prog, size_t idx)
+{
+ return uc_vallist_get(&prog->constants, idx);
+}
+
+ssize_t
+uc_program_add_constant(uc_program_t *prog, uc_value_t *val)
+{
+ return uc_vallist_add(&prog->constants, val);
+}