Skip to content

Conversation

@Malcohol
Copy link
Owner

@Malcohol Malcohol commented Jan 24, 2026

This PR contains some experimental code for improving the way record types are declared:

  • Defining both types and their instance declaration is awkward, because you need to repeat information in the header and source file. In this PR, I'm exploring some kind of auto-registration for the fields so you only need declare fields in the header.

This PR also contains some experimental code for a better way of defining and registering the types themselves.

  • All registered types in my system correspond to a C++ class. In fact, that should not be necessary. C++ classes are needed to define kinds (e.g. record type, int type, etc) and it's their objects that are type. However, registered types in the system require their own class, making those type objects singleton-like and inelegant.
  • Also, types are constructed when registered with the type system. Since types have other types as dependencies, this forces a strict order of registration. (This hasn't been much of a problem as yet. As a counter-point, deferred construction is less intuitive.)
  • Additionally, there is duplication between the logic in type constructors to construct types and the constructor used during registration.
  • This PR has some code that would make all type construction based on type expressions. Even registered types would declare themselves in terms of type expressions. No class would be needed for a type, since a type expression is data. Additionally, the system could sort types in dependency order before constructing them.

I'm deferring these changes for now:

  • For the improved record declaration, the problem is that the self-registering field-information is stripped by default. There's a GCC attribute that works to prevent the stripping ("used"), and MSVC seems happy, but clang is still stripping even with the attribute. When I switch to building with shared libraries (to better support plugins), this problem will be easier to solve because I can ensure an exported symbol references the field info.
  • I'm not 100% sure about using type expressions to define all types: I need to think about it more. At least, it would be better as a separate change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants