[muddle] exploring MIM

kaz at lambdaverse.org kaz at lambdaverse.org
Wed Feb 21 00:23:47 PST 2018


So, I've been thinking about the MIM design some more, and it could
actually make our interpreter much cleaner.

In a source-interpreter in C, implementing Muddle's stack trickery
requires either stack-switching (nonstandard and fiddly) or breaking
up the builtin functions so that any function that could do an MCALL
has to set up the call and then return (trampolining). Trampolining
makes even simple C functions ugly, because most builtins could
potentially MCALL--the need to be able to do complex control flow at
almost arbitrary times makes the C stack really get in our way.

The MIM design solves the problem neatly: define much smaller
builtins, so that control flow never needs to take place in the middle
of a C function. The entire execution state is in the MIM stack, with
atomic excursions into the C world.

In the course of thinking about MIM's architecture, I've produced some
code and docs. I stashed them in a temporary repo to show what I'm
working on; I'll integrate them with the rest of the interpreter soon.

repo: git://git.lambdaverse.org/git/mim
branch: master

Files:
- mim/doc/distribution.dot: diagram of how the different MIM programs
  and data types interrelate (render with graphviz: `dot -Tx11 ...`)
- mim/codegen.mud: Muddle program (runnable with Confusion) that
  generates from a table of opcodes C implementations of: a MIM
  interpreter, disassembler, and (soon) assembler.
- mim/gen.c: generated by codegen.mud.
- mim/main.c: support code for gen.c.

The interpreter codegen.mud produces is currently capable of running a
fibonacci loop, printing a disassembly trace of opcodes executed along
the way (the loop is imperative because the function call machinery
will come in the integration with our original source-interpreter
codebase). If you compile and run main.c (which #includes gen.c), you
can see it working out the value of 7!:

    0: <GRTRB fix0 1 0 1>
    6: <MUL fix0 fix1 1>
    10: <SUBB fix0 1 0>
    14: <GRTRB fix0 1 0 -8>
    6: <MUL fix0 fix1 1>
    10: <SUBB fix0 1 0>
    14: <GRTRB fix0 1 0 -8>
    6: <MUL fix0 fix1 1>
    10: <SUBB fix0 1 0>
    14: <GRTRB fix0 1 0 -8>
    6: <MUL fix0 fix1 1>
    10: <SUBB fix0 1 0>
    14: <GRTRB fix0 1 0 -8>
    6: <MUL fix0 fix1 1>
    10: <SUBB fix0 1 0>
    14: <GRTRB fix0 1 0 -8>
    6: <MUL fix0 fix1 1>
    10: <SUBB fix0 1 0>
    14: <GRTRB fix0 1 0 -8>
    19: <HALT>
    5040

My next step will be to merge this with the rest of the interpreter;
the current object code, MCALL machinery, ATOMs/BINDings, and that
sort of thing will join the other support code that's in
mim/main.c. From here, we'll have several different layers to work on:

MIM:
1. fill out the rest of the MIM opcode table (probably crib the
non-trivial operations from Confusion)
2a. some items from the original interpreter agenda (GC, etc).
2b. extend MIM design for clean support of PROCESSes
2c. more codegen backends; because MIM is simple and mostly generated,
we can easily run on "anything". Some fun ideas: rpython for the free
tracing JIT; JS so your browser can Muddle too; efficient assembly
implementation for embedded CPUs...

MUM:
1. write an interpreter for full MUM-Muddle, initially targetting
Confusion as platform
2. piecewise port MUM to LiteMuddle, reimplementing Muddle's complex
features in terms of what's easily implemented on top of MIM ops
(exactly what LiteMuddle supports we'll learn mainly by writing MIMC)

MIMC:
1. write a MIMC, initially targetting Confusion
2. as we develop MUM, make sure MIMC runs on it

I'm exited about this new architecture; this is really on track to
becoming the language I've always wanted to write (that will also
require our metacircular evaluator to support partial evaluation, but
let's not get ahead of ourselves).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://muddlers.org/pipermail/muddle/attachments/20180221/96211c9c/attachment.sig>


More information about the muddle mailing list