package p4spectec

  1. Overview
  2. Docs
P4-SpecTec: A mechanization toolchain for the P4 Programming Language

Install

dune-project
 Dependency

Authors

Maintainers

Sources

v0.1.2.tar.gz
md5=1a3bc0a385fe1ecf403c019f49aa6de6
sha512=5d20b5821f33e2a3a5419b208606f27c01511994c2b3b1e1cdf4c077056dfd0aa81682af0720e1060ee2bfb0341918fcc4c53159820205a2bc32b725e5c1a714

doc/src/type/typ.ml.html

Source file typ.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
open Lang
open Xl
open Il
open Il.Print
open Util.Source

(* Type *)

type t = typ

let to_string t = string_of_typ t

(* Constructor *)

module Make = struct
  let rec iterate (typ : t) (iters : iter list) : t =
    match iters with
    | [] -> typ
    | iter :: iters -> iterate (IterT (typ, iter) $ typ.at) iters

  let bool' : typ' = BoolT
  let bool : typ = bool' $ no_region
  let nat' : typ' = NumT `NatT
  let nat : typ = nat' $ no_region
  let int' : typ' = NumT `IntT
  let int : typ = int' $ no_region
  let num' (numtyp : Num.typ) : typ' = NumT numtyp
  let num (numtyp : Num.typ) : typ = num' numtyp $ no_region
  let text' : typ' = TextT
  let text : typ = text' $ no_region
  let var' (id : id) (targs : targ list) : typ' = VarT (id, targs)
  let var (id : id) (targs : targ list) : typ = var' id targs $ no_region
  let tuple' (typs : typ list) : typ' = TupleT typs
  let tuple (typs : typ list) : typ = tuple' typs $ no_region
  let iter' (typ : typ) (it : iter) : typ' = IterT (typ, it)
  let iter (typ : typ) (it : iter) : typ = iter' typ it $ no_region
  let opt' (typ : typ) : typ' = iter' typ Opt
  let opt (typ : typ) : typ = iter typ Opt
  let list' (typ : typ) : typ' = iter' typ List
  let list (typ : typ) : typ = iter typ List

  let func' (tparams : tparam list) (typs_params : typ list) (typ : typ) : typ'
      =
    FuncT (tparams, typs_params, typ)

  let func (tparams : tparam list) (typs_params : typ list) (typ : typ) : typ =
    func' tparams typs_params typ $ no_region

  let rec of_param_il (param : Il.param) : t =
    match param.it with
    | ExpP typ -> typ
    | DefP (_, tparams, params, typ) ->
        let typs_params = of_params_il params in
        func tparams typs_params typ

  and of_params_il (params : Il.param list) : t list =
    List.map of_param_il params

  let rec of_param_sl (param : Sl.param) : t =
    match param.it with
    | ExpP (typ, _) -> typ
    | DefP (_, tparams, params, typ) ->
        let typs_params = of_params_sl params in
        func tparams typs_params typ

  and of_params_sl (params : Sl.param list) : t list =
    List.map of_param_sl params

  let rec of_param_pl (param : Pl.param) : t =
    match param.it with
    | ExpP (typ, _) -> typ
    | DefP (_, tparams, params, typ) ->
        let typs_params = of_params_pl params in
        func tparams typs_params typ

  and of_params_pl (params : Pl.param list) : t list =
    List.map of_param_pl params
end