Compiler Construction 2015
Computer Laboratory 
University of Cambridge 
Timothy G. Griffin (tgg22@cam.ac.uk) 

This directory contains Ocaml code implementing 
high-level interpreters for version 2 of the language 
Slang ( = Simple LANGuage).  

===============================================
Building 
===============================================

  ocamlbuild slang.byte 

This will build the executable slang.byte as 
well as a directory _build of compiled code. 

===============================================
Files
===============================================

Every .ml file has an associated .mli file 
describing its interface. 

common.ml      : some commonly used datatypes and functions 
past.ml        : the parsed AST 
ast.ml         : "internal" AST 
pp_past.ml     : pretty printing for parsed AST 
pp_ast.ml      : pretty printing for internal AST 
static.ml      : static analysis (check types and other rules) 
past_to_ast.ml : translated from parsed to internal AST 
alpha.ml       : "alpha convert" 
front_end.ml   : the front end : parse, static check, translate, alpha convert. 
free_vars.ml   : free variable calculation 
tests.ml       : code for parsing tests/manifest.txt and setting up testing. 
slang.ml       : main file, implementing the command-line for the interpreter and compiler 

Lexing and parsing : 
lexer.mll      : specification for ocamllex 
parser.mly     : specification for ocamlyacc 

interp_0.ml : The "definitional" Interpreter 0
interp_1.ml : cps(Interpreter 0)
interp_2.ml : dfc(Interpreter 1)
interp_3.ml : stackify(Interpreter 2)
interp_4.ml : split stacks of Interpreter 3  into three
interp_5.ml : refactor(Interpreter 4) into compiler and interpreter 

Now we are "stuck" if we want to end up with a jargon-like VM, since 
Interpreter 5 has a stack of environments and a stack of values that we 
would somehow have to put back together into a single stack. 

Instead, we go back to Interpreter 3 and start over. 

interp_6.ml : we first defunctionalize environments (finally!) 
interp_7.ml : split stacks of Interpreter 3  into *two* 
interp_8.ml : refactor(Interpreter 7) into compiler and interpreter 
interp_9.ml : make code linear (with numeric addresses) 


               
