about summary refs log blame commit diff stats
path: root/index.html
blob: a1b158d3d8838449ae580857fb78e9539a86fe78 (plain) (tree)
1
2
3
4
5
6
7
8
9

                 
                                                                                                                
   

                                                               
   

      
 

                                                                             
                                                      
 
   


                                                                                                                  
 



                                                                          
                                                                             

                                                                          
                                                                           

                                                                            
                                                                              

                                                                  


                                                                                                 
                                              


                                                                            
                                                                          

                                                                        


                                                                             

     



                                                                                                            




                                                                                                                           
                                                                                   
                                                                            
                                                                        
                                              
                                                                        





                                                                                                                          
                                                                        
                 

                                                                    
                                                                              
                                                          
                                                                      
                                                                         
                                                                        
                                                                       
                                                                           
                                                                         
                                                                              
                                                              
                                                                               
                                                 
                                                                           






                                                                                                    






                                                                             

                                                                       
 
                                                                        
                                                                              
                                                                            
                   
                                                                                 
                           








                                                                             
                                                       
                                                                              

                                                                    
                                                                  



                                                                           
                                                        
                                                                            

                                                                  
                                                                              
                              
                                                                      

                                                                         
                                                                       

                                                                           
                                                                              
                            




                                                                            
                                                                               
                                                                          
                                           
                                                                             

                                                                                         
                                        
                                                                            

                                                                                                         
                                                                         
                                                                                             
                                                                                 
                                                                             
                                                                              
                                                                                       
                                                                              
                                                                                 


                                                                              
                                                                                  
                                                               
                                                                                     




                                                                             

                                                                           

                                                   
                                                                    

                                                                               



                                                                                       







                                                                               

                                                                            

                                                                           

                                                                        

                                                                        
                                                          
                                                                         
                           
 
                                                                           
                                                                            


                                                                       
 
                                                                             
                        
                                                                           
                                           
                                                                         
                                                   

                                                                          
                                                            
                                                                           
                                                     

                                                                       
                                                                       
                                                                    
                                                                         
                                                                          
                                                                    
                                                                         
            
 





























                                                                                                                
                                                                                                             
                                     

                                                                   

                                                                             
 

    


              



                                                    

     


                      














                                                                                                         
 
                               
<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>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/static_dispatch.mu.html'>static_dispatch.mu</a>: example
program showing mu's ability to define functions with headers, and allow
functions with the same name but different headers to coexist.
<li><a href='html/chessboard.mu.html'>chessboard.mu</a>: a little program for
2 people to play chess, with thorough tests of its behavior including both
screen and keyboard handling.
</ul>

Now a listing of every layer in mu. Recall that you can <a href='http://akkartik.name/post/wart-layers'>stop
loading at any layer and get a valid program to run with a subset of features,
that passes all its tests</a>.

<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:
functions, instructions and reagents (operands).
<br/><a href='html/011load.cc.html'>011load.cc</a>: the textual representation
of functions 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/013update_operation.cc.html'>013update_operation.cc</a>:
our first transform: check for unknown functions before the program runs.
<br/><a href='html/014literal_string.cc.html'>014literal_string.cc</a>: extend
the loader to support literal strings in various instructions.
<br/><a href='html/015literal_noninteger.cc.html'>015literal_noninteger.cc</a>:
extend the loader to support non-integer numbers.
<br/><a href='html/020run.cc.html'>020run.cc</a>: executing Mu functions by
executing the list of instructions they contain. Future layers will define
more primitive operations that can be used in instructions.
<br/><a href='html/021check_instruction.cc.html'>021check_instruction.cc</a>:
harness for adding per-primitive checks to run before running a program.
<br/>Various primitive operations: on <a href='html/022arithmetic.cc.html'>numbers</a>,
<a href='html/023boolean.cc.html'>booleans</a>, for <a href='html/024jump.cc.html'>control flow</a>,
and <a href='html/025compare.cc.html'>comparing values</a>.
<br/><a href='html/026call.cc.html'>026call.cc</a>: calls to functions look
just like primitive operations.
<br/><a href='html/027call_ingredient.cc.html'>027call_ingredient.cc</a>: how
functions pass arguments or 'ingredients' without introducing any syntax and
breaking the metaphor of functions as lists of instructions.
<br/><a href='html/028call_reply.cc.html'>028call_reply.cc</a>: functions can
return arbitrary numbers of values to their callers.
<br/><a href='html/029tools.cc.html'>029tools.cc</a>: various primitive
operations to help with testing and debugging.

<p/><a href='html/030container.cc.html'>030container.cc</a>: Mu supports
compound types called <em>containers</em> akin to records, structs or classes.
<br/><a href='html/031array.cc.html'>031array.cc</a>: all Mu data structures
are bounds-checked.
<br/><a href='html/032exclusive_container.cc.html'>032exclusive_container.cc</a>:
tagged unions or sum types.
<br/><a href='html/033address.cc.html'>033address.cc</a>: Mu requires you to
manually manage memory. However, it provides transparent refcounting for all
addresses, making it entirely safe from the sorts of undefined behavior and
security vulnerabilities that plague C. Compared to Rust, Mu gives up some
runtime efficiency in exchange for C-like flexibility (you can copy addresses
around all you like, and write from any copy of an address) and simpler
implementation (since I punt on Rust's static analysis).

<p/><a href='html/061recipe.cc.html'>061recipe.cc</a>: passing functions
around as first-class values in higher-order functions.
<br/><a href='html/062scheduler.cc.html'>062scheduler.cc</a>: running multiple
functions concurrently using <em>routines</em> that might execute in
interleaved fashion.
<br/><a href='html/063wait.cc.html'>063wait.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_target.cc.html'>041jump_target.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/043space.cc.html'>043space.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/044space_surround.cc.html'>044space_surround.cc</a>:
Chaining spaces together to accomodate variables with varying lifetimes and
ownership properties.
<br/><a href='html/045closure_name.cc.html'>045closure_name.cc</a>: how spaces
can implement lexical scope.
<br/><a href='html/046global.cc.html'>046global.cc</a>: experimental support
for 'global' variables that are always available inside a single routine. Mu
has no variables that are available transparently across routines, and this
might go away as well. Global variables are currently not checked as
rigorously as the rest of the type system.
<br/><a href='html/047check_type_by_name.cc.html'>047check_type_by_name.cc</a>:
a simple transform to deduce missing types in instructions on the basis of
previous instructions in the same function.
<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/>Support for <em>shape-shifting</em> or generic data structures that can
contain <em>type ingredients</em>: <a href='html/053dilated_reagent.cc.html'>053dilated_reagent.cc</a>,
a new syntax for allowing whitespace in types; <a href='html/054parse_tree.cc.html'>054parse_tree.cc</a>,
a new syntax for representing complex types as trees using whitespace and
parentheses (s-expressions); <a href='html/055recipe_header.cc.html'>055recipe_header.cc</a>,
a new syntax for introducing ingredients and products with the name of a reagent;
<a href='html/056static_dispatch.cc.html'>056static_dispatch.cc</a>, allowing
multiple variants of a function to coexist with support for different headers;
<a href='html/057shape_shifting_container.cc.html'>057shape_shifting_container.cc</a>, 
a new syntax for wildcard <em>type ingredients</em> in containers; and finally
<a href='html/058shape_shifting_recipe.cc.html'>058shape_shifting_recipe.cc</a>, 
support for type ingredients in functions. Everytime you call a shape-shifting
function with a new set of types for its type ingredients, it creates a new
variant of the function for you matching those types.
<br/><a href='html/060immutable.cc.html'>060immutable.cc</a>, a static analysis to
ensure that functions never modify anything but their products.
<p/><a href='html/998check_type_pointers.cc.html'>998check_type_pointers.cc.html</a>:
After all our messing about with types, a final pass to make sure we didn't
introduce any invalid types.
<br/><a href='html/999spaces.cc.html'>999spaces.cc.html</a>: 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.

<p><b>Part IV</b>: beginnings of a standard library
<p/><a href='html/070text.mu.html'>070text.mu</a>: 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).
<br/><a href='html/064rewrite_literal_string.cc.html'>064rewrite_literal_string.cc</a>:
allow functions taking strings to also take string literals. Mu doesn't have a
global segment; string literals are allocated on the heap everytime they're
used.
<br/><a href='html/071rewrite_stash.cc.html'>071rewrite_stash.cc</a>: a
convenience when debugging is the ability to add variables to the trace using
the <span style='font-family:courier,fixed'>stash</span> command. By default
<span style='font-family:courier,fixed'>stash</span> just prints out the
locations in memory, one by one. To extend its display format specific types,
define a function called <span style='font-family:courier,fixed'>to-text</span>
with the appropriate ingredient type, returning a Mu string.
<br/><a href='html/072channel.mu.html'>072channel.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/073array.mu.html'>073array.mu</a>
<br/><a href='html/074list.mu.html'>074list.mu</a>: linked lists where each
node points to the next, permitting fast insertion/deletion but slow for
search.
<br/><a href='html/075random.cc.html'>075random.cc</a>
<br/><a href='html/076duplex_list.mu.html'>076duplex_list.mu</a>: doubly
linked lists that can be traversed both forwards and back.
<br/><a href='html/077stream.mu.html'>077stream.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/080display.cc.html'>080display.cc</a>: primitives for using
the keyboard and screen.
<br/><a href='html/081print.mu.html'>081print.mu</a>: helpers that can swap
the real screen with fake ones for testing.
<br/><a href='html/082scenario_screen.cc.html'>082scenario_screen.cc</a>:
writing tests that check what is printed to screen.
(<a href='html/083scenario_screen_test.mu.html'>examples</a>)
<br/><a href='html/084console.mu.html'>084console.mu</a>: helpers that can
swap the real keyboard and mouse with fake ones for testing.
<br/><a href='html/085scenario_console.cc.html'>085scenario_console.cc</a>:
writing tests for keyboard and mouse using the fakes.
(<a href='html/086scenario_console_test.mu.html'>examples</a>)
<br/><a href='html/090trace_browser.cc.html'>090trace_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/091run_interactive.cc.html'>091run_interactive.cc</a>:
hacky primitives for running Mu code in the programming environment below.
<br/><a href='html/092persist.cc.html'>092persist.cc</a>: more hacky
primitives for supporting saving/restoring sessions in the Mu programming
environment.

