summaryrefslogtreecommitdiffstats
path: root/vm.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2018-03-23 06:50:58 -0700
committerKaz Kylheku <kaz@kylheku.com>2018-03-23 06:50:58 -0700
commit690038a3c75463681c2acc49689f0472b1698e89 (patch)
treeb43d0fead7be6bc3ba55b9b93c00e10cb835e013 /vm.c
parent73784f852159b14c42024bb2451c4c83067f4d6c (diff)
downloadtxr-690038a3c75463681c2acc49689f0472b1698e89.tar.gz
txr-690038a3c75463681c2acc49689f0472b1698e89.tar.bz2
txr-690038a3c75463681c2acc49689f0472b1698e89.zip
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.
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c12
1 files changed, 6 insertions, 6 deletions
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,