pc2 / sus-compiler

A new Hardware Design Language that keeps you in the driver's seat
GNU General Public License v3.0
70 stars 4 forks source link

Should structs use existing module generative code system? #2

Open VonTum opened 3 months ago

VonTum commented 3 months ago

So I've been looking to add structs to SUS. But I'm not entirely convinced by my current approach.

Basically, I had the idea of integrating struct declarations with the existing SUS generative code system, but instead of

A regular struct looks pretty unassuming:

struct MyVec3 {
    int x
    int y
    int z
}

And having the generative code would allow for templated structs like

struct MyVec<T> {
    input gen int SIZE

    T[SIZE] arr
}

And even structs with optional fields like

struct BRAMRead<T> {
    input gen bool ECC_INCLUDED

    T read_data
    if ECC_INCLUDED { // (compiletime)
        bool ecc_did_error
    }
}

The idea here is that any non-gen (compiletime) declaration is interpreted as a struct field, whereas gen declarations (like the template parameters), are executable compile-time code.

While this is easy to implement, and even gains a little bonus for language consistency, I can't help but fear I might be shooting myself in the foot somehow.