This is a helper library to streamline onGenerate
/onAfterGenerate
passes. It does two things:
- Allow different libraries to register their passes in an orderly fashion via
tink_priority
queues. - Avoid duplicate encoding from compiler to interpreter data structures.
The basic API looks like this:
class OnBuild {
static public final before:Passes;
static public final after:Passes;
}
// with this:
private class Passes {
public final types:Queue<ReadOnlyArray<Type>->Void>;
public final exprs:Queue<Type->Null<ClassField->Null<TypedExpr->Void>>>;
}
The callback type for expressions is a bit involved.
It is called for every type. If you wish to skip the type, you can return null
. Otherwise, it is called with every field on the type. If you wish to skip the field, you can return null
. Otherwise the returned callback is run on every subexpression of said field.
To run before/after the expression pass, use tink.OnBuild.EXPR_PASS
as ID
.
Because the data structures of the macro APIs are mutable and the data is shared between all callbacks, it is left up to you not to mutate them - otherwise other callbacks may be passed falsified data.
Setting this define will make it so that any field's typed AST is cached. Normally, this in not required. If you do wish to access field expressions from type passes, turning on this flag may improve performance (it will however keep all decoded typed AST in memory).