vitreo12 / omni

DSL for low-level audio programming.
https://vitreo12.github.io/omni/
MIT License
188 stars 6 forks source link

New destructor for each concrete instantiation of struct #1

Open vitreo12 opened 5 years ago

vitreo12 commented 5 years ago

It would be nice to have a destructor for each concrete instantiation of struct, in order to then detect if any type in the current struct is another struct. This would also remove the need of struct generics to only be SomeNumber.

The new destructor would be triggered in the init function, which would add type information to a compile time table[string, NimNode] that will contain then all the information to build all the needed destructors.

Refer to newDestructors.nim and to this:

{.push experimental: "codeReordering".}

type 
    Obj[T] = object
        val : T

let one = Obj[string](val : "hi")
let two = Obj[float](val : 0.5)
let three = Obj[int](val : 1)

fun(one)
fun(two)
fun(three)

proc fun(a : Obj[string]) : void =
    echo "stringy string"

proc fun(a : Obj[float]) : void =
    echo "floaty float"

proc fun(a : Obj[int]) : void =
    echo "inty int"

{.pop.}
vitreo12 commented 4 years ago

Related to #59