Expand description
Annotation context and decorator registry
This module provides the infrastructure for Shape’s annotation system.
§Design Philosophy
Annotations in Shape are fully defined in Shape stdlib, not hardcoded in Rust. This module provides the generic runtime primitives that annotation lifecycle hooks use.
§Annotation Lifecycle Hooks
Annotations can define handlers for different lifecycle events:
on_define(fn, ctx)- Called when function is first definedbefore(fn, args, ctx)- Called before each function invocationafter(fn, args, result, ctx)- Called after each function invocationmetadata()- Static metadata for tooling and optimization
§Example (stdlib/finance/annotations/pattern.shape)
annotation pattern() {
on_define(fn, ctx) {
ctx.registry("patterns").set(fn.name, fn);
}
metadata() { return { is_pattern: true }; }
}§Runtime Primitives
The AnnotationContext provides domain-agnostic primitives:
cache- Key-value cache for memoizationstate- Per-annotation persistent stateregistry(name)- Named registries (patterns, strategies, features, etc.)emit(event, data)- Event emission for alerts, loggingdata- Data range manipulation (extend/restore for warmup)
Structs§
- Annotation
Cache - Key-value cache for annotation memoization
- Annotation
Context - Context passed to annotation lifecycle hooks
- Annotation
Registry - Registry for annotation definitions
- Annotation
State - Per-annotation persistent state
- Cache
Entry - Data
Range State - State for data range manipulation (used by @warmup)
- Emitted
Event - An emitted event from an annotation handler
- Named
Registry - A named registry for storing values (functions, patterns, etc.)