Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Xavier Leroy <Xavier.Leroy@inria.fr>
To: Tom <tom.primozic@gmail.com>
Cc: skaller <skaller@users.sourceforge.net>,
	Caml List <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] Function application implementation
Date: Thu, 26 Apr 2007 11:25:00 +0200	[thread overview]
Message-ID: <46306FEC.7010201@inria.fr> (raw)
In-Reply-To: <c1490a380704260152h34df93e9p20decd2f13459bbe@mail.gmail.com>

>     It knows the type of the function expression, and that is all
>     that is required. Incidentally Ocaml evaluates right to left. So
>
>             f x y z
>
>     will be roughly:
>
>             push (eval z)
>             push (eval y)
>             push (eval x)
>             push (eval f)
>             apply
>             apply
>             apply
>
>
> But that doesn't explain how does each apply know what to do, either to
> build a new closure (in the case above, the first two applies) or to
> actually call the code (the third apply).

The generated abstract machine code is more like:
             push (eval z)
             push (eval y)
             push (eval x)
             push (eval f)
             apply 3        (*  number of arguments provided *)

"apply" doesn't do anything clever, it just enters the code of the
called function f.  It's the code of f that determines what to do
with the arguments provided on the stack.

More details can be found in one of my talks:
http://gallium.inria.fr/~xleroy/talks/zam-kazam05.pdf

- Xavier Leroy


      parent reply	other threads:[~2007-04-26  9:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-25 22:38 Tom
2007-04-26  3:13 ` [Caml-list] " skaller
2007-04-26  8:52   ` Tom
2007-04-26  9:17     ` skaller
2007-04-26  9:25     ` Xavier Leroy [this message]

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=46306FEC.7010201@inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=caml-list@yquem.inria.fr \
    --cc=skaller@users.sourceforge.net \
    --cc=tom.primozic@gmail.com \
    /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