I was a compiler writer • wrote compilers at student experiment • minCaml compiler by O’Caml • minCaml compiler by Haskell https://github.com/nineties/Choco • studied optimizing compilers at graduate school • wrote compilers for special purpose CPUs
Strategy:Bootstrapping Write language 1 by assembly language Write a little bit high-level language 2 by language 1 Write Amber by language k Write Amber by Amber here now
What’s the point? • For fun. • To cultivate knowledge, techniques, know-hows of compiler-writing. • But it’s not cost-effective study method... • To feel a sense of gratitude and respect for predecessors.
Generates codes together with parsing • writing memory management is difficult here. • generates codes without building syntax trees. code generation parsing
Completed the first language “rowl0”! • no symbol tables. • function params must be p0,p1,p2,... • to use local variables, allocate stack mems by “allocate(n)” then use x0,x1,x2,...
No memory management • mmap and munmap is the only function 1. Does not recovery garbage memories 2. Allocates fresh memories for new objects 3. So, it will die eventually • When it can compile the next generation compilers, it’s no problem. malloc, free
Decided to create a VM for the next generation • Created a language just for writing the virtual machine. • Defined it as a DSL in the LISP “rowl-core” • No need of writing lexer and parser!
Generates various codes from the table • reflects changes of instructions automatically • It is very easy to make this kind of mechanism with LISP vm_instructions eval loop of the VM Linker Disassembler Assembler Assembler used internally in Amber
There was no programming tools for “rlvm” • Created a tool chain for the VM • a programming language “rowl1” • its compiler • assembler • disassembler • linker
Wrote an assembler • The former assembler assembles codes ahead of time and run on rlci • This assembler assembles codes just in time and run on rlvm • fills addresses by backpatching
Wrote the compiler • Made Amber compiler as one of Amber objects VM object system pattern-matching engine compiler Amber’s core system matching of syntax tree resource management
Wrote parsers • compiles parsers at run-time • each parser is a usual Amber object (closure) VM object system pattern-matching engine compiler Amber core system compile parsers
very simple syntax 1. literals are expressions 2. for a symbol h and expressions e1,..,en (n>=0), h{e1, ..., en} is an expression 3. no other form of Amber’s expression
Encoding/decoding floating-point literal was difficult • wrote them by my self because of “no libc” limitation • require multi-precision integer arithmetic which I wrote before “3.14” 0x40091eb851eb851f strtod, sprintf
Amber interpreter is completed! • dynamic scripting language • run on rlvm • instance-based object oriented system • dynamic pattern-matching engine • partial function fusion • lexical closure • I got modern programming language!
Amber has strong self extensibility • Amber’s simple syntax is extended in a standard library • amber/lib/syntax/parse.ab • Builds its syntax during boot sequence
Now the development is under suspension • No plans of further updates • Try following commands to invoke Amber shell (Linux only) • See the outputs of the make command % git clone https://github.com/nineties/amber.git % cd amber % make; sudo make install % amber
Summary rowl0 rlc rlci rowl-core as lang. for writing VM rlvm rowl1 linker disassembler compiler compiler Amber interpreter impl. impl. run self-extension language tool • I could reach relatively high-level language. Feel satisfied.