about summary refs log tree commit diff stats
path: root/index.html
blob: 422f3a30cbdfc2503e37a83164e84a7f2041c49c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<title>Mu</title>

With apologies to <a href='http://en.wikipedia.org/wiki/Mu_%28negative%29#In_popular_culture'>Robert Pirsig</a>:
<p>
<div style='font-style: italic; margin-left:2em'>
Is it a language, or an operating system, or a virtual machine?
<p>
Mu.
</div>

Read these first: <a href='http://akkartik.name/about'>problem statement</a>,
<a href='http://github.com/akkartik/mu#readme'>readme and installation
  instructions</a> (mu requires minimal dependencies).

<p>
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 <a href='https://github.com/akkartik/mu/blob/master/mu.vim'>custom setup</a>.

<p>Whetting your appetite: some example programs.

<ul>
<li><a href='html/x.mu.html'>x.mu</a>: 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.
<li><a href='html/factorial.mu.html'>factorial.mu</a>: everyone's favorite
example, showing how mu supports conditionals and loops without any special
syntax, using the special labels '{' and '}'.
<li><a href='html/tangle.mu.html'>tangle.mu</a>: another (contrived) version
of factorial showing mu's ability to 'tangle' code from multiple places into a
single function or 'recipe'.
<li><a href='html/counters.mu.html'>counters.mu</a>: lexical scope
<li><a href='html/callcc.mu.html'>callcc.mu</a>: first-class continuations. Mu
also supports first-class functions and delimited continuations.
<li>simple examples showing off support for concurrency: <a href='html/fork.mu.html'>fork.mu</a>,
<a href='html/channel.mu.html'>channel.mu</a>
<li>simple examples showing off hardware control: <a href='html/display.mu.html'>display.mu</a>,
<a href='html/console.mu.html'>console.mu</a>.
<li><a href='html/screen.mu.html'>screen.mu</a>: example program showing
print primitives that inject a screen <em>dependency</em> which can be faked
for testing.
<li><a href='html/chessboard.mu.html'>chessboard.mu</a>: putting it all
together, a little console program along with thorough tests of its behavior
including both screen and keyboard handling.
<li><a href='html/edit.mu.html'>edit.mu</a>: the programming environment I
plan to use to teach programming.
</ul>

<p><b>Part I</b>: basic infrastructure
<p/><a href='html/000organization.cc.html'>000organization.cc</a>: the basic
skeleton program. Compiles and runs but doesn't do much. Later <em>layers</em>
hook into this skeleton to add functionality. Mu's guarantee: you can <a href='http://youtube.com/watch?v=c8N72t7aScY'>load
features</a> up until any layer, and it will compile and pass all tests until
that point. <a href='http://akkartik.name/post/wart-layers'>More details &rarr;</a>
<br/><a href='html/001help.cc.html'>001help.cc</a>: 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.
<br/><a href='html/002test.cc.html'>002test.cc</a>: mu's minimalist test
harness, relying on a couple of one-liners in the makefile to autogenerate
lists of tests to run.
<br/><a href='html/003trace.cc.html'>003trace.cc</a>: support for logging
facts about our program, and for <a href='http://akkartik.name/post/tracing-tests'>checking the facts logged in tests</a>.
(<a href='html/003trace.test.cc.html'>tests for the test harness</a>)

<p><b>Part II</b>: the mu virtual machine, designed to compile easily to
machine language.
<p/><a href='html/010vm.cc.html'>010vm.cc</a>: core data structures: recipes
(functions), instructions and reagents (operands).
<br/><a href='html/011load.cc.html'>011load.cc</a>: the textual representation
of recipes and how it's turned into the data structures.
<br/><a href='html/012transform.cc.html'>012transform.cc</a>: 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
&lsquo;compiler&rsquo; for providing high-level features atop the core.
<br/><a href='html/013literal_string.cc.html'>013literal_string.cc</a>: extend
the loader to support literal strings in various instructions.
<br/><a href='html/014literal_noninteger.cc.html'>014literal_noninteger.cc</a>:
extend the loader to support non-integer numbers.
<br/><a href='html/020run.cc.html'>020run.cc</a>: executing mu recipes by
executing the list of instructions they contain.
<br/>Various primitive operations: on <a href='html/021arithmetic.cc.html'>numbers</a>,
<a href='html/022boolean.cc.html'>booleans</a>, for <a href='html/023jump.cc.html'>control flow</a>,
and <a href='html/024compare.cc.html'>comparing values</a>.
<br/>Primitive operations to help with testing: <a href='html/025trace.cc.html'>tracing/logging</a>, 
<a href='html/026assert.cc.html'>assert</a> and
<a href='html/027debug.cc.html'>debug by print</a>.

<br/><a href='html/030container.cc.html'>030container.cc</a>: compound types
akin to records, structs or classes.
<br/><a href='html/031address.cc.html'>031address.cc</a>: adding and removing
layers of indirection to mu data.
<br/><a href='html/032array.cc.html'>032array.cc</a>: all mu data structures
are bounds-checked.
<br/><a href='html/033exclusive_container.cc.html'>033exclusive_container.cc</a>: tagged unions or sum types.
<br/><a href='html/034call.cc.html'>034call.cc</a>: calls to recipes look
just like primitive operations.
<br/><a href='html/035call_ingredient.cc.html'>035call_ingredient.cc</a>: how
recipes pass arguments or 'ingredients' without introducing any syntax and
breaking the metaphor of recipes as lists of instructions.
<br/><a href='html/036call_reply.cc.html'>036call_reply.cc</a>: recipes can
return arbitrary numbers of values to their callers.
<br/><a href='html/037recipe.cc.html'>037recipe.cc</a>: passing recipes around
as first-class values in higher-order functions.
<br/><a href='html/038scheduler.cc.html'>038scheduler.cc</a>: running multiple
recipes concurrently using <em>routines</em> that might execute in interleaved
fashion.
<br/><a href='html/039wait.cc.html'>039wait.cc</a>: primitives for
synchronization between routines.

