Lombiq / Hastlayer-SDK

Turning .NET software into FPGA hardware for faster execution and lower power usage.

Home Page:https://hastlayer.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support generics (HAST-252)

Piedone opened this issue · comments

Support for generic types, i.e. Generic<T>.

Unlike C++ templates generics in .NET directly exist in IL. How we could handle this is to substitute the type parameters (also a bit like with C++ templates) and basically create a version of the generic class for each type it's used with.

This can happen similarly to how array types are created in VHDL, e.g. we'd create a class named Generic_int and Generic_long from two usages of Generic<T>.

Possibly the best way to implement this would be via an AST processor in the Transformer.

Ideally, there would be a way to get rid of generics in IL and somehow substitute them statically (by the compiler or with some IL tool) but there seems to be no way to do this.

Jira issue

Having arrays of struct-s + a generic SimpleMemory<T> (of structs) would be very handy for image processsing applications. I guess you need to follow some alignment rules on the hardware, so there might be contstraints, but couldn't it be viewed as sugar around byte[] for well-aligned data?

That's a good idea with SimpleMemory, and indeed it would be a nice addition. Since this is implementation-wise a different issue from user-defined generic types, let's follow it up here: #25.

BTW you can already define arrays of any supported type, including custom structs (but not store them directly in SimpleMemory).