File: varpatterns.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 (39 lines) | stat: -rw-r--r-- 963 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
39
default Order dec
$include <prelude.sail>

/* Test constant propagation on some variable patterns in let expressions */

val test : bool -> unit

function test(b) = {
    let 'n : {8,16} = if b then 8 else 16;
    let x : bits('n) = match 'n { 8 => 0x12, 16 => 0x1234 };
    assert(unsigned(x) == (match n { 8 => 18, 16 => 4660 }) : int, "unsigned");
}

val test2 : bool -> unit

function test2(b) = {
    let 'n = (if b then 8 else 16) : {8,16};
    let x : bits('n) = match 'n { 8 => 0x12, 16 => 0x1234 };
    assert(unsigned(x) == (match n { 8 => 18, 16 => 4660 }) : int, "unsigned");
}

val test_mult : {4,8} -> unit

function test_mult('m) = {
    let 'n = 2 * 'm;
    let x : bits('n) = match 'n { 8 => 0x12, 16 => 0x1234 };
    assert(unsigned(x) == (match n { 8 => 18, 16 => 4660 }) : int, "unsigned");
}

val run : unit -> unit

function run() = {
    test(true);
    test(false);
    test2(true);
    test2(false);
    test_mult(4);
    test_mult(8);
}