ForNeVeR / Cesium

C compiler for the CLI platform
MIT License
381 stars 42 forks source link

Per-translation-unit variable indexing #634

Open ForNeVeR opened 2 months ago

ForNeVeR commented 2 months ago

_Originally posted by @ForNeVeR in https://github.com/ForNeVeR/Cesium/pull/617#discussion_r1740190291_

Currently, we have a global static counter, CurrentIndex in the Cesium.CodeGen.Contexts.VariableInfo record.

https://github.com/ForNeVeR/Cesium/blob/f1b5204e9d1f0869ed8c4ee0caf3c3e41ad6a5a9/Cesium.CodeGen/Contexts/VariableInfo.cs#L7-L11

I'd like to have some sort of indexing that's tied to the translation unit.

Such a counter is too error-prone: it will easily overflow on 2 billion variables constructed in a single compilation session. Moreover, this construct makes it impossible to copy a VariableInfo.

kant2002 commented 2 months ago

I think if put CurrentIndex into FunctionScope that would work.

ForNeVeR commented 2 months ago

Yep, most likely it will.