diff options
Diffstat (limited to 'src/bytecode')
-rwxr-xr-x | src/bytecode/compiler.h | 14 | ||||
-rwxr-xr-x | src/bytecode/vm.h | 5 |
2 files changed, 11 insertions, 8 deletions
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) { | |||
520 | 520 | ||
521 | void | 521 | void |
522 | compile_call_op(Chunk *chunk, Compiler *compiler, Token start, Token name) { | 522 | compile_call_op(Chunk *chunk, Compiler *compiler, Token start, Token name) { |
523 | if (name.type == TOKEN_SYMBOL) { | ||
524 | parse_symbol(chunk, compiler, name); | ||
525 | } | ||
526 | |||
523 | // Compile body. | 527 | // Compile body. |
524 | size_t n = 0; | 528 | size_t n = 0; |
525 | while (has_next_token(compiler)) { | 529 | while (has_next_token(compiler)) { |
@@ -540,11 +544,6 @@ compile_call_op(Chunk *chunk, Compiler *compiler, Token start, Token name) { | |||
540 | parse_tree(chunk, compiler); | 544 | parse_tree(chunk, compiler); |
541 | n++; | 545 | n++; |
542 | } | 546 | } |
543 | if (name.type == TOKEN_SYMBOL) { | ||
544 | Object obj = make_symbol(name.value); | ||
545 | emit_constant(chunk, start, obj); | ||
546 | add_code(chunk, OP_GET, start.line, start.column); | ||
547 | } | ||
548 | emit_constant(chunk, start, FIXNUM_VAL(n)); | 547 | emit_constant(chunk, start, FIXNUM_VAL(n)); |
549 | add_code(chunk, OP_CALL, start.line, start.column); | 548 | add_code(chunk, OP_CALL, start.line, start.column); |
550 | } | 549 | } |
@@ -635,7 +634,10 @@ parse_list(Chunk *chunk, Compiler *compiler, Token start) { | |||
635 | case TOKEN_GREATER_EQUAL: { compile_list_binary_op(chunk, compiler, start, OP_GREATER_EQUAL); } break; | 634 | case TOKEN_GREATER_EQUAL: { compile_list_binary_op(chunk, compiler, start, OP_GREATER_EQUAL); } break; |
636 | case TOKEN_PRINT: { compile_list_unary_op(chunk, compiler, start, OP_PRINT); } break; | 635 | case TOKEN_PRINT: { compile_list_unary_op(chunk, compiler, start, OP_PRINT); } break; |
637 | case TOKEN_DISPLAY: { compile_list_unary_op(chunk, compiler, start, OP_DISPLAY); } break; | 636 | case TOKEN_DISPLAY: { compile_list_unary_op(chunk, compiler, start, OP_DISPLAY); } break; |
638 | case TOKEN_NEWLINE: { compile_list_simple_op(chunk, compiler, start, OP_NEWLINE); } break; | 637 | case TOKEN_NEWLINE: { |
638 | compile_list_simple_op(chunk, compiler, start, OP_NEWLINE); | ||
639 | emit_constant(chunk, start, NIL_VAL); | ||
640 | } break; | ||
639 | case TOKEN_DEF: { compile_declare_op(chunk, compiler, start, OP_DEF); } break; | 641 | case TOKEN_DEF: { compile_declare_op(chunk, compiler, start, OP_DEF); } break; |
640 | case TOKEN_SET: { compile_declare_op(chunk, compiler, start, OP_SET); } break; | 642 | case TOKEN_SET: { compile_declare_op(chunk, compiler, start, OP_SET); } break; |
641 | case TOKEN_FUN: { compile_fun_op(chunk, compiler, start); } break; | 643 | case TOKEN_FUN: { compile_fun_op(chunk, compiler, start); } break; |
diff --git a/src/bytecode/vm.h b/src/bytecode/vm.h index a02bdd1..0d1595d 100755 --- a/src/bytecode/vm.h +++ b/src/bytecode/vm.h | |||
@@ -193,6 +193,7 @@ vm_interpret(VM *vm) { | |||
193 | // of it that lives on the heap. | 193 | // of it that lives on the heap. |
194 | Object proc = array_pop(vm->stack); | 194 | Object proc = array_pop(vm->stack); |
195 | proc = make_lambda(proc.closure->chunk); | 195 | proc = make_lambda(proc.closure->chunk); |
196 | |||
196 | ssize_t n_captured = AS_FIXNUM(array_pop(vm->stack)); | 197 | ssize_t n_captured = AS_FIXNUM(array_pop(vm->stack)); |
197 | for (ssize_t i = 0; i < n_captured; i++) { | 198 | for (ssize_t i = 0; i < n_captured; i++) { |
198 | Object value = array_pop(vm->stack); | 199 | Object value = array_pop(vm->stack); |
@@ -303,7 +304,7 @@ vm_interpret(VM *vm) { | |||
303 | } break; | 304 | } break; |
304 | case OP_CALL: { | 305 | case OP_CALL: { |
305 | ssize_t n_args = AS_FIXNUM(array_pop(vm->stack)); | 306 | ssize_t n_args = AS_FIXNUM(array_pop(vm->stack)); |
306 | Object proc = array_pop(vm->stack); | 307 | Object proc = vm->stack[array_size(vm->stack) - 1 - n_args]; |
307 | 308 | ||
308 | // Check the number of arguments is correct. | 309 | // Check the number of arguments is correct. |
309 | // NOTE: This is probably better handled at compilation, but for | 310 | // NOTE: This is probably better handled at compilation, but for |
@@ -363,7 +364,7 @@ vm_interpret(VM *vm) { | |||
363 | vm->pc = frame->rp; | 364 | vm->pc = frame->rp; |
364 | array_head(vm->frames)->size--; | 365 | array_head(vm->frames)->size--; |
365 | Object ret = array_pop(vm->stack); | 366 | Object ret = array_pop(vm->stack); |
366 | array_head(vm->stack)->size = frame->stack_offset; | 367 | array_head(vm->stack)->size = frame->stack_offset - 1; |
367 | array_push(vm->stack, ret); | 368 | array_push(vm->stack, ret); |
368 | frame = &vm->frames[array_size(vm->frames) - 1]; | 369 | frame = &vm->frames[array_size(vm->frames) - 1]; |
369 | chunk = frame->closure->chunk; | 370 | chunk = frame->closure->chunk; |