(* TEST readonly_files = "main.c"; arguments = "-DSORT -DFUN=quicksort main.c"; asmgen; *) (**************************************************************************) (* *) (* OCaml *) (* *) (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) (* *) (* Copyright 1996 Institut National de Recherche en Informatique et *) (* en Automatique. *) (* *) (* All rights reserved. This file is distributed under the terms of *) (* the GNU Lesser General Public License version 2.1, with the *) (* special exception on linking described in the file LICENSE. *) (* *) (**************************************************************************) (function "cmp" (i: int j: int) (- i j)) (function "quick" (lo: int hi: int a: val cmp: val) (if (< lo hi) (letmut (i int lo j int hi pivot int (intaref a hi)) (while (< i j) (catch (while 1 (if (>= i hi) (exit n25) []) (if (> (app cmp (intaref a i) pivot int) 0) (exit n25) []) (assign i (+ i 1))) with (n25) []) (catch (while 1 (if (<= j lo) (exit n35) []) (if (< (app cmp (intaref a j) pivot int) 0) (exit n35) []) (assign j (- j 1))) with (n35) []) (if (< i j) (let temp (intaref a i) (intaset a i (intaref a j)) (intaset a j temp)) [])) (let temp (intaref a i) (intaset a i (intaref a hi)) (intaset a hi temp)) (app "quick" lo (- i 1) a cmp unit) (app "quick" (+ i 1) hi a cmp unit)) [])) (function "quicksort" (lo: int hi: int a: val) (app "quick" lo hi a "cmp" unit))