This commit is contained in:
nub31
2025-09-20 18:17:40 +02:00
parent 7e8ca4171d
commit def567ce4b
10 changed files with 292 additions and 85 deletions

View File

@@ -1,8 +1,8 @@
module "main"
extern "puts" func puts(text: cstring)
extern "malloc" func malloc(size: u64): ^u64
extern "free" func free(address: ^u64)
extern "malloc" func malloc(size: u64): ^void
extern "free" func free(address: ^void)
struct Human
{
@@ -11,29 +11,29 @@ struct Human
extern "main" func main(args: []cstring): i64
{
let x: ref = {}
let x: ref<Human> = {}
test(x)
return 0
}
func test(x: ref)
func test(x: ref<Human>)
{
}
struct ref
struct ref<T>
{
value: ^u64
value: ^T
count: ^u64
@oncreate
func on_create()
{
puts("on_create")
this.value = malloc(8)
this.count = malloc(8)
this.value = @interpret(^T, malloc(@size(T)))
this.count = @interpret(^u64, malloc(@size(u64)))
this.count^ = 1
}
@@ -52,8 +52,8 @@ struct ref
if this.count^ <= 0
{
puts("free")
free(this.value)
free(this.count)
free(@interpret(^void, this.value))
free(@interpret(^void, this.count))
}
}
}