summaryrefslogtreecommitdiff
path: root/test/c/string_mapping.sail
diff options
context:
space:
mode:
authorAlasdair Armstrong2018-12-18 19:45:02 +0000
committerAlasdair Armstrong2018-12-18 19:45:02 +0000
commit4d8a4078990a00ffdc018bc8f5d4d5e3dcf6527d (patch)
tree5c02008b0958371de3a4f8abca39119c4c4775f4 /test/c/string_mapping.sail
parent24c2f4c5d9224d094083e2b4859b39c2ca0b1071 (diff)
Experiment with generating type variable names in a repeatable way
This results in much better error messages, as we can pick readable names that make sense, and should hopefully make the re-writer more robust.
Diffstat (limited to 'test/c/string_mapping.sail')
-rw-r--r--test/c/string_mapping.sail45
1 files changed, 45 insertions, 0 deletions
diff --git a/test/c/string_mapping.sail b/test/c/string_mapping.sail
new file mode 100644
index 00000000..7c620817
--- /dev/null
+++ b/test/c/string_mapping.sail
@@ -0,0 +1,45 @@
+default Order dec
+
+$include <prelude.sail>
+$include <mapping.sail>
+
+val test1 : string <-> (bool, int)
+
+mapping test1 = {
+ "foo" <-> (true, 3),
+ "b" ^ "ar" <-> (false, 2)
+}
+
+val test2 : (bool, int) <-> string
+
+mapping test2 = {
+ (true, 3) <-> "f" ^ "oo",
+ (false, 2) <-> "bar"
+}
+
+val test3 : string <-> int
+
+mapping test3 = {
+ "baz" ^ test1(true, 3) ^ "quux" <-> 6
+}
+
+val "print_endline" : string -> unit
+
+function main((): unit) -> unit = {
+ print_endline(test1(true, 3));
+ print_endline(test1(false, 2));
+ match test1("foo") {
+ (true, _) => print_endline("got true"),
+ _ => print_endline("fail")
+ };
+
+ print_endline(test2(true, 3));
+ print_endline(test2(false, 2));
+ match test2("foo") {
+ (true, _) => print_endline("got true"),
+ _ => print_endline("fail")
+ };
+
+ print_endline(test3(6));
+ ()
+} \ No newline at end of file