From 6eed0aa02c657ae97e18280a6dd9d74c84fd91d4 Mon Sep 17 00:00:00 2001 From: Bad Diode Date: Tue, 26 Oct 2021 17:17:04 +0200 Subject: Fix symbol evaluation --- src/bytecode/compiler.h | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/src/bytecode/compiler.h b/src/bytecode/compiler.h index 995a5c1..6a17beb 100755 --- a/src/bytecode/compiler.h +++ b/src/bytecode/compiler.h @@ -117,12 +117,6 @@ compile_list_binary_op(Chunk *chunk, Compiler *compiler, Token start, Ops op) { break; } parse_tree(chunk, compiler); - if (tok.type == TOKEN_SYMBOL) { - ssize_t idx = find_local_index(chunk, tok); - if (idx < 0) { - add_code(chunk, OP_GET, tok.line, tok.column); - } - } n++; } emit_constant(chunk, start, FIXNUM_VAL(n)); @@ -156,12 +150,6 @@ compile_list_unary_op(Chunk *chunk, Compiler *compiler, Token start, Ops op) { return; } parse_tree(chunk, compiler); - if (tok.type == TOKEN_SYMBOL) { - ssize_t idx = find_local_index(chunk, tok); - if (idx < 0) { - add_code(chunk, OP_GET, tok.line, tok.column); - } - } add_code(chunk, op, start.line, start.column); n++; if (n > 1) { @@ -227,7 +215,10 @@ compile_declare_op(Chunk *chunk, Compiler *compiler, Token start, Ops op) { }); return; } - parse_tree(chunk, compiler); + Object obj = make_symbol(name.value); + emit_constant(chunk, name, obj); + next_token(compiler); + Token tok = peek_token(compiler); if (name.type == TOKEN_EOF || tok.type == TOKEN_EOF) { error_push((Error){ @@ -248,12 +239,6 @@ compile_declare_op(Chunk *chunk, Compiler *compiler, Token start, Ops op) { return; } parse_tree(chunk, compiler); - if (tok.type == TOKEN_SYMBOL) { - ssize_t idx = find_local_index(chunk, tok); - if (idx < 0) { - add_code(chunk, OP_GET, tok.line, tok.column); - } - } if (peek_token(compiler).type != TOKEN_RPAREN) { error_push((Error){ .type = ERR_TYPE_COMPILER, @@ -343,7 +328,10 @@ compile_fun_op(Chunk *chunk, Compiler *compiler, Token start) { }); return; } - parse_tree(chunk, compiler); + Object obj = make_symbol(name.value); + emit_constant(chunk, name, obj); + next_token(compiler); + compile_lambda(chunk, compiler, start, name.value); add_code(chunk, OP_DEF, start.line, start.column); } @@ -533,6 +521,7 @@ parse_tree(Chunk *chunk, Compiler *compiler) { if (idx < 0) { Object obj = make_symbol(tok.value); emit_constant(chunk, tok, obj); + add_code(chunk, OP_GET, tok.line, tok.column); return; } -- cgit v1.2.1