From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id CE504BC0A for ; Thu, 26 Apr 2007 11:25:12 +0200 (CEST) Received: from [128.93.11.95] (estephe.inria.fr [128.93.11.95]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l3Q9P02R024472; Thu, 26 Apr 2007 11:25:00 +0200 Message-ID: <46306FEC.7010201@inria.fr> Date: Thu, 26 Apr 2007 11:25:00 +0200 From: Xavier Leroy User-Agent: Thunderbird 1.5.0.7 (X11/20060915) MIME-Version: 1.0 To: Tom Cc: skaller , Caml List Subject: Re: [Caml-list] Function application implementation References: <1177557207.8088.27.camel@rosella.wigram> In-Reply-To: X-Enigmail-Version: 0.94.0.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 46306FEC.002 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml:01 stack:01 05.:98 abstract:01 caml-list:01 xleroy:01 closure:01 expression:02 evaluates:02 talks:03 talks:03 generated:05 xavier:06 xavier:06 inria:06 > 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