...
This commit is contained in:
@@ -11,49 +11,49 @@ struct Human
|
||||
|
||||
extern "main" func main(args: []cstring): i64
|
||||
{
|
||||
let x: ref<Human> = {}
|
||||
// let x: ref<Human> = {}
|
||||
|
||||
test(x)
|
||||
// test(x)
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
func test(x: ref<Human>)
|
||||
{
|
||||
// func test(x: ref<Human>)
|
||||
// {
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
struct ref<T>
|
||||
{
|
||||
value: ^T
|
||||
count: ^u64
|
||||
// struct ref<T>
|
||||
// {
|
||||
// value: ^T
|
||||
// count: ^u64
|
||||
|
||||
@oncreate
|
||||
func on_create()
|
||||
{
|
||||
puts("on_create")
|
||||
this.value = @interpret(^T, malloc(@size(T)))
|
||||
this.count = @interpret(^u64, malloc(@size(u64)))
|
||||
this.count^ = 1
|
||||
}
|
||||
// @oncreate
|
||||
// func on_create()
|
||||
// {
|
||||
// puts("on_create")
|
||||
// this.value = @interpret(^T, malloc(@size(T)))
|
||||
// this.count = @interpret(^u64, malloc(@size(u64)))
|
||||
// this.count^ = 1
|
||||
// }
|
||||
|
||||
@oncopy
|
||||
func on_copy()
|
||||
{
|
||||
puts("on_copy")
|
||||
this.count^ = 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(@interpret(^void, this.value))
|
||||
free(@interpret(^void, this.count))
|
||||
}
|
||||
}
|
||||
}
|
||||
// @ondestroy
|
||||
// func on_destroy()
|
||||
// {
|
||||
// puts("on_destroy")
|
||||
// this.count^ = this.count^ - 1
|
||||
// if this.count^ <= 0
|
||||
// {
|
||||
// puts("free")
|
||||
// free(@interpret(^void, this.value))
|
||||
// free(@interpret(^void, this.count))
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
Reference in New Issue
Block a user