Skip to main content

Symbol Mangling

Zynx uses a custom mangling scheme inspired by the Itanium C++ ABI to support namespacing, overloading, and interoperation with C toolchains.

General Format

_ZN <scope> <name> E <params>
  • _ZN: Prefix for all Zynx mangled symbols.
  • <scope>: One or more name segments (module, struct/interface) encoded as <len><name>.
  • <name>: The function name (or operator code).
  • E: Terminates the nested name portion.
  • <params>: Mangled types of the function parameters. Use v if there are no parameters.

Name Encoding

  • Regular names: Encoded as <len><name>.
  • Dotted names: Each segment is encoded separately (e.g., foo.bar -> 3foo3bar).
  • Operators: Use two-letter codes (e.g., + -> pl, - -> mi).

Type Mangling Codes

TypeCodeTypeCode
i8au8h
i32iu32j
i64lu64m
f32ff64d
strDiboolb
voidvusizey

Type Modifiers

  • Reference (&T): R
  • Pointer (*T): P
  • Array (T[]): A_
  • Nullable (T?): u

Examples

Functions

  • fn foo() in module main: _ZN4main3fooEv
  • fn add(a: i32, b: i32) in module math: _ZN4math3addEii

Structs

  • struct Point in module geo: _ZN3geo5PointE
  • struct Wrapper<i32> in module util: _ZN4util7WrapperIiEE

Verification

Since Zynx's mangling scheme is heavily inspired by the Itanium C++ ABI, standard tools like c++filt can be used to decode and verify mangled names:

echo <mangled name> | c++filt -n

For example:

echo _ZN4math3addEii | c++filt -n
# Output: math::add(int, int)

See also

  • Memory Model - ownership rules and lifetime behavior that influence symbol lifetimes.
  • Compiler Internals - how mangling fits into the overall compilation pipeline and C code generation.
  • C Interoperability Overview - how mangled Zynx symbols coexist with C symbols at the ABI boundary.