File: nested_mapping.sail

package info (click to toggle)
sail-ocaml 0.19.1%2Bdfsg5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,008 kB
  • sloc: ml: 75,941; ansic: 8,848; python: 1,342; exp: 560; sh: 474; makefile: 218; cpp: 36
file content (38 lines) | stat: -rw-r--r-- 531 bytes parent folder | download
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
default Order dec

$include <prelude.sail>

enum E1 = {A1, B1}

enum E2 = {A2, B2}

val m1 : bits(1) <-> E1

mapping m1 = {
    0b0 <-> A1,
    0b1 <-> B1,
}

val m2 : E1 <-> E2

mapping m2 = {
    A1 <-> A2,
    B1 <-> B2,
}

val main : unit -> unit

function main() = {
    let x: int = match 0b10 {
        0b00 => 1,
        m1(m2(A2)) @ 0b0 => 2,
        _ => 3,
    };
    print_int("x = ", x);
    let y: int = match 0b10 {
        0b00 => 1,
        m1(m2(B2)) @ 0b0 => 2,
        _ => 3,
    };
    print_int("y = ", 2)
}