<p>Finally, the programming environment, the first major application in its
own directory. Stop loading after each of these layers to get a working
version with just fewer features. The <a href='https://github.com/akkartik/mu/blob/master/edit/Readme.md'>readme
for the app</a> contains instructions for running it.<br>

<br/><a href='html/edit/001-editor.mu.html'>edit/001-editor.mu</a>: data
structures for a simple text editor widget. Load just this layer to see just
the rendering and line-wrapping at work.
<br/><a href='html/edit/002-typing.mu.html'>edit/002-typing.mu</a>: support
for moving the cursor anywhere with the mouse and typing text in there.
<br/><a href='html/edit/003-shortcuts.mu.html'>edit/003-shortcuts.mu</a>:
support for various keyboard shortcuts for manipulating text you've typed in.
<br/><a href='html/edit/004-programming-environment.mu.html'>edit/004-programming-environment.mu</a>:
combining two text editor widgets, one on the left, one on the right.
<br/><a href='html/edit/005-sandbox.mu.html'>edit/005-sandbox.mu</a>: support
for running mu code in the right-hand widget using code from the left, and
displaying results in a <em>sandbox</em> below on the right. You can have
multiple sandboxes, and hit F4 to rerun them all at anytime with the latest
version of the code on the left side.
<br/><a href='html/edit/006-sandbox-edit.mu.html'>edit/006-sandbox-edit.mu</a>:
click on the title bar of each sandbox to pop it back into the sandbox editor
and make changes to it.
<br/><a href='html/edit/007-sandbox-delete.mu.html'>edit/007-sandbox-delete.mu</a>:
click on the 'x' in the title bar of a sandbox to delete it.
<br/><a href='html/edit/008-sandbox-test.mu.html'>edit/008-sandbox-test.mu</a>:
click on the results of a sandbox to turn them green and save the output as
golden/expected. Any future changes to the output will then be flagged in red.
<br/><a href='html/edit/009-sandbox-trace.mu.html'>edit/009-sandbox-trace.mu</a>:
click on code in a sandbox to open up a drawer containing its trace. The trace
can be added to using the <span style='font-family:courier,fixed'>stash</span>
command, which renders arbitrary data structures using <span style='font-family:courier,fixed'>to-text</span>
with the appropriate function header.
<br/><a href='html/edit/010-errors.mu.html'>edit/010-errors.mu</a>:
support for rendering errors on both the left and in each sandbox.
<br/><a href='html/edit/011-editor-undo.mu.html'>edit/011-editor-undo.mu</a>:
support for undo in the editor widget.

<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'/>