ocaml/typing/primitive.ml

60 lines
2.6 KiB
OCaml
Raw Normal View History

(***********************************************************************)
(* *)
(* Objective Caml *)
(* *)
(* 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 Q Public License version 1.0. *)
(* *)
(***********************************************************************)
(* $Id$ *)
(* Description of primitive functions *)
open Misc
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
| name :: "noalloc" :: name2 :: "float" :: _ ->
{prim_name = name; prim_arity = arity; prim_alloc = false;
prim_native_name = name2; prim_native_float = true}
| name :: "noalloc" :: name2 :: _ ->
{prim_name = name; prim_arity = arity; prim_alloc = false;
prim_native_name = name2; prim_native_float = false}
| name :: name2 :: "float" :: _ ->
{prim_name = name; prim_arity = arity; prim_alloc = true;
prim_native_name = name2; prim_native_float = true}
| name :: "noalloc" :: _ ->
{prim_name = name; prim_arity = arity; prim_alloc = false;
prim_native_name = ""; prim_native_float = false}
| name :: name2 :: _ ->
{prim_name = name; prim_arity = arity; prim_alloc = true;
prim_native_name = name2; prim_native_float = false}
| name :: _ ->
{prim_name = name; prim_arity = arity; prim_alloc = true;
prim_native_name = ""; prim_native_float = false}
| [] ->
fatal_error "Primitive.parse_declaration"
open Format;;
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";
if p.prim_native_name <> "" then
fprintf ppf "@ %a" print_quoted p.prim_native_name;
if p.prim_native_float then
fprintf ppf "@ %a" print_quoted "float"