Improved type system
This commit is contained in:
@ -1 +1 @@
|
||||
f(a Int,) -> Int { return a }
|
||||
f(a int,) -> int { return a }
|
@ -1 +1 @@
|
||||
f(,a Int) {}
|
||||
f(,a int) {}
|
@ -2,6 +2,6 @@ main() {
|
||||
writeToMemory(42)
|
||||
}
|
||||
|
||||
writeToMemory(p *Any) {
|
||||
writeToMemory(p *any) {
|
||||
p[0] = 'A'
|
||||
}
|
@ -2,6 +2,6 @@ main() {
|
||||
x := 1 + f(x)
|
||||
}
|
||||
|
||||
f(x Int) -> Int {
|
||||
f(x int) -> int {
|
||||
return x
|
||||
}
|
@ -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"}},
|
||||
|
@ -12,7 +12,7 @@ main() {
|
||||
assert b == 5
|
||||
}
|
||||
|
||||
f(b Int) -> (Int, Int) {
|
||||
f(b int) -> (int, int) {
|
||||
a := 0
|
||||
|
||||
if b >= 10 {
|
||||
|
@ -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
|
||||
}
|
@ -2,6 +2,6 @@ main() {
|
||||
assert f(1) + f(2) + f(3) == 9
|
||||
}
|
||||
|
||||
f(x Int) -> Int {
|
||||
f(x int) -> int {
|
||||
return x + 1
|
||||
}
|
@ -12,6 +12,6 @@ main() {
|
||||
}
|
||||
}
|
||||
|
||||
f(x Int) -> Int {
|
||||
f(x int) -> int {
|
||||
return x
|
||||
}
|
@ -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
|
||||
}
|
@ -5,6 +5,6 @@ main() {
|
||||
assert neg(256) == -256
|
||||
}
|
||||
|
||||
neg(x Int) -> Int {
|
||||
neg(x int) -> int {
|
||||
return -x
|
||||
}
|
@ -2,6 +2,6 @@ main() {
|
||||
assert f(f(f(1))) == 4
|
||||
}
|
||||
|
||||
f(x Int) -> Int {
|
||||
f(x int) -> int {
|
||||
return x + 1
|
||||
}
|
@ -2,7 +2,7 @@ main() {
|
||||
f(10)
|
||||
}
|
||||
|
||||
f(new Int) {
|
||||
f(new int) {
|
||||
old := new
|
||||
new -= 1
|
||||
assert new != old
|
||||
|
@ -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
|
||||
}
|
@ -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
|
||||
|
@ -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
|
||||
}
|
@ -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
|
||||
}
|
@ -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
|
||||
}
|
@ -2,6 +2,6 @@ main() {
|
||||
assert f(1) == 3
|
||||
}
|
||||
|
||||
f(x Int) -> Int {
|
||||
f(x int) -> int {
|
||||
return x + 1 + x
|
||||
}
|
@ -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)
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
struct Point {
|
||||
x Int
|
||||
y Int
|
||||
x int
|
||||
y int
|
||||
}
|
||||
|
||||
main() {
|
||||
|
Reference in New Issue
Block a user