Hi everyone, I wanted to share the results of a recent experiment. Initially, I didn’t plan on implementing deep typing, but while developing my own assembler (ZASM), a rather compact and powerful runtime type system started to crystallize.
The Concept: We define the type hierarchy directly in the source code. The .type-descriptor macro handles all the "heavy lifting": it generates pointers to parent types, creates string names for debugging, and most importantly, constructs vtables with full inheritance support.
Source Code (Lisp-style DSL):
(defproc test-type-descriptor () (declare (once) (asm-func none)) (.type-descriptor object) (.type-descriptor structure) (.type-descriptor vec3))
The Result (Generated Listing):
The system automatically generates linked data structures. Notice how the hierarchy is preserved: vec3 correctly points to the structure parent, which in turn points to the base object.
0051: 51 00 | DW ; Self-reference 0053: 60 00 | DW ; "object" string 0055: 02 | DB $02 ; Type flags/ID ... 0057: | [object::vtable::new] 0057: C3 01 00 | JP object::new ; Method dispatch ... 007A: | [type::def::vec3] 007A: 67 00 | DW ; Pointer to Parent! 0080: | [vec3::vtable::new] 0080: C3 05 00 | JP vec3::new ; Overridden method 0083: C3 02 00 | JP object::delete ; Inherited method
Why this works well:
1. Compactness: Each descriptor occupies only a few bytes.
2. Inheritance "for free": If a method isn't overridden in a child type, the vtable simply copies the jump (JP) to the parent's implementation.
3. Runtime Reflection: Having type names available at runtime allows for robust type-checking directly on the hardware.
Next Steps: The final polish of the parse-arg logic for method argument validation. The goal is to have the assembler "slap the programmer's wrist" during compilation if they try to pass an incompatible register or type to a method.
h2w
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.