Source file func.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
open Lang
open Il
open Il.Print

(* Function *)

type t =
  | Extern of tparam list * param list * typ
  | Builtin of tparam list * param list * typ
  | Table of param list * typ * tablerow list
  | Defined of tparam list * param list * typ * clause list * elseclause option

let to_string = function
  | Extern (tparams, params, typ) ->
      "extern def " ^ string_of_tparams tparams ^ string_of_params params
      ^ " : " ^ string_of_typ typ
  | Builtin (tparams, params, typ) ->
      "builtin def " ^ string_of_tparams tparams ^ string_of_params params
      ^ " : " ^ string_of_typ typ
  | Table (params, typ, tablerows) ->
      "table def " ^ string_of_params params ^ " : " ^ string_of_typ typ
      ^ " =\n"
      ^ String.concat "\n"
          (List.map (fun clause -> string_of_tablerow clause) tablerows)
  | Defined (tparams, params, typ, clauses, elseclause_opt) ->
      "def " ^ string_of_tparams tparams ^ string_of_params params ^ " : "
      ^ string_of_typ typ ^ " =\n" ^ string_of_clauses clauses
      ^ string_of_elseclause_opt elseclause_opt