Skip to content

Pirobi/Min-C

Repository files navigation

An educational compiler for a minimal subset of OCaml, written in
~2000 lines of OCaml.  For details, see:

http://esumii.github.io/min-caml/ (Japanese Web page)
http://esumii.github.io/min-caml/jpaper.pdf (Japanese academic paper)
http://esumii.github.io/min-caml/index-e.html (English Web page)
http://esumii.github.io/min-caml/paper.pdf (English academic paper)

1. Install OCaml (http://caml.inria.fr/) if you haven't

2. Download (and expand) MinCaml, e.g.
   git clone https://github.com/esumii/min-caml.git

3. cd min-caml/

4. Execute ./to_x86 for x86
   (or ./to_sparc for SPARC, ./to_ppc for PowerPC)

5. make

6. If you like, try the ray tracer

     cd min-rt/ ; make

   though it takes time because of OCaml bytecode (for testing by
   comparison), not MinCaml

#############################################################################################################
Translator from MinCaml to C, written in OCaml.

This translator will take source code written in MinCaml and translate into C code. The translated C code can 
then be compiled and run or further modified.

To run the translator:

1. Follow the above steps to install MinCaml

2. cd /min-caml/

3. make test/*.ml.c
   - This will read the .ml file in the test folder and output a translated .ml.c file in the same folder.
   - You can put any typed code into the test folder and translate it in this way

4. Translated code can be edited and modified to fit your program. Please use helper functions/structs
   Found in /translation/: csyntax.c and csyntax.h

5. Any external variables/functions defined by you must be placed into a seperate C file. The translator
   Will automatically determine external variables. A future update will make the translator automatically
   determine external functions.

6. Use gcc or another compiler to compile the translated code. 
   - You MUST include translation/csyntax.c and any files containing external variables/functions when compiling.

To run ray tracer translations:

1. cd min-rt/

2. make min-rt.ml.c

3. make *.min-c.ppm
   - Where * = the name of the .sld file you with to generate, which must be stored in the min-rt folder
###############################################################################################################

[Updates on August 17, 2015]

- Added ability to translate min-caml source code into C.

[Updates on October 9, 2013]

- Moved from SourceForge https://sourceforge.net/p/min-caml/code/ to
  GitHub https://github.com/esumii/min-caml

- Merged the Mac OS patch by shinh
  https://twitter.com/shinh/status/322043108021907458

[Update on July 24, 2012]

- 32-bit x86 (with SSE2, that is, Pentium IV or later) is now
  supported (on Linux and Cygwin); execute ./to_x86 before make.

[Updates on September 17, 2008]

- PowerPC is now supported (in addition to SPARC), thanks to
  Ms. Masuko and Prof. Asai in Ochanomizu University.  You _must_
  execute either ./to_ppc or ./to_sparc _before_ make.

- The register allocator now uses a simpler algorithm.  It omits the
  backtracking (ToSpill and NoSpill) in previous versions.