[fpc-pascal] Compiler internals. Changing dynamic arrays format

denisgolovan denisgolovan at yandex.ru
Wed Apr 13 00:34:25 CEST 2022


Hi all

I've been maintaining a set of private patches for some quite old FPC revision for some years.
The idea behind those patches to ease interoperation between FPC and LuaJIT FFI by pointer tagging for dynamic arrays.
For that to happen I was forced to modify "tdynarray" record (increase its size to 32 bytes and always align dynamic arrays to 32 bytes) & change some compiler internals to emit proper offset to "high" and "reference count" fields.

Bootstrapping patched compiler is quite an adventure.
And that is something I'd like to straight-line and I feel that I need some piece of advice.

My first trouble is initialization of dynamic arrays with constant arrays. 
It looks like simply building one version of compiler just makes a build with old-style array constants and my already patched code.
That leads to code/constant data format mismatches and new compiler process just crashes.

Looks vanilla makefile builds a several versions of compiler progressing to a final version.
It seems that my troubles also can be solved by enabling parts of the patchset progressively.
More specifically, I plan to enable array serialization code patch first in cyclelevel 1. 
Then build next compiler level using compiler 1 with rest code enabled to get cyclelevel 2.
Cyclelevel2 build should already contain both all code changes and data constants in new format.
And finally build cyclelevel3 build with cyclelevel2 compiler to complete build.

Is it the right way to go?
And if I get it right - could anyone suggest me how to enable my constants code serialization patches (via conditional defines I guess) at cyclelevel 1 and all patches at cyclelevels 2 and 3?

-- Regards,
Denis Golovan


More information about the fpc-pascal mailing list