module "main" extern "puts" func puts(text: cstring) extern "malloc" func malloc(size: u64): ^u64 extern "free" func free(address: ^u64) struct Human { name: cstring } extern "main" func main(args: []cstring): i64 { let x: ref = {} test(x) return 0 } 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) } } }