diff options
Diffstat (limited to 'src/bytecode/compiler.h')
-rwxr-xr-x | src/bytecode/compiler.h | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/src/bytecode/compiler.h b/src/bytecode/compiler.h index 27ff312..124c345 100755 --- a/src/bytecode/compiler.h +++ b/src/bytecode/compiler.h | |||
@@ -608,26 +608,29 @@ parse_tree(Chunk *chunk, Compiler *compiler) { | |||
608 | return; | 608 | return; |
609 | } break; | 609 | } break; |
610 | case TOKEN_SYMBOL: { | 610 | case TOKEN_SYMBOL: { |
611 | size_t depth = compiler->scope_depth - 1; | 611 | if (compiler->scope_depth > 1) { |
612 | ssize_t idx = -1; | 612 | size_t depth = compiler->scope_depth - 1; |
613 | do { | 613 | ssize_t idx = -1; |
614 | Scope *scope = &compiler->scopes[depth]; | 614 | do { |
615 | idx = find_local_index(scope, tok); | 615 | Scope *scope = &compiler->scopes[depth]; |
616 | idx = find_local_index(scope, tok); | ||
617 | if (idx >= 0) { | ||
618 | break; | ||
619 | } | ||
620 | depth--; | ||
621 | } while (depth > 0); | ||
622 | |||
616 | if (idx >= 0) { | 623 | if (idx >= 0) { |
617 | break; | 624 | emit_constant(chunk, tok, FIXNUM_VAL(depth)); |
625 | emit_constant(chunk, tok, FIXNUM_VAL(idx)); | ||
626 | add_code(chunk, OP_LOCAL, tok.line, tok.column); | ||
627 | return; | ||
618 | } | 628 | } |
619 | depth--; | ||
620 | } while (depth > 0); | ||
621 | |||
622 | if (idx >= 0) { | ||
623 | emit_constant(chunk, tok, FIXNUM_VAL(depth)); | ||
624 | emit_constant(chunk, tok, FIXNUM_VAL(idx)); | ||
625 | add_code(chunk, OP_LOCAL, tok.line, tok.column); | ||
626 | } else { | ||
627 | Object obj = make_symbol(tok.value); | ||
628 | emit_constant(chunk, tok, obj); | ||
629 | add_code(chunk, OP_GET, tok.line, tok.column); | ||
630 | } | 629 | } |
630 | |||
631 | Object obj = make_symbol(tok.value); | ||
632 | emit_constant(chunk, tok, obj); | ||
633 | add_code(chunk, OP_GET, tok.line, tok.column); | ||
631 | return; | 634 | return; |
632 | } break; | 635 | } break; |
633 | case TOKEN_NIL: { | 636 | case TOKEN_NIL: { |