summaryrefslogtreecommitdiffstats
path: root/vm.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2018-03-12 20:07:10 -0700
committerKaz Kylheku <kaz@kylheku.com>2018-03-12 20:07:10 -0700
commitbf523ef3457d20fd1b1c3e8113136966ec035177 (patch)
treec284e712aa086b10ea8844f0b9570cadf135b5c0 /vm.c
parentc9d60bd84e0a77407b0f88326268c92aaeebd9d2 (diff)
downloadtxr-bf523ef3457d20fd1b1c3e8113136966ec035177.tar.gz
txr-bf523ef3457d20fd1b1c3e8113136966ec035177.tar.bz2
txr-bf523ef3457d20fd1b1c3e8113136966ec035177.zip
vm: introduce sframe instruction.
This is for allocating a new frame purely on the stack. The frame will not be captured by lexical closures, and so can only be used for non-shared variables and additional compiler-generated temporaries (if registers run out, for instance). * share/txr/stdlib/asm.tl (op-sframe, sframe): New opcode class and opcode. * vm.c (vm_do_frame): New static function for the common implementation of frame and sframe. (vm_frame): Now just a call with vm_do_frame, passing the flag indicating that closure capture is enabled for this environment frame. (vm_sframe): New static function. * vmop.h: Regenerated.
Diffstat (limited to 'vm.c')
-rw-r--r--vm.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/vm.c b/vm.c
index 128b8f29..7759500c 100644
--- a/vm.c
+++ b/vm.c
@@ -262,7 +262,7 @@ INLINE void vm_set(struct vm_env *dspl, unsigned ref, val newval)
mut(env->vec);
}
-static void vm_frame(struct vm *vm, vm_word_t insn)
+static void vm_do_frame(struct vm *vm, vm_word_t insn, int capturable)
{
int lev = vm_insn_extra(insn);
int size = vm_insn_operand(insn);
@@ -272,11 +272,21 @@ static void vm_frame(struct vm *vm, vm_word_t insn)
vm->lev = lev;
vm->dspl[lev].mem = coerce(val *, zalloca(size * sizeof (val *)));
- vm->dspl[lev].vec = num_fast(size);
+ vm->dspl[lev].vec = (capturable ? num_fast(size) : 0);
vm_execute(vm);
vm->lev = lev - 1;
}
+static void vm_frame(struct vm *vm, vm_word_t insn)
+{
+ vm_do_frame(vm, insn, 1);
+}
+
+static void vm_sframe(struct vm *vm, vm_word_t insn)
+{
+ vm_do_frame(vm, insn, 0);
+}
+
static void vm_dframe(struct vm *vm, vm_word_t insn)
{
val saved_dyn_env = dyn_env;
@@ -610,6 +620,9 @@ static val vm_execute(struct vm *vm)
case FRAME:
vm_frame(vm, insn);
break;
+ case SFRAME:
+ vm_sframe(vm, insn);
+ break;
case DFRAME:
vm_dframe(vm, insn);
break;