caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Announce: Nativize 0.1
@ 2004-03-08  9:11 Issac Trotts
       [not found] ` <Pine.LNX.4.44.0403082258090.6523-100000@lcmpc4.epfl.ch>
  0 siblings, 1 reply; 2+ messages in thread
From: Issac Trotts @ 2004-03-08  9:11 UTC (permalink / raw)
  To: caml-list

Nativize : Compile and run native functions from the toplevel.

http://redwood.ucdavis.edu/~issac/software/nativize-0.1.tar.gz

Introduction
============
  It is useful to be able to easily run native code from the toplevel.
  Nativize makes this possible for functions whose arguments and return
  values can be serialized using the functions in OCaml's Marshal
  module.

Example: running Ackermann's function in the toplevel
=====================================================

# #require "nativize";;
Loading /usr/lib/ocaml/3.07/nativize/nativize.cma
# Nativize.nativize "Ack1" "
  let rec ack m n =
      if m = 0 then n + 1
      else if n = 0 then ack (m - 1) 1
      else ack (m - 1) (ack m (n - 1));;
  " [];;
Please type #load "Ack1.cmo";;
- : unit = ()
# #load "Ack1.cmo";;
# assert(Ack1.ack 5 0 = 65533);; (* Wait about 10 seconds. *)
- : unit = ()
# let rec ack m n =
      if m = 0 then n + 1
      else if n = 0 then ack (m - 1) 1
      else ack (m - 1) (ack m (n - 1));;
# ack 5 0;;  (* Wait a good while longer. *)

-- 
Issac Trotts
http://redwood.ucdavis.edu/~issac

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] Announce: Nativize 0.1
       [not found] ` <Pine.LNX.4.44.0403082258090.6523-100000@lcmpc4.epfl.ch>
@ 2004-03-08 23:29   ` Issac Trotts
  0 siblings, 0 replies; 2+ messages in thread
From: Issac Trotts @ 2004-03-08 23:29 UTC (permalink / raw)
  To: caml-list; +Cc: Henri DF

On Mon, Mar 08, 2004 at 10:59:12PM +0100, Henri DF wrote:
> sounds cool!!
> just wondering , reading through your example below:
> why wouldn't you spit out a "Ack1.cmx", if this is native code?

Well, I do something like that behind the scenes, but I can't just load
a .cmx file directly into the toplevel.  Instead, I compile a native
code program named Ack1 whose purpose is to evaluate the Ackermann
function.  It takes three arguments, the first two being the names of
temporary files holding marshalled arguments, the last one being the
name of a temporary file where it should store its answer in marshalled
form.  The code in Ack1.cmo marshalls the arguments (5 and 0 in the case
below) into these temporary files, calls the Ack1 program on the temp
files, reads the answer from the result file and then returns it.  

-- 
Issac Trotts
http://redwood.ucdavis.edu/~issac

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-03-08 23:30 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-08  9:11 [Caml-list] Announce: Nativize 0.1 Issac Trotts
     [not found] ` <Pine.LNX.4.44.0403082258090.6523-100000@lcmpc4.epfl.ch>
2004-03-08 23:29   ` Issac Trotts

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).