Polymorphic procedure, with passed in compile time type but without removing the type in params etc.

This commit is contained in:
Krzosa Karol
2023-04-01 19:40:12 +02:00
parent 3d438645a0
commit 7bf3e107bb
8 changed files with 158 additions and 80 deletions

View File

@@ -30,6 +30,10 @@ Triple :: struct($A: Type, $B: Type, $C: Type)
a: A
b: B
c: C
Variant :: union($A: Type, $B: Type, $C: Type)
a: A
b: B
c: C
MakeArray :: (a: *int, count: int): Array(int)
result := Array(int) {
@@ -46,13 +50,19 @@ MakeArray :: (a: *int, count: int): Array(int)
MultipleArgs :: (): Tuple(int, F32)
return {32, 32}
PolyLambda :: (value: $T): T
return value
PolyLambda :: ($T: Type): T
return 32
GetCount :: (a: int): int
return a
// @todo: this is allowed, shouldn't be
// Test :: (a: int, b: int = 10, c: int???)
Test :: (a: int, b: int = 10, c: int = 20)
pass
main :: (argc: int, argv: **char): int
buff: *int
array: Array(int) = {len = 10, cap = 10, data = buff}
@@ -61,12 +71,21 @@ main :: (argc: int, argv: **char): int
fourth: Array(F32)
fifth: Array(F32)
sixth: Array(Array(F32))
seventh: Variant(int, F32, S64)
// d: int(32)
// c := MakeArray(buff, GetCount(GetCount(32)))
// a,b := MultipleArgs()
a := MultipleArgs()
// value := PolyLambda(32)
Test(10)
Test(10, 20)
Test(10, 20, 30)
Test(10, b = 10)
Test(10, b = 10, c = 20)
Test(a = 10, b = 10, c = 20)
value := PolyLambda(int)
return 0