With apologies to Robert Pirsig:
Is it a language, or an operating system, or a virtual machine?
Mu.
Read these first: problem statement,
readme and installation
instructions (Mu requires minimal dependencies).
Mu's code looks quite alien, requiring editors to be specially configured to
colorize it in a sane manner. So this page provides links to the source files
showing how it currently looks in my custom setup.
Whetting your appetite: some example programs.
- x.mu: a simple program to add two numbers
together. Shows that at bottom Mu is a simple VM bytecode designed to convert
directly to machine code.
- factorial.mu: everyone's favorite
example, showing how Mu supports conditionals and loops without any special
syntax, using the special labels '{' and '}'.
- tangle.mu: another (contrived) version
of factorial showing Mu's ability to 'tangle' code from multiple places into a
single function or 'recipe'.
- counters.mu: lexical scope
- simple examples showing off support for concurrency: fork.mu,
channel.mu
- simple examples showing off hardware control: display.mu,
console.mu.
- screen.mu: example program showing
print primitives that inject a screen dependency which can be faked
for testing.
- static_dispatch.mu: example
program showing mu's ability to define recipes with headers, and allow recipes
with the same name but different headers to coexist.
- chessboard.mu: a little program for
2 people to play chess, with thorough tests of its behavior including both
screen and keyboard handling.
Now a listing of every layer in mu. Recall that you can stop
loading at any layer and get a valid program to run with a subset of features,
that passes all its tests.
Part I: basic infrastructure
000organization.cc: the basic
skeleton program. Compiles and runs but doesn't do much. Later layers
hook into this skeleton to add functionality. Mu's guarantee: you can load
features up until any layer, and it will compile and pass all tests until
that point. More details →
001help.cc: just a simple test layer
to show how to hook into the skeleton. Also summarizes how to invoke Mu,
behaviors that later layers will be providing.
002test.cc: Mu's minimalist test
harness, relying on a couple of one-liners in the makefile to autogenerate
lists of tests to run.
003trace.cc: support for logging
facts about our program, and for checking the facts logged in tests.
(tests for the test harness)
Part II: the Mu virtual machine, designed to compile easily to
machine language.
010vm.cc: core data structures: recipes
(functions), instructions and reagents (operands).
011load.cc: the textual representation
of recipes and how it's turned into the data structures.
012transform.cc: after Mu
programs are loaded but before they are run they can be transformed in an
extensible manner akin to lisp macros. Think of this as the core of Mu's
‘compiler’ for providing high-level features atop the core.
013update_operation.cc:
our first transform: check for unknown recipes before the program runs.
014literal_string.cc: extend
the loader to support literal strings in various instructions.
015literal_noninteger.cc:
extend the loader to support non-integer numbers.
020run.cc: executing Mu recipes by
executing the list of instructions they contain. Future layers will define
more primitive operations that can be used in instructions.
021check_instruction.cc:
harness for adding per-primitive checks to run before running a program.
Various primitive operations: on numbers,
booleans, for control flow,
and comparing values.
029tools.cc: various primitive
operations to help with testing and debugging.
030container.cc: Mu supports
compound types akin to records, structs or classes.
031address.cc: adding and removing
layers of indirection to Mu data.
032array.cc: all Mu data structures
are bounds-checked.
033exclusive_container.cc: tagged unions or sum types.
034call.cc: calls to recipes look
just like primitive operations.
035call_ingredient.cc: how
recipes pass arguments or 'ingredients' without introducing any syntax and
breaking the metaphor of recipes as lists of instructions.
036call_reply.cc: recipes can
return arbitrary numbers of values to their callers.
038new.cc: rudimentary memory
allocator that is aware of all global types in any Mu program.
061recipe.cc: passing recipes around
as first-class values in higher-order functions.
062scheduler.cc: running multiple
recipes concurrently using routines that might execute in interleaved
fashion.
063wait.cc: primitives for
synchronization between routines.
Part III: transforms to provide 80% of the benefits of high-level
languages.
040brace.cc and
041jump_target.cc: how Mu provides
structured goto-less programming without introducing the syntax of
conditionals and loops other languages require.
042name.cc: how Mu transforms variable
names to raw memory addresses.
043space.cc: how variables in
different routines are isolated from each other using spaces. Mu
‘local variables’ are allocated on the heap.
044space_surround.cc:
Chaining spaces together to accomodate variables with varying lifetimes and
ownership properties.
045closure_name.cc: how spaces
can implement lexical scope.
046global.cc: support for 'global'
variables that are always available inside a single routine. Mu has no
variables that are available transparently across routines.
047check_type_by_name.cc:
a simple transform to deduce missing types in instructions on the basis of
previous instructions in the same recipe.
050scenario.cc: Mu's first syntax
— not for code but for tests. (example)
052tangle.cc: support for layers in
Mu programs. They've been so good to us.
Support for shape-shifting or generic data structures that can
contain type ingredients: 054dilated_reagent.cc,
a new syntax for allowing whitespace in types; 055parse_tree.cc,
a new syntax for representing complex types as trees using whitespace and
parentheses (s-expressions); 056recipe_header.cc,
a new syntax for introducing ingredients and products with the name of a reagent;
057static_dispatch.cc, allowing
multiple variants of a recipe to coexist with support for different headers;
058shape_shifting_container.cc,
a new syntax for wildcard type ingredients in containers; and finally
059shape_shifting_recipe.cc,
support for type ingredients in recipes. Everytime you call a shape-shifting
recipe with a new set of types for its type ingredients, it creates a
new variant of the recipe for you matching those types.
060immutable.cc, a static analysis to
ensure that recipes never modify anything but their products.
998check_type_pointers.cc.html:
After all our messing about with types, a final pass to make sure we didn't
introduce any invalid types.
999spaces.cc.html: Maps summarizing
various address spaces in the core, and the conventions that regulate their
use in previous layers.
various address spaces in the core, and the conventions that regulate their
use in previous layers.
Part IV: beginnings of a standard library
070text.mu: strings in Mu are
bounds-checked rather than null-terminated. They're also unicode-aware (code
points only; no control characters, no combining characters, no normalization).
071channel.mu: channels are Mu's
only synchronization primitive, queues that can cause the routine reading or
writing from them to stall without taking up CPU resources.
072array.mu
073list.mu: linked lists where each
node points to the next, permitting fast insertion/deletion but slow for
search.
074random.cc
075duplex_list.mu: doubly linked
lists that can be traversed both forwards and back.
076stream.mu: data structure to
efficiently append strings.
Part V: Nascent tools for browsing Mu codebases, and for teaching
programming to non-programmers by getting them hooked on the value of tests.
The eventual goal is an environment that watches programmers as they
manually test their code, and turns these interactive sessions into
reproducible test scenarios.
080display.cc: primitives for using
the keyboard and screen.
081print.mu: helpers that can swap
the real screen with fake ones for testing.
082scenario_screen.cc:
writing tests that check what is printed to screen.
(examples)
084console.mu: helpers that can
swap the real keyboard and mouse with fake ones for testing.
085scenario_console.cc:
writing tests for keyboard and mouse using the fakes.
(examples)
090trace_browser.cc: a
zoomable UI for inspecting traces generated by Mu programs. Allows both
scanning a high-level view and drilling down into selective details.
091run_interactive.cc:
hacky primitives for running Mu code in the programming environment below.
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color