qupa-project / uniview-lang

View once immutability enabling the safeties of immutable code, while enjoying near procedural performance
https://uniview.qupa.org
MIT License
2 stars 0 forks source link

Constant Value Argument Types #46

Closed AjaniBilby closed 3 years ago

AjaniBilby commented 3 years ago

This would not affect the type signature but instead allows more condensed code to be written and the compiler to remove unnecessary clones.

Example of somewhat condensed code

class String {

    fn Length(this: #String): u64 {
        return this.size - cast#[u64](1);
    }

    fn Clone(this: #String): String {
        // Initiliase the data structure
        let out = Blank#[String]();
        out.data = Memory.Alloc(this.size);
        out.size = this.size;

        // Copy the blob data to the new allocation
        Memory.Copy($out.data, $this.data, this.size, false);

        return out;
    }
}

fn puts(str: #String) {
    puts(str.data);
}