From 0ff1716f45c9494b1aa02b8ddb2541821480c5ad Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Thu, 28 Oct 2021 13:34:18 +0200 Subject: Fix difference between lambda and named func calls --- src/bytecode/compiler.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'src/bytecode/compiler.h') diff --git a/src/bytecode/compiler.h b/src/bytecode/compiler.h index 867d194..5f38216 100755 --- a/src/bytecode/compiler.h +++ b/src/bytecode/compiler.h @@ -520,6 +520,10 @@ compile_fun_op(Chunk *chunk, Compiler *compiler, Token start) { void compile_call_op(Chunk *chunk, Compiler *compiler, Token start, Token name) { + if (name.type == TOKEN_SYMBOL) { + parse_symbol(chunk, compiler, name); + } + // Compile body. size_t n = 0; while (has_next_token(compiler)) { @@ -540,11 +544,6 @@ compile_call_op(Chunk *chunk, Compiler *compiler, Token start, Token name) { parse_tree(chunk, compiler); n++; } - if (name.type == TOKEN_SYMBOL) { - Object obj = make_symbol(name.value); - emit_constant(chunk, start, obj); - add_code(chunk, OP_GET, start.line, start.column); - } emit_constant(chunk, start, FIXNUM_VAL(n)); add_code(chunk, OP_CALL, start.line, start.column); } @@ -635,7 +634,10 @@ parse_list(Chunk *chunk, Compiler *compiler, Token start) { case TOKEN_GREATER_EQUAL: { compile_list_binary_op(chunk, compiler, start, OP_GREATER_EQUAL); } break; case TOKEN_PRINT: { compile_list_unary_op(chunk, compiler, start, OP_PRINT); } break; case TOKEN_DISPLAY: { compile_list_unary_op(chunk, compiler, start, OP_DISPLAY); } break; - case TOKEN_NEWLINE: { compile_list_simple_op(chunk, compiler, start, OP_NEWLINE); } break; + case TOKEN_NEWLINE: { + compile_list_simple_op(chunk, compiler, start, OP_NEWLINE); + emit_constant(chunk, start, NIL_VAL); + } break; case TOKEN_DEF: { compile_declare_op(chunk, compiler, start, OP_DEF); } break; case TOKEN_SET: { compile_declare_op(chunk, compiler, start, OP_SET); } break; case TOKEN_FUN: { compile_fun_op(chunk, compiler, start); } break; -- cgit v1.2.1