Building on Mac
git clone https://github.com/esumii/min-caml.git
cd min-caml
./to_x86
make min-caml
For IS people: The above procedure works on Macs at IS computer room, West-7 building.
I think it also works on Linux and “Bash on Ubuntu on Windows”.
Building on classic Windows
If you are a Windows user and still unable to upgrade your Windows to recent edition (Anniversary edition or Community edition):
Install Cygwin
Install gcc-core
, make
, and ocaml
using cygwin setup tool.
Follow the same procedure.
A Healthy Build Log
☁ min-caml make min-caml
ocamllex lexer.mll
82 states, 2498 transitions, table size 10484 bytes
ocamlyacc parser.mly
...
ocamlc -c -cc "gcc" -ccopt "-g -O2 -Wall -o float.o " float.c ocamlc \
float.o -custom -g -warn-error -31 -o min-caml \
...
File "parser.cmo", line 1:
Warning 31: files parser.cmo and /usr/local/lib/ocaml/compiler-libs/ocamlcommon.cma(Parser) both define a module named Parser
File "lexer.cmo", line 1:
Warning 31: files lexer.cmo and /usr/local/lib/ocaml/compiler-libs/ocamlcommon.cma(Lexer) both define a module named Lexer
The Build Result
☁ min-caml ls -F
LICENSE constFold.cmi lexer.cmo simm.cmi
Makefile constFold.cmo lexer.ml simm.cmo
OCamlMakefile constFold.ml lexer.mll simm.ml
...
anchor.ml emit.ml main.mli to_sparc*
asm.cmi emit.mli min-caml* to_x86*
asm.cmo fdpe05.ppt min-caml.top* tutorial-mincaml.doc
asm.ml float.c min-rt/ tutorial-ml.doc
...
Many files added. Among them is the min-caml
compiler. The ls -F
command puts *
marks after the names of executable files.
Min-Caml Command Line Arguments
☁ min-caml ./min-caml --help
Mitou Min-Caml Compiler (C) Eijiro Sumii
usage: ./min-caml [-inline m] [-iter n] ...filenames without ".ml"...
-inline maximum size of functions inlined
-iter maximum number of optimizations iterated
-help Display this list of options
--help Display this list of options
Compiling fib.ml
with Min-Caml
☁ kw pwd; ls -F
/Users/wakita/Dropbox/projects/fp/min-caml/fp04b
fib.ml
☁ kw ../min-caml fib
free variable print_int assumed as external
free variable print_newline assumed as external
iteration 1000
iteration 999
directly applying fib.17
directly applying fib.17
directly applying loop.19
directly applying fib.17
directly applying loop.19
eliminating closure(s) loop.19
eliminating closure(s) fib.17
register allocation: may take some time (up to a few minutes, depending on the size of functions)
generating assembly...
☁ kw ls -F
fib.ml fib.s
Linking fib
Using a C Compiler
☁ kw clang -m32 -O2 -Wall fib.s ../libmincaml.S ../stub.c -lm -o fib
ld: warning: PIE disabled. Absolute addressing (perhaps -mdynamic-no-pic) not allowed in code signed PIE, but used in _min_caml_start from /var/folders/6l/z36pjysn4zx7hpfzmcfv4xqh0000gn/T/fib-fd883b.o. To fix this warning, don't compile with -mdynamic-no-pic or link with -Wl,-no_pie
☁ kw ls -FC
fib* fib.ml fib.s
Use the standard C compiler on your platform. The above example uses clang
: the standard on macOS. Users of other platforms may want to use other compilers, like gcc
, icc
.
Running fib
☁ kw ./fib
sp = 0xbff0afc0, hp = 0x200000
1346269
1346269
1346269
1346269
1346269
...
1346269
1346269
1346269