by uticus · 3y ago · 0 comments
I'm always confused by the relationship of C and Lisp(s). Here the VM is written in C. Yet elsewhere there seem to be at least one good example of a Lisp compiler written in Lisp [0]. What was the reason for writing Maiko in C, versus Lisp "all the way"?
[0] "The first complete Lisp compiler, written in Lisp, was implemented in 1962 by Tim Hart and Mike Levin at MIT, and could be compiled by simply having an existing LISP interpreter interpret the compiler code, producing machine code output able to be executed at a 40-fold improvement in speed over that of the interpreter.[19] This compiler introduced the Lisp model of incremental compilation, in which compiled and interpreted functions can intermix freely. The language used in Hart and Levin's memo is much closer to modern Lisp style than McCarthy's earlier code. " https://en.wikipedia.org/wiki/Lisp_(programming_language)#Hi...
Now, one could write a virtual machine in Lisp, but usually one would write it in C or assembler, since that's what squeezes more performance out of the hardware and makes interfacing to the operating system 'easier' (threads, calls into the OS, memory management, interrupts, error handling, etc.).
There are examples where (parts of) a virtual machine are written in Lisp. For example the Virtual-CPU emulator may be generated as C or assembler code from a Lisp program. There are also special versions of, say, the JVM written in Lisp to prove its correctness. Ideally one may want to have the core VM emulator written in assembler to reduce it to the most minimum hardware instructions per virtual machine instruction.
The example you cited from 1962 is a Lisp compiler written in Lisp, compiled by itself, running in a Lisp whose runtime was written in assembler (IIRC).
[0] https://online.interlisp.org/main
[1] Part of my confusion may stem from ideas like presented by Chuck Moore in Masterminds of Programming by Biancuzzi: "Operating systems are dauntingly complex and totally unnecessary. It’s a brilliant thing that Bill Gates has done in selling the world on the notion of operating systems. It’s probably the greatest con game the world has ever seen.
An operating system does absolutely nothing for you. As long as you had something—a subroutine called disk driver, a subroutine called some kind of communication support, in the modern world, it doesn’t do anything else. In fact, Windows spends a lot of time with overlays and disk management all [sic] stuff like that which are irrelevant. You’ve got gigabyte disks; you’ve got megabyte RAMs. The world has changed in a way that renders the operating system unnecessary.
What about device support?
Chuck: You have a subroutine for each device. That’s a library, not an operating system. Call the ones you need or load the ones you need."
When Danny went to PARC they started working on a port of Interlisp to the D machine hardware. The model adopted was that of smalltalk: a hermetic environment running on the bare iron, with everything (drivers, network stack etc) written in lisp. One big difference from the MIT world was that smalltalk and Interlisp were built around working in a world and checkpointing the entire machine state, rather than loading files into a base image.
PARC also had a lot of network-only RPC services (mail, filesystem, printing, etc) so each environment had its own implementation of talking to these services, and all its own UX. We’re talking late 70s here, some of it more sophisticated than what you can get today.
> Genera is your whole environment; it encompasses what you normally think of as an operating system as well as everything else - system commands and all other activities. From where you look at it, there is no "top-level" controller or exec.
however, typically you'd want the vm to be easily portable / buildable in new environments, and that's much easier to achieve with c.
and it is likely just easier to write this kind of low-level code in c (however i know plenty of people who will gladly demonstrate otherwise).
consider that the jvm et al are also written in c(++), for much the same reasons of practicality.
It’s actually been an unfortunate and pernicious codependence IMHO.