defer and struct hooks

This commit is contained in:
nub31
2025-09-19 23:08:12 +02:00
parent 609e1b5d85
commit ca838e32b8
15 changed files with 240 additions and 97 deletions

View File

@@ -1,6 +1,8 @@
module "main"
extern "puts" func puts(text: cstring)
extern "malloc" func malloc(size: u64): ^u64
extern "free" func free(address: ^u64)
struct Human
{
@@ -9,28 +11,49 @@ struct Human
extern "main" func main(args: []cstring): i64
{
let x = [2]cstring
let x: ref = {}
x[0] = "test1"
x[1] = "test2"
for u in x
{
puts(u)
}
let me: Human = {
name = "test"
}
puts(me.name)
test(32)
test(x)
return 0
}
func test(x: u8)
func test(x: ref)
{
}
struct ref
{
value: ^u64
count: ^u64
@oncreate
func on_create()
{
puts("on_create")
this.value = malloc(8)
this.count = malloc(8)
this.count^ = 1
}
@oncopy
func on_copy()
{
puts("on_copy")
this.count^ = this.count^ + 1
}
@ondestroy
func on_destroy()
{
puts("on_destroy")
this.count^ = this.count^ - 1
if this.count^ <= 0
{
puts("free")
free(this.value)
free(this.count)
}
}
}