From: Jon Harrop <jon@ffconsultancy.com>
To: caml-list@yquem.inria.fr
Subject: New HLVM examples!
Date: Wed, 24 Jun 2009 14:23:27 +0100 [thread overview]
Message-ID: <200906241423.27628.jon@ffconsultancy.com> (raw)
The HLVM project now includes two examples: a calculator and a tiny compiler:
http://forge.ocamlcore.org/projects/hlvm/
The design and implementation of the compiler are described in detail in the
latest OCaml Journal article:
http://ocamlnews.blogspot.com/2009/06/compiler-development-part-1.html
The compiler can execute the following OCaml-like program to print the
Mandelbrot set:
# let rec pixel((n, zr, zi, cr, ci) : int * float * float * float * float) :
unit =
if n = 65536 then print_char ' ' else
if zr * zr + zi * zi >= 4.0 then print_char '.' else
pixel(n+1, zr * zr - zi * zi + cr, 2.0 * zr * zi + ci, cr, ci);;
# let rec row((i, j, n) : int * int * int) : unit =
if i>n then () else
begin
let cr = 2.0 * float_of_int i / float_of_int n - 1.5 in
let ci = 2.0 * float_of_int j / float_of_int n - 1.0 in
pixel(0, 0.0, 0.0, cr, ci);
row(i+1, j, n)
end;;
# let rec col((j, n) : int * int) : unit =
if j>n then () else
begin
row(0, j, n);
print_char '\n';
col(j+1, n)
end;;
# let rec mandelbrot(n : int) : unit =
col(0, n);;
# mandelbrot 77;;
In particular, our compiler runs this program interactively 50x faster than
the OCaml top-level and 60% faster than native-code compiled OCaml!
Check out HLVM's SVN repository including these examples with:
svn checkout svn://svn.forge.ocamlcore.org/svnroot/hlvm
--
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e
reply other threads:[~2009-06-24 12:14 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200906241423.27628.jon@ffconsultancy.com \
--to=jon@ffconsultancy.com \
--cc=caml-list@yquem.inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox