Design and Implementation of a Unified Reflection and Dynamic Invocation System for Native Languages via Synthetic RTTI and ABI-Level Interoperability
Loading...
Date
Authors
Journal Title
Journal ISSN
Volume Title
Publisher
University of Tlemcen
Abstract
Native compiled languages do not interoperate at the object level. Each language defines its own
type system, its own calling conventions, and its own memory model. Bridging them requires
hand-written glue code for every language pair: a cost that grows quadratically with the number
of languages involved.
This thesis identifies the root cause of that cost and removes it. The root cause is not the
diversity of calling conventions: those are already resolved by the C ABI, which every compiled
language can emit and consume. The root cause is the absence of a shared descriptor protocol:
a stable, C-ABI-visible format in which a language can publish what its types are, how to
construct them, and how to invoke their operations, so that any other language can read that
description and act on it without prior static knowledge of the source type system.
The thesis argues that such a protocol is always constructible, and that its constructibility
rests on a fundamental duality named directly in the thesis title. The first pole is Synthetic
RTTI: every compiler must build a complete internal model of every type during semantic
analysis in order to verify type correctness and generate code. This model exists in the compiler’s
intermediate representation regardless of whether the language standard requires it to be preserved
in the binary. It is therefore always accessible, either natively (Delphi’s System.Rtti.NET
metadata) or synthetically (intercepted at the compilation phase via a GCC plugin, a GHC Core
plugin, or a Clang AST pass). The second pole is ABI-Level Interoperability: the C calling
convention is paradigm-neutral, language-neutral, and universal among compiled languages.
It is the invariant transport through which any RTTI-derived descriptor can be published and
consumed. The descriptor protocol is the interface between the two poles; it is what varies across
paradigm categories (OOP, functional, procedural), while the poles themselves remain constant.
This thesis defines the Native ABI Reflection Protocol (NARP, hereafter NARP): a descriptor
protocol and invocation protocol for class-based OOP languages, and demonstrates it with two
concrete language adapters. The Delphi RTTI Bridge reads Delphi’s built-in runtime RTTI
through TRttiContext and exposes it as a 28-function C ABI surface, giving any C-callable
language full dynamic access to Delphi FMX/VCL components without source modification. The
GCCC++Plugin intercepts GCC’s PLUGIN_FINISH_TYPE event: the moment after semantic
analysis when each class’s type node is fully populated, and synthesises equivalent C-ABI-stable
class descriptors for arbitrary C++ class hierarchies, without modifying any C++ source.
Both adapters produce descriptors in the same format. The same 28-function invocation
protocol works on both. A 16-byte tagged union, TDVariant, carries values across all language
boundaries. Four client bindings (C, D, Python, Delphi) demonstrate that connecting a new
consuming language costs one fixed adapter over the stable C ABI surface, not one adapter per
exposed class.
Benchmarks show cached cross-language invocation latency of 180ns, 12× over a direct
native call, well within interactive budgets, and below COM/IDispatch’s ∼500ns, without
requiring IDL authoring or static wrapper generation