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 static fields and properties (HAST-251)

Piedone opened this issue · comments

Currently, all methods' variables are like private static fields because the VHDL variables' values are kept between FSM executions. Because such variables are never read before being initialized (this would also be invalid in C#) this is not an issue.

The same mechanism could be used for static fields/properties: every field would have a static setter and getter FSM (like for instance properties) and they'd use the same common signal to store the member's value (which would only be produced once, on first access).

It's a question how this could work with arrays, because their single elements should also be writable. Maybe the easiest way would be to always overwrite the whole array too.

However, arrays and static fields/properties also bring an issue with concurrency: what happens if multiple threads try to access an uninitialized static field? This is not thread-safe in .NET either.

When ConvertConstructorCallIntoInitializer is deactivated, static constructors will appear, and these will contain field initializers (however instance ctors will also appear with a lot of redundant code). This is easier to transform. Such static ctors should be run once after power up (i.e. on the FPGA we need to store that they were run) simultaneously on the first start Task.WhenAll()-style. But what if static fields depend on each other? Maybe a sequential run, but with two passes is better.

Jira issue