Implementing the Braincons virtual machine

I'm back to work on Braincons, a Brainfuck implementation I'm developing with Medley Interlisp.

The new code I wrote implements the virtual machine (VM) and executes the Braunfuck instructions. Now Braincons can create and reset a VM, load a program into it, and execute the program until completion or for a designated number of steps.

The Lisp record BRC.VM represents the VM and holds the Brainfuck program, memory, machine state such as the instruction and memory pointers, and virtual I/O devices. All the functions that operate on the VM accept a BRC.VM record as an argument, update it as necessary, and return the record.

To decouple as much as possible I/O from other subsystems, BRC.VM contains the IN and OUT fields to hold a Lisp input stream and a Lisp output stream.

Any functions that need to read data or display output on behalf of the VM can do I/O to the relevant VM streams. This adds flexibility as most Interlisp text and window output functions accept streams as arguments.

Having the book A Philosophy of Software Design fresh in my mind after recently reading it, to design the Braincons VM I deliberately sat down to think about and write a specification of how the features needed to work. Although the book presents a lot of material I haven't absorbed yet, this preliminary work helped me design a relatively small and clean VM interface and saved some code rewriting.

Now that Braincons can parse, compile, and execute Braunfuck programs, the next step will be to build the user interface for editing and running programs, as well as inspecting the VM and its state.

#braincons #Interlisp #Lisp

Discuss... Email | Reply @amoroso@fosstodon.org