diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-01-07 20:03:17 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-01-18 10:58:11 +0100 |
commit | 725bb75b7b66dd1e0a381908e831cede0402cb6e (patch) | |
tree | b8ee8c737198e5b5bad6b809457c59be2a7f8bb5 /compiler.c | |
parent | 6b2e79af9fe6e7d05d31245fc9049540a96d5d31 (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 'compiler.c')
-rw-r--r-- | compiler.c | 14 |
1 files changed, 5 insertions, 9 deletions
@@ -483,8 +483,7 @@ uc_compiler_set_u32(uc_compiler_t *compiler, size_t off, uint32_t n) static size_t uc_compiler_emit_constant(uc_compiler_t *compiler, size_t srcpos, uc_value_t *val) { - uc_chunk_t *chunk = uc_compiler_current_chunk(compiler); - size_t cidx = uc_chunk_add_constant(chunk, val); + size_t cidx = uc_program_add_constant(compiler->program, val); uc_compiler_emit_insn(compiler, srcpos, I_LOAD); uc_compiler_emit_u32(compiler, 0, cidx); @@ -495,8 +494,7 @@ uc_compiler_emit_constant(uc_compiler_t *compiler, size_t srcpos, uc_value_t *va static size_t uc_compiler_emit_regexp(uc_compiler_t *compiler, size_t srcpos, uc_value_t *val) { - uc_chunk_t *chunk = uc_compiler_current_chunk(compiler); - size_t cidx = uc_chunk_add_constant(chunk, val); + size_t cidx = uc_program_add_constant(compiler->program, val); uc_compiler_emit_insn(compiler, srcpos, I_LREXP); uc_compiler_emit_u32(compiler, 0, cidx); @@ -1086,7 +1084,7 @@ uc_compiler_emit_variable_rw(uc_compiler_t *compiler, uc_value_t *varname, uc_to ((sub_insn & 0xff) << 24) | idx); } else { - idx = uc_chunk_add_constant(uc_compiler_current_chunk(compiler), varname); + idx = uc_program_add_constant(compiler->program, varname); insn = sub_insn ? I_UVAR : (type ? I_SVAR : I_LVAR); uc_compiler_emit_insn(compiler, compiler->parser->prev.pos, insn); @@ -1195,8 +1193,7 @@ uc_compiler_compile_arrowfn(uc_compiler_t *compiler, uc_value_t *args, bool rest if (fn) uc_compiler_set_u32(compiler, load_off, - uc_chunk_add_constant(uc_compiler_current_chunk(compiler), - &fn->header)); + uc_program_add_constant(compiler->program, &fn->header)); return true; } @@ -1635,8 +1632,7 @@ uc_compiler_compile_function(uc_compiler_t *compiler) if (fn) uc_compiler_set_u32(compiler, load_off, - uc_chunk_add_constant(uc_compiler_current_chunk(compiler), - &fn->header)); + uc_program_add_constant(compiler->program, &fn->header)); /* if a local variable of the same name already existed, overwrite its value * with the compiled function here */ |