diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-01-13 16:06:17 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-01-18 10:58:11 +0100 |
commit | 6c2caf9fbb9d346cfb20cd5c83875fdff77e584c (patch) | |
tree | 4d0fe816584e8f351ed0f1da8be0b9ccf1c5635f /program.c | |
parent | 725bb75b7b66dd1e0a381908e831cede0402cb6e (diff) |
source: refactor source file handling
- Move source object pointer into program entity which is referenced by
each function
- Move lineinfo related routines into source.c and use them from lexer.c
since lineinfo encoding does not belong into the lexical analyzer.
- Implement initial infrastructure for detecting source file type,
this is required later to differentiate between plaintext and
precompiled bytecode files
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'program.c')
-rw-r--r-- | program.c | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -15,11 +15,12 @@ */ #include "ucode/program.h" +#include "ucode/source.h" #include "ucode/vallist.h" uc_program_t * -uc_program_new(void) +uc_program_new(uc_source_t *source) { uc_program_t *prog; @@ -28,6 +29,8 @@ uc_program_new(void) prog->functions.next = &prog->functions; prog->functions.prev = &prog->functions; + prog->source = uc_source_get(source); + uc_vallist_init(&prog->constants); return prog; @@ -64,15 +67,16 @@ uc_program_free(uc_program_t *prog) } uc_vallist_free(&prog->constants); + uc_source_put(prog->source); free(prog); } uc_value_t * -uc_program_function_new(uc_program_t *prog, const char *name, size_t srcpos, uc_source_t *source) +uc_program_function_new(uc_program_t *prog, const char *name, size_t srcpos) { uc_function_t *func; - func = (uc_function_t *)ucv_function_new(name, srcpos, source, prog); + func = (uc_function_t *)ucv_function_new(name, srcpos, prog); func->root = (prog->functions.next == &prog->functions); ucv_ref(&prog->functions, &func->progref); |