fix double free

This commit is contained in:
William Bell
2025-08-27 16:16:32 +01:00
parent db650d8ccf
commit c322d5680f
3 changed files with 25 additions and 14 deletions

View File

@@ -0,0 +1,3 @@
term.log(((x)=do
return x*x
)(3545436543634634))

View File

@@ -14,17 +14,15 @@
size_t translate_parsed_function(Translated *translated, size_t translate_parsed_function(Translated *translated,
ParsedFunction *parsedFunction, ArErr *err) { ParsedFunction *parsedFunction, ArErr *err) {
DArray main_bytecode = translated->bytecode; DArray main_bytecode = translated->bytecode;
DArray _temp_bytecode; darray_init(&translated->bytecode, sizeof(uint8_t));
darray_init(&_temp_bytecode, sizeof(uint8_t));
set_registers(translated, 1); set_registers(translated, 1);
translated->bytecode = _temp_bytecode;
translate_parsed(translated, parsedFunction->body, err); translate_parsed(translated, parsedFunction->body, err);
size_t function_bytecode_offset = size_t function_bytecode_offset =
arena_push(&translated->constants, translated->bytecode.data, arena_push(&translated->constants, translated->bytecode.data,
translated->bytecode.size*translated->bytecode.element_size); translated->bytecode.size*translated->bytecode.element_size);
size_t function_bytecode_length = translated->bytecode.size; size_t function_bytecode_length = translated->bytecode.size;
darray_free(&translated->bytecode, NULL);
translated->bytecode = main_bytecode; translated->bytecode = main_bytecode;
darray_free(&_temp_bytecode, NULL);
size_t start = push_instruction_byte(translated, OP_LOAD_FUNCTION); size_t start = push_instruction_byte(translated, OP_LOAD_FUNCTION);
size_t offset = arena_push(&translated->constants, parsedFunction->name, size_t offset = arena_push(&translated->constants, parsedFunction->name,
strlen(parsedFunction->name)); strlen(parsedFunction->name));

View File

@@ -22,16 +22,26 @@ let call(f) = do
term.log( term.log(
call( call(
()=call( ()=call(
()=call( ()=do
()=call( term.log('hello testing testing')
()=do return call(
()=call(
()=do
term.log("hello this is a test of anonymous functions. hopefully this works :)") term.log("hello this is a test of anonymous functions. hopefully this works :)")
return say_hi("test") return say_hi("test")
)
)
)
)
) )
) call(()=do
) term.log((
) (x)=x*x*x*x*x*x*x*x*x*x*x*x
)(
10000675435574942378423458324823473205237523053278452368578032472390453275238558438905348905894035890348905349805345485843578934268954328902589607469328905490832678934728969834689057843267854736890256743928563256749016078596789416895657435690769013674516750941765438576867893726789543789345678576846715416789058903890549045839804538905389045890435890349580348905894035890435784785236523656237985678342523678
)
)
) )