newCTFE Status October 2021

Stefan Koch uplink.coder at
Sun Oct 17 11:44:24 UTC 2021

Hi Guys,

I know I have been quiet about newCTFE for a while, mainly I have 
been focusing on other features which would make it more 
important, since a lot of the compile-time of certain companies 
is not spent in CTFE.

However recently I had the urge to fix an early design mistake in 
And that was that newCTFE had no notion of a frame pointer.
Which made it impossible to easily take pointers of locals.

What newCTFE would do when it was asked to take the address of a 
local variable was to allocate space space on the heap.
Copy the local to the heap.
and then convert the local variable into a pointer to that heap 
location under the hood.

int  x = 22;
int* y = &x;

would become:

int  x = 22;
void* _mem_y = malloc(x.sizeof);
memcpy(mem_y, &x, z.sizeof);
int* y = cast(int*)mem_y,
&x = y; // this line represents nasty compiler magic

Now however I have the concept of a frame pointer, and things 
becomes much cleaner
The code above becomes:

int  x = 22;
int* y = framePointer + OffsetFromFramePointer(x);

And no nasty syncing of different memory locations is required 
anymore ;)



More information about the Digitalmars-d mailing list