10.8. Type macro and template structure support

The TYPEMACRO_BOOST module provides infrastructure for defining type macros — custom compile-time type transformations. Type macros allow introducing new type syntax that expands into standard daslang types during compilation.

All functions and symbols are in “typemacro_boost” module, use require to get access to it.

require daslib/typemacro_boost

10.8.1. Structures

typemacro_boost::TypeMacroTemplateArgument

Holds a type macro template argument with its name and inferred type.

Fields
  • name : string - Name of the template argument.

  • argument_type : TypeDeclPtr - Declared argument type from the template signature.

  • inferred_type : TypeDeclPtr - Inferred concrete type after template instantiation.

10.8.2. Function annotations

typemacro_boost::typemacro_function

This macro converts function into a type macro.

typemacro_boost::typemacro_template_function

This one converts function into a type macro that uses template arguments. For example [typemacro_template(TFlatHashTable)] def makeFlatHashTable ( macroArgument, passArgument : TypeDeclPtr; KeyType, ValueType : TypeDeclPtr; hashFunctionName : string) : TypeDeclPtr { … } We generate the body that handles template argument inference and instantiation.

10.8.3. Structure macros

typemacro_boost::typemacro_documentation

Structure annotation that stores type macro documentation metadata.

typemacro_boost::typemacro_template

Structure annotation that marks a struct as a type macro template instance.

typemacro_boost::template_structure

This macro creates typemacro function and associates it with the structure. It also creates the typemacro_template_function to associate with it. For example:

[template_structure(KeyType,ValueType)] struct template TFlatHashTable { ... }
creates:
1) [typemacro_function] def TFlatHashTable (macroArgument, passArgument : TypeDeclPtr; KeyType, ValueType : TypeDeclPtr) : TypeDeclPtr {
    return <- make`template`TFlatHashTable(macroArgument, passArgument, KeyType, ValueType)
 }
2) [typemacro_template_function(TFlatHashTable)] def make`template`TFlatHashTable (macroArgument, passArgument : TypeDeclPtr; KeyType, ValueType : TypeDeclPtr) : TypeDeclPtr {
    return <- default<TypeDeclPtr>
 }

10.8.4. Enum helpers

typemacro_boost::int64_to_enum(_enu: auto(ET); value: int64) : ET()

Converts an int64 value to the specified enum type via reinterpret cast.

Arguments
  • _enu : auto(ET)

  • value : int64

10.8.5. Template structure instantiation

typemacro_boost::is_typemacro_template_instance(passArgument: TypeDeclPtr; templateType: TypeDeclPtr; extra: array<tuple<string;string>> = array<tuple<string;string>>()) : bool()

template instance is determined by having parent == template.parent

Arguments
typemacro_boost::make_typemacro_template_instance(instance_type: Structure?; template_type: Structure?; ex: array<tuple<string;string>> = array<tuple<string;string>>())

Annotates a structure as a typemacro template instance of the given template type.

Arguments
typemacro_boost::template_structure_name(base: Structure?; arguments: array<TypeMacroTemplateArgument>; extra: array<tuple<string;string>> = array<tuple<string;string>>()) : string()

Builds a mangled template structure name from its base name and argument types.

Arguments

10.8.6. Type inference helpers

typemacro_boost::add_structure_aliases(structType: Structure?; args: array<TypeMacroTemplateArgument>)

Adds all template argument type aliases to a structure.

Arguments
typemacro_boost::infer_struct_aliases(structType: Structure?; args: array<TypeMacroTemplateArgument>) : bool()

Infers structure alias types for all template arguments from a structure definition.

Arguments
typemacro_boost::infer_template_types(passArgument: TypeDeclPtr; args: array<TypeMacroTemplateArgument>) : TypeDeclPtr()

Infers and validates template argument types against a pass argument, returning the resolved type.

Arguments
typemacro_boost::verify_arguments(args: array<TypeMacroTemplateArgument>) : bool()

Verifies that all template arguments have been fully inferred (no remaining auto or alias types).

Arguments

10.8.7. String constant access

typemacro_boost::get_string_const(expr: ExpressionPtr) : string()

Extracts a string constant value or function address name from an expression.

Arguments

10.8.8. Work tracking

typemacro_boost::is_custom_work_done(structType: Structure?) : bool()

Returns true if custom work has already been performed on the template structure.

Arguments
typemacro_boost::mark_custom_work_done(structType: Structure?)

Marks the template structure’s custom work as complete in its annotation.

Arguments

10.8.9. Type macro arguments

10.8.9.1. typemacro_argument

typemacro_boost::typemacro_argument(dimExpr: auto; index: int; constType: ExprConstString; defaultValue: auto(ValueT)) : ValueT()

Extracts a string constant or function address argument at the given index from a type macro’s dimension expressions.

Arguments
  • dimExpr : auto

  • index : int

  • constType : ExprConstString

  • defaultValue : auto(ValueT)

typemacro_boost::typemacro_argument(dimExpr: auto; index: int; constType: auto(ExprConstType); defaultValue: auto(ValueT)) : ValueT()