Commits

Anonymous committed f3f5e63

Creation du module primitive

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@160f963ae5c-01c2-4b8c-9fe0-0dff7051ff02

Comments (0)

Files changed (2)

typing/primitive.ml

+(* Description of primitive functions *)
+
+open Format
+
+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" :: _ ->
+      Some{prim_name = name; prim_arity = arity; prim_alloc = false;
+           prim_native_name = name2; prim_native_float = true}
+  | name :: "noalloc" :: name2 :: _ ->
+      Some{prim_name = name; prim_arity = arity; prim_alloc = false;
+           prim_native_name = name2; prim_native_float = false}
+  | name :: name2 :: "float" :: _ ->
+      Some{prim_name = name; prim_arity = arity; prim_alloc = true;
+           prim_native_name = name2; prim_native_float = true}
+  | name :: "noalloc" :: _ ->
+      Some{prim_name = name; prim_arity = arity; prim_alloc = false;
+           prim_native_name = ""; prim_native_float = false}
+  | name :: name2 :: _ ->
+      Some{prim_name = name; prim_arity = arity; prim_alloc = true;
+           prim_native_name = name2; prim_native_float = false}
+  | name :: _ ->
+      Some{prim_name = name; prim_arity = arity; prim_alloc = true;
+           prim_native_name = ""; prim_native_float = false}
+  | [] ->
+      None
+
+let print_quoted s = print_char '"'; print_string s; print_char '"'
+
+let print_description p =
+  print_quoted p.prim_name;
+  if not p.prim_alloc then
+    (print_space(); print_quoted "noalloc");
+  if p.prim_native_name <> "" then
+    (print_space(); print_quoted p.prim_native_name);
+  if p.prim_native_float then
+    (print_space(); print_quoted "float")

typing/primitive.mli

+(* Description of primitive functions *)
+
+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? *)
+
+val parse_declaration: int -> string list -> description option
+val print_description: description -> unit