diff options
| author | Alasdair | 2019-04-06 00:07:11 +0100 |
|---|---|---|
| committer | Alasdair | 2019-04-06 01:30:27 +0100 |
| commit | 76bf4a3853e547ae2e0327b20e4f4b89d16820b7 (patch) | |
| tree | c237dfe772fc299bb1fd37b5035df668b0702ca3 /test/c | |
| parent | 889f129b824790694f820d7d083607796abd3efb (diff) | |
Various bugfixes and improvements
- Rename DeIid to Operator. It corresponds to operator <string> in the
syntax. The previous name is from when it was called deinfix in
sail1.
- Removed things that weren't actually common from
pretty_print_common.ml, e.g. printing identifiers is backend
specific. The doc_id function here was only used for a very specific
use case in pretty_print_lem, so I simplified it and renamed it to
doc_sia_id, as it is always used for a SIA.Id whatever that is.
- There is some support for anonymous records in constructors, e.g.
union Foo ('a : Type) = {
MkFoo : { field1 : 'a, field2 : int }
}
somewhat similar to the enum syntax in Rust. I'm not sure when this
was added, but there were a few odd things about it. It was
desugared in the preprocessor, rather than initial_check, and the
desugaring generated incorrect code for polymorphic anonymous
records as above.
I moved the code to initial_check, so the pre-processor now just
deals with pre-processor things and not generating types, and I
fixed the code to work with polymorphic types. This revealed some
issues in the C backend w.r.t. polymorphic structs, which is the
bulk of this commit. I also added some tests for this feature.
- OCaml backend can now generate a valid string_of function for
polymorphic structs, previously this would cause the ocaml to fail
to compile.
- Some cleanup in the Sail ott definition
- Add support for E_var in interpreter previously this would just
cause the interpreter to fail
Diffstat (limited to 'test/c')
| -rw-r--r-- | test/c/anon_rec.expect | 1 | ||||
| -rw-r--r-- | test/c/anon_rec.sail | 12 | ||||
| -rw-r--r-- | test/c/poly_int_record.expect | 3 | ||||
| -rw-r--r-- | test/c/poly_int_record.sail | 21 | ||||
| -rw-r--r-- | test/c/poly_record.expect | 1 | ||||
| -rw-r--r-- | test/c/poly_record.sail | 18 |
6 files changed, 56 insertions, 0 deletions
diff --git a/test/c/anon_rec.expect b/test/c/anon_rec.expect new file mode 100644 index 00000000..9766475a --- /dev/null +++ b/test/c/anon_rec.expect @@ -0,0 +1 @@ +ok diff --git a/test/c/anon_rec.sail b/test/c/anon_rec.sail new file mode 100644 index 00000000..17dd1e07 --- /dev/null +++ b/test/c/anon_rec.sail @@ -0,0 +1,12 @@ +default Order dec + +union Foo ('a : Type) = { + MkFoo : { field1 : 'a, field2 : int } +} + +val "print_endline" : string -> unit + +function main((): unit) -> unit = { + let _: Foo(unit) = MkFoo(struct { field1 = (), field2 = 22 }); + print_endline("ok") +} diff --git a/test/c/poly_int_record.expect b/test/c/poly_int_record.expect new file mode 100644 index 00000000..a8a10253 --- /dev/null +++ b/test/c/poly_int_record.expect @@ -0,0 +1,3 @@ +x = 1 +y = 2 +ok diff --git a/test/c/poly_int_record.sail b/test/c/poly_int_record.sail new file mode 100644 index 00000000..ebb18713 --- /dev/null +++ b/test/c/poly_int_record.sail @@ -0,0 +1,21 @@ +default Order dec + +val "print_endline" : string -> unit +val "print_int" : (string, int) -> unit + +struct S('a: Type) = { + field1 : ('a, 'a), + field2 : unit +} + +function main((): unit) -> unit = { + var s : S(range(0, 3)) = struct { field1 = (0, 3), field2 = () }; + s.field1 = (1, 2); + match s.field1 { + (x, y) => { + print_int("x = ", x); + print_int("y = ", y); + } + }; + print_endline("ok"); +} diff --git a/test/c/poly_record.expect b/test/c/poly_record.expect new file mode 100644 index 00000000..9766475a --- /dev/null +++ b/test/c/poly_record.expect @@ -0,0 +1 @@ +ok diff --git a/test/c/poly_record.sail b/test/c/poly_record.sail new file mode 100644 index 00000000..afe1f144 --- /dev/null +++ b/test/c/poly_record.sail @@ -0,0 +1,18 @@ +default Order dec + +val "print_endline" : string -> unit + +struct S('a: Type) = { + field1 : 'a, + field2 : unit +} + +function f forall ('a :Type). (s: S('a)) -> unit = { + s.field2 +} + +function main((): unit) -> unit = { + let s : S(unit) = struct { field1 = (), field2 = () }; + f(s); + print_endline("ok"); +} |
