Files
corelang/build/examples/polymorphism.core
2023-04-22 09:15:34 +02:00

92 lines
1.6 KiB
Core

/* @todo
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
MultipleArgs :: (): Tuple(int, F32)
return {32, 32}
PolyLambda :: ($T: Type = *int): T
return 0
PolyType :: (a: $T): T
return a
GetCount :: (a: int): int
return a
C :: #import "LibC.core"
Add :: (arr: *Array($T), val: T)
if arr.cap == 0
arr.cap = 16
arr.data = C.malloc(sizeof(T)->U64 * arr.cap->U64)
arr.data[arr.len++] = val
main :: (argc: int, argv: **char): int
buff: *int
array: Array(S64)
second_array: Array(int)
third_array: Array(int)
fourth: Array(F32)
fifth: Array(F32)
sixth: Array(Array(F32))
seventh: Variant(int, F32, S64)
test_a := int
test := *int
Assert(test_a != test)
// c := MakeArray(buff, GetCount(GetCount(32)))
a, b := MultipleArgs()
Assert(a == 32 && b == 32)
Add(&array, 32)
Add(&second_array, 32)
Add(&third_array, 32)
Add(&fourth, 32)
Add(&fifth, 32)
Add(&sixth, {})
value := PolyLambda(**int)
PolyType_r1 := PolyType(10)
PolyType_r2 := PolyType(int)
PolyType_r3 := PolyType(test)
PolyType_r4 := PolyType(test_a)
PolyType_r5 := PolyType(sixth)
PolyType_r6 := PolyType(seventh)
return 0