Previously it wasnt working but now its working, TRUST ME
This commit is contained in:
90
build/examples/_polymorphism.core
Normal file
90
build/examples/_polymorphism.core
Normal file
@@ -0,0 +1,90 @@
|
||||
|
||||
/*
|
||||
PushStruct :: (a: *MA.Arena, $T: Type): *$T
|
||||
size := size_of(Type)
|
||||
result := PushSize(a, size)
|
||||
return result
|
||||
|
||||
Array(int)
|
||||
|
||||
QueueAddSLL(list: $List, node: $Node, first: #Identifier = first, last: #Identifier = last, next: #Identifier = next)
|
||||
|
||||
ArrayAdd(array: $Array, item: $Item, data: #Identifier = data, len: #Identifier = len, len: #Identifier = cap)
|
||||
|
||||
QueueAddSLL(list: $List, node: $Node, $first = first, $last = last, $next = next)
|
||||
if list.first == 0
|
||||
list.first = list.last = node
|
||||
else
|
||||
list.last = list.last.next = node
|
||||
*/
|
||||
|
||||
Array :: struct($T: Type)
|
||||
data: *T
|
||||
len: int
|
||||
cap: int
|
||||
|
||||
Tuple :: struct($A: Type, $B: Type)
|
||||
a: A
|
||||
b: B
|
||||
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) {
|
||||
data = a,
|
||||
len = count,
|
||||
cap = count
|
||||
}
|
||||
return result
|
||||
|
||||
// :Multiple arguments
|
||||
// @todo: maybe disallow multiple arguments in current form
|
||||
// and use polimorphism. Then we could make var unpacking,
|
||||
// unpack structs making it more powerful
|
||||
MultipleArgs :: (): Tuple(int, F32)
|
||||
return {32, 32}
|
||||
|
||||
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}
|
||||
second_array: Array(int)
|
||||
third_array: Array(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()
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user