diff --git a/anonymous-function-test.ar b/anonymous-function-test.ar new file mode 100644 index 0000000..f75fd48 --- /dev/null +++ b/anonymous-function-test.ar @@ -0,0 +1,3 @@ +term.log(((x)=do + return x*x +)(3545436543634634)) \ No newline at end of file diff --git a/src/translator/function/function.c b/src/translator/function/function.c index 21fad94..6e0c5d7 100644 --- a/src/translator/function/function.c +++ b/src/translator/function/function.c @@ -14,17 +14,15 @@ size_t translate_parsed_function(Translated *translated, ParsedFunction *parsedFunction, ArErr *err) { DArray main_bytecode = translated->bytecode; - DArray _temp_bytecode; - darray_init(&_temp_bytecode, sizeof(uint8_t)); + darray_init(&translated->bytecode, sizeof(uint8_t)); set_registers(translated, 1); - translated->bytecode = _temp_bytecode; translate_parsed(translated, parsedFunction->body, err); size_t function_bytecode_offset = arena_push(&translated->constants, translated->bytecode.data, translated->bytecode.size*translated->bytecode.element_size); size_t function_bytecode_length = translated->bytecode.size; + darray_free(&translated->bytecode, NULL); translated->bytecode = main_bytecode; - darray_free(&_temp_bytecode, NULL); size_t start = push_instruction_byte(translated, OP_LOAD_FUNCTION); size_t offset = arena_push(&translated->constants, parsedFunction->name, strlen(parsedFunction->name)); diff --git a/testing.ar b/testing.ar index 936e48a..0b54559 100644 --- a/testing.ar +++ b/testing.ar @@ -22,16 +22,26 @@ let call(f) = do term.log( -call( -()=call( -()=call( -()=call( -()=do - term.log("hello this is a test of anonymous functions. hopefully this works :)") + call( + ()=call( + ()=do + term.log('hello testing testing') + return call( + ()=call( + ()=do + 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 + ) + ) ) \ No newline at end of file