summaryrefslogtreecommitdiff
path: root/test/c
diff options
context:
space:
mode:
authorJon French2019-02-03 17:50:01 +0000
committerJon French2019-02-03 17:50:01 +0000
commitab3f3671d4dd682b2aee922d5a05e9455afd5849 (patch)
treed951e1beac8fa0af18c71e6c33879925b2707049 /test/c
parentbce4ee6000254c368fc83cdf62bdcdb9374b9691 (diff)
parent4f45f462333c5494a84886677bc78a49c84da081 (diff)
Merge branch 'sail2' into rmem_interpreter
Diffstat (limited to 'test/c')
-rw-r--r--test/c/nonexistent_pragma.expect1
-rw-r--r--test/c/nonexistent_pragma.sail12
-rw-r--r--test/c/unroll.expect6
-rw-r--r--test/c/unroll.sail37
4 files changed, 56 insertions, 0 deletions
diff --git a/test/c/nonexistent_pragma.expect b/test/c/nonexistent_pragma.expect
new file mode 100644
index 00000000..9daeafb9
--- /dev/null
+++ b/test/c/nonexistent_pragma.expect
@@ -0,0 +1 @@
+test
diff --git a/test/c/nonexistent_pragma.sail b/test/c/nonexistent_pragma.sail
new file mode 100644
index 00000000..da4b99f7
--- /dev/null
+++ b/test/c/nonexistent_pragma.sail
@@ -0,0 +1,12 @@
+default Order dec
+
+$include <prelude.sail>
+
+$not_a_valid_pragma test
+
+val "print_endline" : string -> unit
+
+function main((): unit) -> unit = {
+ print_endline("test")
+}
+
diff --git a/test/c/unroll.expect b/test/c/unroll.expect
new file mode 100644
index 00000000..355943c1
--- /dev/null
+++ b/test/c/unroll.expect
@@ -0,0 +1,6 @@
+fac(4) = 24
+fac(5) = 120
+fac(6) = 720
+fac2(4) = 24
+fac2(5) = 120
+fac2(6) = 720
diff --git a/test/c/unroll.sail b/test/c/unroll.sail
new file mode 100644
index 00000000..c68bb49d
--- /dev/null
+++ b/test/c/unroll.sail
@@ -0,0 +1,37 @@
+default Order dec
+
+$include <prelude.sail>
+
+/* It's hard to test that this optimization does the right thing, but
+we can at least test that it doesn't do the wrong thing. */
+
+$optimize unroll 20
+val fac : forall 'n, 'n >= 0. int('n) -> int
+function fac(n) = {
+ if n == 0 then {
+ 1
+ } else {
+ n * fac(n - 1)
+ }
+}
+
+$optimize unroll 2
+val fac2 : forall 'n, 'n >= 0. int('n) -> int
+function fac2(n) = {
+ if n == 0 then {
+ 1
+ } else {
+ n * fac2(n - 1)
+ }
+}
+
+val "print_int" : (string, int) -> unit
+
+function main((): unit) -> unit = {
+ print_int("fac(4) = ", fac(4));
+ print_int("fac(5) = ", fac(5));
+ print_int("fac(6) = ", fac(6));
+ print_int("fac2(4) = ", fac2(4));
+ print_int("fac2(5) = ", fac2(5));
+ print_int("fac2(6) = ", fac2(6))
+} \ No newline at end of file