Improved type system

This commit is contained in:
2025-02-17 14:31:47 +01:00
parent 3550f9e24e
commit b8e37fafae
62 changed files with 189 additions and 172 deletions

View File

@ -1 +1 @@
f(a Int,) -> Int { return a }
f(a int,) -> int { return a }

View File

@ -1 +1 @@
f(,a Int) {}
f(,a int) {}

View File

@ -2,6 +2,6 @@ main() {
writeToMemory(42)
}
writeToMemory(p *Any) {
writeToMemory(p *any) {
p[0] = 'A'
}

View File

@ -2,6 +2,6 @@ main() {
x := 1 + f(x)
}
f(x Int) -> Int {
f(x int) -> int {
return x
}

View File

@ -49,8 +49,8 @@ var errs = []struct {
{"MissingParameter3.q", errors.MissingParameter},
{"MissingType.q", errors.MissingType},
{"ReturnCountMismatch.q", &errors.ReturnCountMismatch{Count: 1, ExpectedCount: 0}},
{"TypeMismatch.q", &errors.TypeMismatch{Expected: "*Any", Encountered: "Int64", ParameterName: "p"}},
{"TypeMismatch2.q", &errors.TypeMismatch{Expected: "[]Any", Encountered: "Int64", ParameterName: "array"}},
{"TypeMismatch.q", &errors.TypeMismatch{Expected: "*any", Encountered: "int64", ParameterName: "p"}},
{"TypeMismatch2.q", &errors.TypeMismatch{Expected: "[]any", Encountered: "int64", ParameterName: "array"}},
{"UnknownFunction.q", &errors.UnknownFunction{Name: "unknown"}},
{"UnknownFunction2.q", &errors.UnknownFunction{Name: "f"}},
{"UnknownIdentifier.q", &errors.UnknownIdentifier{Name: "x"}},

View File

@ -12,7 +12,7 @@ main() {
assert b == 5
}
f(b Int) -> (Int, Int) {
f(b int) -> (int, int) {
a := 0
if b >= 10 {

View File

@ -74,10 +74,10 @@ main() {
sys.exit(1)
}
inc(x Int) -> Int {
inc(x int) -> int {
return x + 1
}
dec(x Int) -> Int {
dec(x int) -> int {
return x - 1
}

View File

@ -2,6 +2,6 @@ main() {
assert f(1) + f(2) + f(3) == 9
}
f(x Int) -> Int {
f(x int) -> int {
return x + 1
}

View File

@ -12,6 +12,6 @@ main() {
}
}
f(x Int) -> Int {
f(x int) -> int {
return x
}

View File

@ -4,10 +4,10 @@ main() {
assert result == 10
}
div(x Int, y Int) -> Int {
div(x int, y int) -> int {
return x / y
}
div10(x Int) -> Int {
div10(x int) -> int {
return x / 10
}

View File

@ -5,6 +5,6 @@ main() {
assert neg(256) == -256
}
neg(x Int) -> Int {
neg(x int) -> int {
return -x
}

View File

@ -2,6 +2,6 @@ main() {
assert f(f(f(1))) == 4
}
f(x Int) -> Int {
f(x int) -> int {
return x + 1
}

View File

@ -2,7 +2,7 @@ main() {
f(10)
}
f(new Int) {
f(new int) {
old := new
new -= 1
assert new != old

View File

@ -2,11 +2,11 @@ main() {
assert f(1, 2, 3) == 21
}
f(x Int, y Int, z Int) -> Int {
f(x int, y int, z int) -> int {
w := g(4, 5, 6)
return x + y + z + w
}
g(x Int, y Int, z Int) -> Int {
g(x int, y int, z int) -> int {
return x + y + z
}

View File

@ -2,11 +2,11 @@ main() {
f1(1, 2, 3, 4, 5, 6)
}
f1(a Int, b Int, c Int, d Int, e Int, f Int) {
f1(a int, b int, c int, d int, e int, f int) {
f2(f, e, d, c, b, a)
}
f2(a Int, b Int, c Int, d Int, e Int, f Int) {
f2(a int, b int, c int, d int, e int, f int) {
assert a == 6
assert b == 5
assert c == 4

View File

@ -2,11 +2,11 @@ main() {
assert f(1) == 3
}
f(x Int) -> Int {
f(x int) -> int {
y := g()
return x + y
}
g() -> Int {
g() -> int {
return 2
}

View File

@ -15,14 +15,14 @@ main() {
assert i == 1 + 4
}
reverse2(a Int, b Int) -> (Int, Int) {
reverse2(a int, b int) -> (int, int) {
return b, a
}
reverse3(a Int, b Int, c Int) -> (Int, Int, Int) {
reverse3(a int, b int, c int) -> (int, int, int) {
return c, b, a
}
mix4(a Int, b Int, c Int, d Int) -> (Int, Int, Int, Int) {
mix4(a int, b int, c int, d int) -> (int, int, int, int) {
return d + a, c + b, b + c, a + d
}

View File

@ -2,10 +2,10 @@ main() {
assert f(2) == 6
}
f(x Int) -> Int {
f(x int) -> int {
return x + 1 + g(x)
}
g(x Int) -> Int {
g(x int) -> int {
return x + 1
}

View File

@ -2,6 +2,6 @@ main() {
assert f(1) == 3
}
f(x Int) -> Int {
f(x int) -> int {
return x + 1 + x
}

View File

@ -2,6 +2,6 @@ main() {
assert f(2, 3) == 25
}
f(x Int, y Int) -> Int {
f(x int, y int) -> int {
return (x + y) * (x + y)
}

View File

@ -1,6 +1,6 @@
struct Point {
x Int
y Int
x int
y int
}
main() {