1995-08-09 08:06:35 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Objective Caml *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07:00
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* $Id$ *)
|
|
|
|
|
1995-07-27 10:47:52 -07:00
|
|
|
(* Description of primitive functions *)
|
|
|
|
|
1997-05-13 07:07:00 -07:00
|
|
|
open Misc
|
1995-07-27 10:47:52 -07:00
|
|
|
|
|
|
|
type description =
|
|
|
|
{ prim_name: string; (* Name of primitive or C function *)
|
|
|
|
prim_arity: int; (* Number of arguments *)
|
|
|
|
prim_alloc: bool; (* Does it allocates or raise? *)
|
|
|
|
prim_native_name: string; (* Name of C function for the nat. code gen. *)
|
|
|
|
prim_native_float: bool } (* Does the above operate on unboxed floats? *)
|
|
|
|
|
|
|
|
let parse_declaration arity decl =
|
|
|
|
match decl with
|
2000-03-13 08:49:01 -08:00
|
|
|
| name :: "noalloc" :: name2 :: "float" :: _ ->
|
1997-05-13 07:07:00 -07:00
|
|
|
{prim_name = name; prim_arity = arity; prim_alloc = false;
|
|
|
|
prim_native_name = name2; prim_native_float = true}
|
1995-07-27 10:47:52 -07:00
|
|
|
| name :: "noalloc" :: name2 :: _ ->
|
1997-05-13 07:07:00 -07:00
|
|
|
{prim_name = name; prim_arity = arity; prim_alloc = false;
|
|
|
|
prim_native_name = name2; prim_native_float = false}
|
1995-07-27 10:47:52 -07:00
|
|
|
| name :: name2 :: "float" :: _ ->
|
1997-05-13 07:07:00 -07:00
|
|
|
{prim_name = name; prim_arity = arity; prim_alloc = true;
|
|
|
|
prim_native_name = name2; prim_native_float = true}
|
1995-07-27 10:47:52 -07:00
|
|
|
| name :: "noalloc" :: _ ->
|
1997-05-13 07:07:00 -07:00
|
|
|
{prim_name = name; prim_arity = arity; prim_alloc = false;
|
|
|
|
prim_native_name = ""; prim_native_float = false}
|
1995-07-27 10:47:52 -07:00
|
|
|
| name :: name2 :: _ ->
|
1997-05-13 07:07:00 -07:00
|
|
|
{prim_name = name; prim_arity = arity; prim_alloc = true;
|
|
|
|
prim_native_name = name2; prim_native_float = false}
|
1995-07-27 10:47:52 -07:00
|
|
|
| name :: _ ->
|
1997-05-13 07:07:00 -07:00
|
|
|
{prim_name = name; prim_arity = arity; prim_alloc = true;
|
|
|
|
prim_native_name = ""; prim_native_float = false}
|
1995-07-27 10:47:52 -07:00
|
|
|
| [] ->
|
1997-05-13 07:07:00 -07:00
|
|
|
fatal_error "Primitive.parse_declaration"
|
1995-07-27 10:47:52 -07:00
|
|
|
|
2000-03-13 08:49:01 -08:00
|
|
|
open Format;;
|
1995-07-27 10:47:52 -07:00
|
|
|
|
2000-03-13 08:49:01 -08:00
|
|
|
let print_quoted ppf s = fprintf ppf "\"%s\"" s
|
|
|
|
|
|
|
|
let print_description ppf p =
|
|
|
|
print_quoted ppf p.prim_name;
|
|
|
|
if not p.prim_alloc then fprintf ppf "@ %a" print_quoted "noalloc";
|
1995-07-27 10:47:52 -07:00
|
|
|
if p.prim_native_name <> "" then
|
2000-03-13 08:49:01 -08:00
|
|
|
fprintf ppf "@ %a" print_quoted p.prim_native_name;
|
1995-07-27 10:47:52 -07:00
|
|
|
if p.prim_native_float then
|
2000-03-13 08:49:01 -08:00
|
|
|
fprintf ppf "@ %a" print_quoted "float"
|