Skip to content

Commit

Permalink
Update TODO, add some tests, which show there are things TODO.
Browse files Browse the repository at this point in the history
  • Loading branch information
cpressey committed Jun 30, 2021
1 parent 18898ef commit 681df3a
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 19 deletions.
83 changes: 81 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ Type of value returned must jibe with other return statements.
| }
? type mismatch

### Builtins ###
### Equality ###

Equality, inequality, boolean operators.

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
27 changes: 10 additions & 17 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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:
Expand Down

0 comments on commit 681df3a

Please sign in to comment.