qlova / ilang

"i" is a clear, concise programming language that is multi-lingual cross-platform, deterministic and resilient.
Artistic License 2.0
7 stars 1 forks source link

Rust style ownership #7

Open Splizard opened 7 years ago

Splizard commented 7 years ago

Consider the code:

type SubValue {
    n
}

type Value {
    {SubValue} sub
}

type Pointer {
    {Value} value
    {Pointer} p
}

software {
    var p = Pointer()
    p.value.sub.n = 5   

    var t = p.value
    p.value = Value()

    print(t.sub.n)
}

There is currently a dangling pointer issue here. Instead of creating very evil bugs, the language should have an ownership system of sorts. When this happens:

var t = p.value
p.value = Value()

This should imply that 't' has taken the value of 'p.value' and now 'p.value' is empty. This should stop such dangling pointer bugs from occurring.