aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBad Diode <bd@badd10de.dev>2021-10-26 17:17:04 +0200
committerBad Diode <bd@badd10de.dev>2021-10-26 17:17:04 +0200
commit6eed0aa02c657ae97e18280a6dd9d74c84fd91d4 (patch)
treece399222b8b173829df65ebf22b8f5503953aa1c
parent26c5b458a067388da968465ba9e102a084bf7a2c (diff)
downloadbdl-6eed0aa02c657ae97e18280a6dd9d74c84fd91d4.tar.gz
bdl-6eed0aa02c657ae97e18280a6dd9d74c84fd91d4.zip
Fix symbol evaluation
-rwxr-xr-xsrc/bytecode/compiler.h29
1 files 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) {
117 break; 117 break;
118 } 118 }
119 parse_tree(chunk, compiler); 119 parse_tree(chunk, compiler);
120 if (tok.type == TOKEN_SYMBOL) {
121 ssize_t idx = find_local_index(chunk, tok);
122 if (idx < 0) {
123 add_code(chunk, OP_GET, tok.line, tok.column);
124 }
125 }
126 n++; 120 n++;
127 } 121 }
128 emit_constant(chunk, start, FIXNUM_VAL(n)); 122 emit_constant(chunk, start, FIXNUM_VAL(n));
@@ -156,12 +150,6 @@ compile_list_unary_op(Chunk *chunk, Compiler *compiler, Token start, Ops op) {
156 return; 150 return;
157 } 151 }
158 parse_tree(chunk, compiler); 152 parse_tree(chunk, compiler);
159 if (tok.type == TOKEN_SYMBOL) {
160 ssize_t idx = find_local_index(chunk, tok);
161 if (idx < 0) {
162 add_code(chunk, OP_GET, tok.line, tok.column);
163 }
164 }
165 add_code(chunk, op, start.line, start.column); 153 add_code(chunk, op, start.line, start.column);
166 n++; 154 n++;
167 if (n > 1) { 155 if (n > 1) {
@@ -227,7 +215,10 @@ compile_declare_op(Chunk *chunk, Compiler *compiler, Token start, Ops op) {
227 }); 215 });
228 return; 216 return;
229 } 217 }
230 parse_tree(chunk, compiler); 218 Object obj = make_symbol(name.value);
219 emit_constant(chunk, name, obj);
220 next_token(compiler);
221
231 Token tok = peek_token(compiler); 222 Token tok = peek_token(compiler);
232 if (name.type == TOKEN_EOF || tok.type == TOKEN_EOF) { 223 if (name.type == TOKEN_EOF || tok.type == TOKEN_EOF) {
233 error_push((Error){ 224 error_push((Error){
@@ -248,12 +239,6 @@ compile_declare_op(Chunk *chunk, Compiler *compiler, Token start, Ops op) {
248 return; 239 return;
249 } 240 }
250 parse_tree(chunk, compiler); 241 parse_tree(chunk, compiler);
251 if (tok.type == TOKEN_SYMBOL) {
252 ssize_t idx = find_local_index(chunk, tok);
253 if (idx < 0) {
254 add_code(chunk, OP_GET, tok.line, tok.column);
255 }
256 }
257 if (peek_token(compiler).type != TOKEN_RPAREN) { 242 if (peek_token(compiler).type != TOKEN_RPAREN) {
258 error_push((Error){ 243 error_push((Error){
259 .type = ERR_TYPE_COMPILER, 244 .type = ERR_TYPE_COMPILER,
@@ -343,7 +328,10 @@ compile_fun_op(Chunk *chunk, Compiler *compiler, Token start) {
343 }); 328 });
344 return; 329 return;
345 } 330 }
346 parse_tree(chunk, compiler); 331 Object obj = make_symbol(name.value);
332 emit_constant(chunk, name, obj);
333 next_token(compiler);
334
347 compile_lambda(chunk, compiler, start, name.value); 335 compile_lambda(chunk, compiler, start, name.value);
348 add_code(chunk, OP_DEF, start.line, start.column); 336 add_code(chunk, OP_DEF, start.line, start.column);
349} 337}
@@ -533,6 +521,7 @@ parse_tree(Chunk *chunk, Compiler *compiler) {
533 if (idx < 0) { 521 if (idx < 0) {
534 Object obj = make_symbol(tok.value); 522 Object obj = make_symbol(tok.value);
535 emit_constant(chunk, tok, obj); 523 emit_constant(chunk, tok, obj);
524 add_code(chunk, OP_GET, tok.line, tok.column);
536 return; 525 return;
537 } 526 }
538 527