.
This commit is contained in:
2
.idea/tyche.iml
generated
Normal file
2
.idea/tyche.iml
generated
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module classpath="External" external.linked.project.id="tyche" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="Makefile" type="CPP_MODULE" version="4" />
|
||||||
@@ -67,7 +67,7 @@ TYC_RESULT code_load_bytecode(Code* code, uint8_t const* bytecode, size_t byteco
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
uint32_t n_consts = code_n_consts(code);
|
uint32_t n_consts = code_n_consts(code);
|
||||||
code->const_addr = calloc(n_consts, sizeof(uint32_t));
|
code->const_addr = xcalloc(n_consts, sizeof(uint32_t));
|
||||||
uint32_t addr = CONST_START;
|
uint32_t addr = CONST_START;
|
||||||
for (size_t i = 0; i < n_consts; ++i) {
|
for (size_t i = 0; i < n_consts; ++i) {
|
||||||
code->const_addr[i] = addr;
|
code->const_addr[i] = addr;
|
||||||
@@ -90,7 +90,7 @@ TYC_RESULT code_load_bytecode(Code* code, uint8_t const* bytecode, size_t byteco
|
|||||||
memcpy(&code->fn_count, &bytecode[addr], sizeof(uint32_t)); // number of functions
|
memcpy(&code->fn_count, &bytecode[addr], sizeof(uint32_t)); // number of functions
|
||||||
addr += 4;
|
addr += 4;
|
||||||
|
|
||||||
code->fn_addr = calloc(code->fn_count, sizeof(uint32_t));
|
code->fn_addr = xcalloc(code->fn_count, sizeof(uint32_t));
|
||||||
code->fn_addr[0] = addr;
|
code->fn_addr[0] = addr;
|
||||||
for (size_t i = 1; i < code->fn_count; ++i) {
|
for (size_t i = 1; i < code->fn_count; ++i) {
|
||||||
uint32_t addr_next;
|
uint32_t addr_next;
|
||||||
|
|||||||
3
lib/vm.c
3
lib/vm.c
@@ -105,7 +105,7 @@ static TYC_RESULT enter_function(TycheVM* T, uint16_t n_pars)
|
|||||||
TYC_RESULT r;
|
TYC_RESULT r;
|
||||||
|
|
||||||
// get parameters
|
// get parameters
|
||||||
VALUE params[n_pars + 1];
|
VALUE* params = xcalloc(n_pars + 1, sizeof(VALUE));
|
||||||
for (uint16_t i = 0; i < n_pars; ++i)
|
for (uint16_t i = 0; i < n_pars; ++i)
|
||||||
TRY(stack_pop(T->stack, ¶ms[i]))
|
TRY(stack_pop(T->stack, ¶ms[i]))
|
||||||
|
|
||||||
@@ -123,6 +123,7 @@ static TYC_RESULT enter_function(TycheVM* T, uint16_t n_pars)
|
|||||||
for (int i = n_pars-1; i >= 0; --i)
|
for (int i = n_pars-1; i >= 0; --i)
|
||||||
TRY(stack_push(T->stack, params[i]))
|
TRY(stack_push(T->stack, params[i]))
|
||||||
|
|
||||||
|
free(params);
|
||||||
return T_OK;
|
return T_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user