|
|
|
|
|
by lispm
3038 days ago
|
|
If you look at code with really low-level operators like CAR, CDR, CONS, ATOM, NULL, etc then this is the assembly level of Lisp. If you look at some Lisp Machines, which had a processor with a for Lisp optimized instruction set, many of those mapped relatively direct to corresponding machine instructions - using a mostly stack machine. The CLISP implementation of Common Lisp has a virtual machine implementation. Let's take some simple demonstration code: [1]> (defun foo (a)
(car (cdr (if (null a)
'(1 2)
(cons 3 a)))))
FOO
Now we compile it for the CLISP virtual machine: [2]> (compile 'foo)
FOO ;
NIL ;
NIL
If we look at the disassembled virtual machine code, you'll see that the machine code has actually similar primitives for its stack machine: [3]> (disassemble 'foo)
Disassembly of function FOO
(CONST 0) = (1 2)
(CONST 1) = 3
1 required argument
0 optional arguments
No rest parameter
No keyword parameters
11 byte-code instructions:
0 (LOAD&JMPIFNOT 1 L10)
3 (CONST&PUSH 1) ; 3
4 (LOAD 2)
5 (CONS)
6 L6
6 (CDR)
7 (CAR)
8 (SKIP&RET 2)
10 L10
10 (CONST 0) ; (1 2)
11 (JMP L6)
NIL
Unrelated to that there is also the idea to program assembler code embedded in Lisp - this is often called LAP code (Lisp Assembler Program). Several implementations are using this. |
|