<p><b>Part III</b>: transforms to provide 80% of the benefits of high-level
languages.
<br/><a href='html/040brace.cc.html'>040brace.cc</a> and
<a href='html/041jump_label.cc.html'>041jump_label.cc</a>: how mu provides
structured goto-less programming without introducing the syntax of
conditionals and loops other languages require.
<br/><a href='html/042name.cc.html'>042name.cc</a>: how mu transforms variable
names to raw memory addresses.
<br/><a href='html/043new.cc.html'>043new.cc</a>: rudimentary memory
allocator that is aware of all global types in any mu program.
<br/><a href='html/044space.cc.html'>044space.cc</a>: how variables in
different routines are isolated from each other using <em>spaces</em>. Mu
&lsquo;local variables&rsquo; are allocated on the heap.
<br/><a href='html/045space_surround.cc.html'>045space_surround.cc</a>:
Chaining spaces together to accomodate variables with varying lifetimes and
ownership properties.
<br/><a href='html/046closure_name.cc.html'>046closure_name.cc</a>: how spaces
can implement lexical scope.
<br/><a href='html/047global.cc.html'>047global.cc</a>: support for 'global'
variables that are always available inside a single routine. Mu has no
variables that are available transparently across routines.
<br/><a href='html/048typecheck.cc.html'>048typecheck.cc</a>: a simple
transformer to insert missing types in instructions.
<br/><a href='html/050scenario.cc.html'>050scenario.cc</a>: mu's first syntax
&mdash; not for code but for tests. (<a href='html/051scenario_test.mu.html'>example</a>)
<br/><a href='html/052tangle.cc.html'>052tangle.cc</a>: support for layers in
mu programs. They've been so good to us.
<br/><a href='html/053continuation.cc.html'>053continuation.cc</a>:
first-class and delimited continuations, primitives for yield, exceptions and
much else besides.

<p><b>Part IV</b>: beginnings of a standard library
<p/><a href='html/060string.mu.html'>060string.mu</a>: strings in mu are
bounds-checked rather than null-terminated. They're also unicode-aware.
<br/><a href='html/061channel.mu.html'>061channel.mu</a>: 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.
<br/><a href='html/062array.mu.html'>062array.mu</a>
<br/><a href='html/063list.mu.html'>063list.mu</a>: linked lists where each
node points to the next, permitting fast insertion/deletion but slow for
search.
<br/><a href='html/064random.cc.html'>064random.cc</a>
<br/><a href='html/065duplex_list.mu'>065duplex_list.mu</a>: doubly linked
lists that can be traversed both forwards and back.
<br/><a href='html/066stream.mu'>066stream.mu</a>: data structure to
efficiently append strings.

<p><b>Part V</b>: 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 <b>an environment that watches programmers as they
manually test their code, and turns these interactive sessions into
reproducible test scenarios.</b>

<p/><a href='html/070display.cc.html'>070display.cc</a>: primitives for using
the keyboard and screen.
<br/><a href='html/071print.mu.html'>071print.mu</a>: helpers that can swap
the real screen with fake ones for testing.
<br/><a href='html/072scenario_screen.cc.html'>072scenario_screen.cc</a>:
writing tests that check what is printed to screen.
(<a href='html/073scenario_screen_test.mu.html'>examples</a>)
<br/><a href='html/074console.mu.html'>074console.mu</a>: helpers that can
swap the real keyboard and mouse with fake ones for testing.
<br/><a href='html/075scenario_console.cc.html'>075scenario_console.cc</a>:
writing tests for keyboard and mouse using the fakes.
(<a href='html/076scenario_console_test.mu.html'>examples</a>)
<br/><a href='html/080trace_browser.cc.html'>080trace_browser.cc</a>: a
zoomable UI for inspecting traces generated by mu programs. Allows both
scanning a high-level view and drilling down into selective details.
<br/><a href='html/081run_interactive.cc.html'>081run_interactive.cc</a>:
hacky primitives for supporting the mu programming environment in <a
href='html/edit.mu.html'>edit.mu</a>.
<br/><a href='html/082persist.cc.html'>082persist.cc</a>: more hacky
primitives for supporting saving/restoring sessions in the mu programming
environment.

<p/><a href='html/999spaces.cc.html'>Epilogue</a>: maps summarizing various
address spaces, and the conventions that regulate their use in previous
layers.

<hr>

<p>
The zen of mu:
<ul>
<li>traces, not interfaces
<li>be rewrite-friendly, not backwards-compatible
<li>be easy to port rather than portable
<li>global structure matters more than local hygiene
</ul>

<p>
Mu's vision of utopia:
<ul>
<li>Run your devices in 1/1000th the code.
<li>1000x more forks for open source projects.
<li>Make simple changes to any project in an afternoon, no matter how large it is.
<li>Projects don't slow down with age, they continue to evolve just as fast as
when they were first started.
<li>All software rewards curiosity, allowing anyone to query its design
decisions, gradually learn how to tweak it, try out increasingly radical
redesign ideas in a sandbox. People learn programming as an imperceptible side
effect of tinkering with the projects they care about.
<li><a href='https://www.dreamsongs.com/Files/PatternsOfSoftware.pdf'>Habitable</a> digital environments.
<li>A <em>literate</em> digital society with widespread skills for
comprehending large-scale software structure and comparing-and-contrasting
similar solutions. (I don't think anybody is literate by this definition
today. All we can do easily is read our own programs that we wrote recently.)
</ul>

<p style='margin-bottom: 2em'/>