This repository has been archived on 2025-10-24. You can view files and clone it, but cannot push or open issues or pull requests.
Files
nub-lang-archive-2/example/src/main.nub
2025-09-19 23:08:12 +02:00

59 lines
855 B
Plaintext

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)
}
}
}