From 690038a3c75463681c2acc49689f0472b1698e89 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 23 Mar 2018 06:50:58 -0700 Subject: vm: change encoding of getv, setv and related. In most compiler uses of bindv, getv and setv, the operand which names the dynamic symbol is the data table: a d0-dff register. The source or destination register of the transfer could be anything. Therefore, the existing encoding is suboptimal: the symbol is being put into the full sized operand field of the instruction, and the source or destination register into the small, ten-bit extra field in the upper half. This breaks on cases like (set x y) where x is a deeply nested lexical variable and y is a dynamic variable. Let's reverse the encoding. * share/txr/stdlib/asm.tl (op-getv, op-setv): Reverse the operands. All derived opcodes follow this since they reuse the code via inheritance. * vm.c (vm_get_binding): Fetch the symbol from the small operand field rather than the main operand field. (vm_getsym, vm_getbind, vm_setsym, vm_bindv): Pull the destination or source from the main operand of the instruction rather than the small opreand. --- vm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'vm.c') diff --git a/vm.c b/vm.c index 9f0ff266..3b9c64ca 100644 --- a/vm.c +++ b/vm.c @@ -707,7 +707,7 @@ static val vm_get_binding(struct vm *vm, vm_word_t insn, val (*lookup_fn)(val env, val sym), val kind_str) { - val sym = vm_get(vm->dspl, vm_insn_operand(insn)); + val sym = vm_get(vm->dspl, vm_insn_extra(insn)); val binding = lookup_fn(nil, sym); if (nilp(binding)) @@ -721,7 +721,7 @@ static void vm_getsym(struct vm *vm, vm_word_t insn, val kind_str) { val binding = vm_get_binding(vm, insn, lookup_fn, kind_str); - int dst = vm_insn_extra(insn); + unsigned dst = vm_insn_operand(insn); vm_set(vm->dspl, dst, cdr(binding)); } @@ -730,7 +730,7 @@ static void vm_getbind(struct vm *vm, vm_word_t insn, val kind_str) { val binding = vm_get_binding(vm, insn, lookup_fn, kind_str); - int dst = vm_insn_extra(insn); + unsigned dst = vm_insn_operand(insn); vm_set(vm->dspl, dst, binding); } @@ -739,14 +739,14 @@ static void vm_setsym(struct vm *vm, vm_word_t insn, val kind_str) { val binding = vm_get_binding(vm, insn, lookup_fn, kind_str); - int src = vm_insn_extra(insn); + unsigned src = vm_insn_operand(insn); rplacd(binding, vm_get(vm->dspl, src)); } static void vm_bindv(struct vm *vm, vm_word_t insn) { - val sym = vm_get(vm->dspl, vm_insn_operand(insn)); - int src = vm_insn_extra(insn); + val sym = vm_get(vm->dspl, vm_insn_extra(insn)); + int src = vm_insn_operand(insn); if (nilp(dyn_env)) eval_error(vm->vd->bytecode, -- cgit v1.2.3