diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2018-03-10 20:10:40 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2018-03-10 20:10:40 -0800 |
commit | 0ed1a4855cd4c821107dde0eb43e472fe233374b (patch) | |
tree | d20f1a4fd4724707a49c3dfca6d4aef39203c5a7 /vmop.h | |
parent | 82d26bb83a07c5eac808455c3f7dab50f55f4a8a (diff) | |
download | txr-0ed1a4855cd4c821107dde0eb43e472fe233374b.tar.gz txr-0ed1a4855cd4c821107dde0eb43e472fe233374b.tar.bz2 txr-0ed1a4855cd4c821107dde0eb43e472fe233374b.zip |
New: virtual machine with assembler.
This commit is the start of compiler work to make TXR Lisp
execute faster. In six days of part time work, we now have a
register-style virtual machine with 32 instructions, handling
exceptions, unwind-protect, lexical closures, and global
environment access/mutation. We have a complete assembler and
disassembler for this machine. The assembler supports labels
with forward referencing with backpatching, and features
pseudo-ops: for instance the (mov ...) pseudo-instruction
chooses one of three kinds of specific move instruction based
on the operands.
* Makelfile (OBJS): Add vm.o.
* eval.c (lookup_sym_lisp1): Static function becomes external;
the virtual machine needs to use this to support that style
of lookup.
* genvmop.txr: New file. This is the generator for the
"vmop.h" header.
* lib.c (func_vm): New function.
(generic_funcall): Handle the FVM function type via new
vm_execute_closure function. In the variadic case, we want
to avoid the argument copying which we do for the sake of C
functions that get their fixed arguments directly, and then
just the trailing arguments. Thus the code is restructured a
bit in order to switch twice on the function type.
(init): Call vm_init.
* lib.h (functype_t): New enum member FVM.
(struct func): New member in the .f union: vm_desc.
(func_vm): Declared.
* lisplib.c (set_dlt_entries_impl): New static function,
formed from set_dlt_entries.
(set_dlt_entries): Reduced to wrapper for
set_dlt_entries_impl, passing in the user package.
(set_dlt_entries_sys): New static function: like
set_dlt_entries but targetting the sys package.
(asm_instantiate, asm_set_entries): New static functions.
(lisplib_init): Auto-load the sys:assembler class.
* share/txr/stdlib/asm.tl: New file.
* vm.c, vm.h, vmop.h: New files.
Diffstat (limited to 'vmop.h')
-rw-r--r-- | vmop.h | 61 |
1 files changed, 61 insertions, 0 deletions
@@ -0,0 +1,61 @@ +/* Copyright 2018 + * Kaz Kylheku <kaz@kylheku.com> + * Vancouver, Canada + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +typedef enum vm_op { + NOOP = 0, + FRAME = 1, + DFRAME = 2, + END = 3, + FIN = 4, + CALL = 5, + APPLY = 6, + MOVRS = 7, + MOVSR = 8, + MOVRR = 9, + MOVRSI = 10, + MOVSMI = 11, + MOVRBI = 12, + JMP = 13, + IF = 14, + UWPROT = 15, + BLOCK = 16, + RETSR = 17, + RETRS = 18, + RETRR = 19, + CATCH = 20, + HANDLE = 21, + GETV = 22, + GETF = 23, + GETL1 = 24, + GETVB = 25, + GETFB = 26, + GETL1B = 27, + SETV = 28, + SETL1 = 29, + BINDV = 30, + CLOSE = 31, +} vm_op_t; |