|
|
|
|
|
by shoo
2705 days ago
|
|
Graydon Hoare's "One-Day Compilers" presentation: http://www.venge.net/graydon/talks/mkc/html/mgp00001.html > goal: translate subset of makefile syntax into native executables
result: pipeline to compile subset of makefile syntax into native executables, in less than 400 lines of code
> including
> * lexing and parsing
> * variable binding
> * type checking
> * error reporting
> * native code generation
- use custom camlp4 pre processor
- define Ocaml types and functions to model things found in input makefile (variable, rules, dependencies). leverage Ocaml semantics
- parse input simple makefile language
- map parsed input into AST for Ocaml functions defined earlier
- use ocaml's quotation machinery to define ocaml AST values from standard ocaml syntax, without building AST values by hand
- bundle everything into an ocaml program
- ocaml program produces single ocaml value that models the input program described by makefile
- translate ocaml value into C code:
- generate C code from templated quotations, again using ocaml quotation support, but for C language, not ocaml
- compile generated C code with gcc
- glue everything together into one pipeline
|
|