Battle-plan for CTFE
Martin Nowak via Digitalmars-d-announce
digitalmars-d-announce at puremagic.com
Sun May 15 06:25:42 PDT 2016
On 05/15/2016 02:17 PM, Daniel Murphy wrote:
>
> For simple types that's true. For more complicated reference types...
>
> Variable indexes are not enough, you also need heap memory, but slices
> and pointers (and references) can refer to values either on the heap or
> the stack, and you can have a slice of a member static array of a class
> on the stack, etc. Then there are closures...
So we do need a GC or RC for arrays, structs, classes (anything
heapish). Values for those could be allocated by a simple bump/region
allocator or a dedicated allocator that support individual freeing (via
RC or GC).
In any case struct Pointer { int index; /* 2B positive values for stack,
2B negative for heap*/ } wouldn't be much more complicated than a raw
pointer (and a bit simpler to garbage collect).
> Neither e2ir or s2ir are actually that complex. A lot of the mess there
> comes from the backend IR interface being rather difficult to work with.
Think of a simple switch statement where you even need to introduce
relocations (or keep a list of fixup addresses) b/c you don't know the
jump addresses in advance.
In a visitor you simply test the cases and execute the first case body.
Not to mention that we can reuse existing solutions from the current
interpreter (e.g. for gotos see
https://github.com/dlang/dmd/blob/0757504342e48e272372b7ac52cda5a333b2a2bc/src/dinterpret.d#L1014
and
https://github.com/dlang/dmd/blob/0757504342e48e272372b7ac52cda5a333b2a2bc/src/dinterpret.d#L1094).
More information about the Digitalmars-d-announce
mailing list