diff options
| author | Pierre-Marie Pédrot | 2017-09-26 22:47:09 +0200 |
|---|---|---|
| committer | Pierre-Marie Pédrot | 2017-09-30 14:42:41 +0200 |
| commit | 5d208a8e1d46a57d3428ed43c195d193fc6c5b67 (patch) | |
| tree | 3ff365fe23280081c2cf0858b7bd08cea066655c /src/tac2ffi.ml | |
| parent | 940da8a791b8b1c704f28662fa2e6a8f3ddf040f (diff) | |
Abstracting away the primitive functions on valexpr datatype.
Diffstat (limited to 'src/tac2ffi.ml')
| -rw-r--r-- | src/tac2ffi.ml | 50 |
1 files changed, 48 insertions, 2 deletions
diff --git a/src/tac2ffi.ml b/src/tac2ffi.ml index 5460643bb5..7960d4d45f 100644 --- a/src/tac2ffi.ml +++ b/src/tac2ffi.ml @@ -41,6 +41,35 @@ type 'a arity = (valexpr, 'a) arity0 let mk_closure arity f = MLTactic (arity, f) +module Valexpr = +struct + +type t = valexpr + +let is_int = function +| ValInt _ -> true +| ValBlk _ | ValStr _ | ValCls _ | ValOpn _ | ValExt _ -> false + +let tag v = match v with +| ValBlk (n, _) -> n +| ValInt _ | ValStr _ | ValCls _ | ValOpn _ | ValExt _ -> + CErrors.anomaly (Pp.str "Unexpected value shape") + +let field v n = match v with +| ValBlk (_, v) -> v.(n) +| ValInt _ | ValStr _ | ValCls _ | ValOpn _ | ValExt _ -> + CErrors.anomaly (Pp.str "Unexpected value shape") + +let set_field v n w = match v with +| ValBlk (_, v) -> v.(n) <- w +| ValInt _ | ValStr _ | ValCls _ | ValOpn _ | ValExt _ -> + CErrors.anomaly (Pp.str "Unexpected value shape") + +let make_block tag v = ValBlk (tag, v) +let make_int n = ValInt n + +end + type 'a repr = { r_of : 'a -> valexpr; r_to : valexpr -> 'a; @@ -251,9 +280,26 @@ let array r = { r_id = false; } +let of_block (n, args) = ValBlk (n, args) +let to_block = function +| ValBlk (n, args) -> (n, args) +| _ -> assert false + let block = { - r_of = of_tuple; - r_to = to_tuple; + r_of = of_block; + r_to = to_block; + r_id = false; +} + +let of_open (kn, args) = ValOpn (kn, args) + +let to_open = function +| ValOpn (kn, args) -> (kn, args) +| _ -> assert false + +let open_ = { + r_of = of_open; + r_to = to_open; r_id = false; } |
