Start of topic | Skip to actions

Requirements:

  • Python 2.4 or above (for the parser)
  • OCaml 3.09 or above: Compile the OCaml compiler with the 'make opt.opt' command to generate native-code versions of all the compilation tools (Read OCaml compilation instructions for details)
  • OCaml ExtLib library
  • OCaml findlib package manager

Usage instructions:

1) Compiling the translator and the runtime environment

  • Edit the relevant part of the toplevel Makefile to set paths. Then type 'make' followed by 'make install'
  • This should result in the creation and installation of 3 different things:
    • py2ocaml: The translator from Python to OCaml
    • pyenv.cma, pyyenv.cmxa: bytecode and native OCaml library for the runtime environment
    • libmontyffi.a: C library containing the OCaml/Python Foreign function interface

2) Compiling a Python program to OCaml bytecode/native code

Let your valid Python program be called 'foo.py'. There are 2 steps to translation to an OCaml executable

  • py2ocaml foo: This step produces an OCaml file called foo.ml
  • In order to compile foo.ml to an executable use the following (make a shell alias)
    • For native code: ocamlopt.opt -inline 100 -thread str.cmxa nums.cmxa unix.cmxa threads.cmxa extLib.cmxa pyenv.cmxa -o foo foo.ml
    • For byte-code (useful for debugging): ocamlc.opt -thread str.cma nums.cma unix.cma threads.cma extLib.cma pyenv.cma -o foo foo.ml

-- Main.RajB - 15 Dec 2007


End of topic
Skip to actions | Back to top
Creative Commons LicenseThis work is licensed under a Creative Commons Attribution 2.5 License. Please follow our citation guidelines.