Conversation
…ype arg support and fixtures
…; add type alias global var support
…nctionNode directly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds generic class and function support via type erasure (
T→i8*). No monomorphization — all type parameters erase to opaque pointers at the LLVM IR level, keeping codegen simple and self-hosting compatible.Generic classes:
class Stack<T>,Box<T>,Queue<T>,Pair<A, B>,Wrapper<T extends Printable>all workT[]erases to%ObjectArray*; push/pop/shift guarded against generic class instances to avoid dispatching to built-in array handlersnew Stack<Point>(),new Box<Animal>()— interface and class type args supportedtype Point = { ... }type alias works as a generic type arg (treated as interface)Generic functions:
identity<T>,first<T>(arr: T[])— type parameter return types infer correctly for both locals and globalsSelf-hosting fixes:
{ }fromcase "type_alias_declaration"in native transformer — the native compiler'sbreakinside a block scope exited the block rather than the switch, silently dropping all type alias declarations from the ASTFunctionNodestruct layout crash in native compilertypeParametersto end of interfaces (CLAUDE.md rule improve install scripts #3); refactored union-type-checkerTests: 9 new fixtures in
tests/fixtures/generics/— all pass with both node and native compilers. Stage 0 and Stage 1 self-hosting pass (npm run verify:quick).Limitations (not in this PR)
new Stack<number>()) not supported —doubleandi8*have different sizesswap(): Pair<B,A>) — result not tracked as class instanceextendsclauseTest plan
npm test— 396+ tests pass (5 pre-existing network failures unrelated to generics)stack,queue,box,pair,generic-functions,generic-interface,generic-type-alias,generic-class-arg,generic-extendsnpm run verify:quick— Stage 0 and Stage 1 self-hosting pass