2021-06-01 19:58:46 +00:00
|
|
|
struct Foo {
|
|
|
|
static Func2<U>(u: U) : U {
|
|
|
|
return u;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Func<T>(t: T): T {
|
|
|
|
foo: T = t;
|
|
|
|
return Foo.Func2(foo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-03 00:26:26 +00:00
|
|
|
struct MemoryBlock<T>
|
|
|
|
{
|
|
|
|
start: MemoryAddress;
|
|
|
|
capacity: uint;
|
|
|
|
|
2021-06-07 18:51:33 +00:00
|
|
|
AddressOf(index: uint): MemoryAddress
|
2021-06-03 00:26:26 +00:00
|
|
|
{
|
2021-06-07 18:51:33 +00:00
|
|
|
return start + (index * @sizeof<T>());
|
|
|
|
}
|
|
|
|
|
|
|
|
Get(index: uint): T
|
|
|
|
{
|
|
|
|
return @dereference<T>(AddressOf(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
Set(index: uint, value: T): void
|
|
|
|
{
|
|
|
|
@memcpy(AddressOf(index), @addr(value), @sizeof<T>());
|
|
|
|
}
|
|
|
|
|
|
|
|
Free(): void
|
|
|
|
{
|
|
|
|
@free(start);
|
2021-06-03 00:26:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-01 19:58:46 +00:00
|
|
|
struct Program {
|
|
|
|
static Main(): int {
|
|
|
|
x: int = 4;
|
|
|
|
y: int = Foo.Func(x);
|
2021-06-07 18:51:33 +00:00
|
|
|
block: MemoryBlock<int> = MemoryBlock<int>
|
|
|
|
{
|
|
|
|
capacity: y,
|
|
|
|
start: @malloc(y * @sizeof<int>())
|
|
|
|
};
|
|
|
|
block.Set(0, 5);
|
|
|
|
block.Set(1, 3);
|
|
|
|
block.Set(2, 9);
|
|
|
|
block.Set(3, 100);
|
|
|
|
Console.PrintLine("%p", block.start);
|
|
|
|
Console.PrintLine("%i", block.Get(0));
|
|
|
|
Console.PrintLine("%i", block.Get(1));
|
|
|
|
Console.PrintLine("%i", block.Get(2));
|
|
|
|
Console.PrintLine("%i", block.Get(3));
|
|
|
|
block.Free();
|
|
|
|
return 0;
|
2021-06-01 19:58:46 +00:00
|
|
|
}
|
|
|
|
}
|