From 084f913075ede36dd68d6f202307cf043c5a52ac Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 22 Mar 2018 06:26:16 -0700 Subject: vm: ret instructions: throw error if block not found. * vm.c (vm_no_block_err): New static function. (vm_retsr, vm_retrs, vm_retrr): Call vm_no_block_err if uw_block_return returns. --- vm.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/vm.c b/vm.c index 960dd833..b8eb2fed 100644 --- a/vm.c +++ b/vm.c @@ -617,6 +617,17 @@ static void vm_block(struct vm *vm, vm_word_t insn) vm->lev = saved_lev; } +static void vm_no_block_err(struct vm *vm, val name) +{ + if (name) + eval_error(vm->vd->bytecode, + lit("return-from: no block named ~s is visible"), + name, nao); + else + eval_error(vm->vd->bytecode, + lit("return: no anonymous block is visible"), + name, nao); +} static void vm_retsr(struct vm *vm, vm_word_t insn) { @@ -624,6 +635,7 @@ static void vm_retsr(struct vm *vm, vm_word_t insn) val tag = vm_get(vm->dspl, vm_insn_extra(insn)); uw_block_return(tag, res); + vm_no_block_err(vm, tag); } static void vm_retrs(struct vm *vm, vm_word_t insn) @@ -632,6 +644,7 @@ static void vm_retrs(struct vm *vm, vm_word_t insn) val tag = vm_get(vm->dspl, vm_insn_operand(insn)); uw_block_return(tag, res); + vm_no_block_err(vm, tag); } static void vm_retrr(struct vm *vm, vm_word_t insn) @@ -641,6 +654,7 @@ static void vm_retrr(struct vm *vm, vm_word_t insn) val tag = vm_get(vm->dspl, vm_arg_operand_lo(arg)); uw_block_return(tag, res); + vm_no_block_err(vm, tag); } static void vm_catch(struct vm *vm, vm_word_t insn) -- cgit v1.2.3