From 681df3ae0bbb447e34d296a4e26baf53d0f23787 Mon Sep 17 00:00:00 2001 From: Chris Pressey Date: Wed, 30 Jun 2021 16:28:35 +0100 Subject: [PATCH] Update TODO, add some tests, which show there are things TODO. --- README.md | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- TODO.md | 27 +++++++----------- 2 files changed, 91 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 1e2e41a..0357670 100644 --- a/README.md +++ b/README.md @@ -692,7 +692,7 @@ Type of value returned must jibe with other return statements. | } ? type mismatch -### Builtins ### +### Equality ### Equality, inequality, boolean operators. @@ -726,6 +726,39 @@ Equality cannot be checked between two values of different types. | } ? mismatch +Equality can be checked between unions. (TODO) + + /| fun main() { + /| a = 40 as string|integer + /| b = 40 as string|integer + /| if a == b { + /| print("it is") + /| } + /| } + /= ok + + | fun main() { + | a = 40 as string|integer + | b = "beep" as string|integer + | if a != b { + | print("correct") + | } + | } + = correct + +Equality cannot be tested between two disjoint unions. + + | fun main() { + | a = 40 as string|integer + | b = 40 as integer|void + | if a == b { + | print("correct") + | } + | } + ? mismatch + +### Builtins ### + The usual. | fun main() { @@ -1015,7 +1048,7 @@ The type after the `as` must be a union. | } ? bad cast -The type after the `as` must be one of the types in the union. +The type of the value being cast by the `as` must be one of the types in the union. | fun main() { | a = 20; @@ -1034,6 +1067,52 @@ The type after the `as` must be the type of the expression. | } = ok +Each of the individual types named in the union type must be unique. (TODO) + + /| fun foo(a, b: integer|string) { + /| print("ok") + /| } + /| fun main() { + /| a = 20; + /| b = 30; + /| c = a + b as integer|integer|string + /| foo(a, c) + /| } + /? bad union type + +Cannot promote a union type to itself. + + | fun main() { + | a = 20; + | b = 30; + | c = a + b as integer|string + | d = c as integer|string + | print("ok") + | } + ? bad cast + +Can promote a union type to another union type, so long as it is a superset. (TODO) + + /| fun main() { + /| a = 20; + /| b = 30; + /| c = a + b as integer|string + /| d = c as integer|string|void + /| print("ok") + /| } + /= ok + +Cannot promote a union type to a union type that is not a superset. + + | fun main() { + | a = 20; + | b = 30; + | c = a + b as integer|string + | d = c as integer|void + | print("ok") + | } + ? bad cast + Values of union type can be passed to functions. | fun foo(a, b: integer|string) { diff --git a/TODO.md b/TODO.md index 95a8d32..b438b7f 100644 --- a/TODO.md +++ b/TODO.md @@ -1,30 +1,19 @@ TODO ---- -### Tests ### - -Tests for unions of unions. - -Test for equality of union values. - -Tests for multiple occurrences of same type in a union. - -Test for casting a union to the same union or a different union. - ### Implementation ### Name mangling for compilers (prepend with `_` most likely.) -Struct equality in Javascript, stackmac backends. - -Better approach to equality testing. The `Op` with `==` node -should be subject to type-checking, and transformation, whence -it is replaced with an `Eq` node, a `StrEq` node, or a `StructEq` -node, before code generation happens. +And literal characters in strings, especially `'` and `"`. Figure out a way to do `input`, `read`, and `write` with node.js backend. -Implement `int`, `chr`, `ord` for Ruby, Javascript, stackmac. +Implement `int`, `chr`, `ord` for Ruby, JavaScript, stackmac, C. + +Struct equality is not properly deep in JavaScript or C. + +Better indentation in the JavaScript backend. TaggedValue -> just a tuple. @@ -41,6 +30,10 @@ Other backends (Python? Java? CIL? Scheme?) ### Design ### +Each of the individual types named in the union type must be unique. + +Promote union type to bigger union type (e.g. `string|int` => `string|int|void`) + Don't output final value. Command-line arguments passed to `main`. (`sysmain`?) Convenience: