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.4 required=5.0 tests=AWL,DNS_FROM_RFC_ABUSE autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 8CDD1BC6B for ; Sat, 18 Aug 2007 09:42:50 +0200 (CEST) Received: from rabbit.math.nagoya-u.ac.jp (rabbit.math.nagoya-u.ac.jp [133.6.130.5]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l7I7gmvm026343 for ; Sat, 18 Aug 2007 09:42:49 +0200 Received: from localhost (rabbit-172 [172.16.254.254]) by rabbit.math.nagoya-u.ac.jp (8.12.11/3.7W) with ESMTP id l7I7geOV014336; Sat, 18 Aug 2007 16:42:40 +0900 (JST) Date: Sat, 18 Aug 2007 16:42:40 +0900 (JST) Message-Id: <20070818.164240.2004159589.garrigue@math.nagoya-u.ac.jp> To: joelr1@gmail.com Cc: caml-list@inria.fr Subject: Re: [Caml-list] What is a match statement translated into? From: Jacques GARRIGUE In-Reply-To: <1A6B8F53-FDA5-4F37-BA08-1FBD9CF09E7B@gmail.com> References: <1A6B8F53-FDA5-4F37-BA08-1FBD9CF09E7B@gmail.com> X-Mailer: Mew version 4.2 on Emacs 21.4 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at discorde with ID 46C6A2F8.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; translated:01 ocaml:01 computed:01 branching:01 compilation:01 compiler:01 ocaml:01 compiler:01 matched:01 caml-list:01 data:02 match:02 assembler:02 garrigue:03 garrigue:03 From: Joel Reymont > Is pattern-matching code in OCaml expanded into threaded code (pre- > computed branch table) or something analogous to the C switch > statement (lots of branching)? I do not understand your description of C compilation: this certainly depends a lot on the compiler and the optimization level. OCaml does different things according to the data matched, using a table when it is compact enough, or branches otherwise. So there is no uniform answer, just that it is rather optimized. > How do I find out? > > I suspect this should be quite optimized but I haven't tried dumping > disassembling native-compiled OCaml yet and I wonder if there's a > simpler approach. No need to disassemble: you can just dump the assembler with the -S flag. And this is probably the most instructive approach, as the compiler itself is quite involved. Jacques Garrigue