Module: Jade::Codegen::Context
Overview
Dynamically-scoped emission state. Each with_X wraps a block so the
state is visible to the recursive generate call tree, then restored
on exit. Stored on the Codegen singleton because threading these as
parameters through every AST branch would pollute the API.
Instance Method Summary collapse
-
#boundary_cache ⇒ Object
Maps boundary decoder/encoder expression strings to module-level const names that hold the same value, precomputed once at module load.
-
#dict_env ⇒ Object
Maps [interface_qname, type_var_id] => ruby parameter name.
-
#dispatched_methods ⇒ Object
Methods (def strings) to inline into each type's `Data.define do ...
-
#hoist_records? ⇒ Boolean
False outside a Module so bare expressions (REPL) get the runtime fallback — no constants exist to reference.
-
#self_var_name ⇒ Object
When set, references with this name emit as
self(and field accesses on them as bare method calls). - #with_boundary_cache(cache) ⇒ Object
- #with_dict_env(env) ⇒ Object
- #with_dispatched_methods(map) ⇒ Object
- #with_hoisted_records ⇒ Object
- #with_self_var_name(name) ⇒ Object
Instance Method Details
#boundary_cache ⇒ Object
Maps boundary decoder/encoder expression strings to module-level
const names that hold the same value, precomputed once at module
load. Populated by Boundary.collect_cache at the start of module
emission; consumed by Boundary.cached_decoder_for /
cached_encoder_for from wrapper codegen.
Shape: { decoders: { spec => const }, encoders: { spec => const } }.
Empty outside a Module — cached_* falls through to the raw spec.
83 84 85 |
# File 'lib/jade/codegen/context.rb', line 83 def boundary_cache @boundary_cache || { decoders: {}, encoders: {} } end |
#dict_env ⇒ Object
Maps [interface_qname, type_var_id] => ruby parameter name. Set by FunctionDeclaration around its body so nested calls can resolve the caller's dict for var-typed constraints. Empty outside any function.
13 14 15 |
# File 'lib/jade/codegen/context.rb', line 13 def dict_env @dict_env ||= {} end |
#dispatched_methods ⇒ Object
Methods (def strings) to inline into each type's Data.define do ... end
block. Populated once at the start of module emission by walking impls
of dispatched interfaces; consumed by StructDeclaration /
VariantDeclaration. Indexed by the fully-qualified Ruby class string
(e.g. "::Sample::Money").
63 64 65 |
# File 'lib/jade/codegen/context.rb', line 63 def dispatched_methods @dispatched_methods || {} end |
#hoist_records? ⇒ Boolean
False outside a Module so bare expressions (REPL) get the runtime fallback — no constants exist to reference.
46 47 48 |
# File 'lib/jade/codegen/context.rb', line 46 def hoist_records? @hoist_records end |
#self_var_name ⇒ Object
When set, references with this name emit as self (and field accesses
on them as bare method calls). Used to rewrite operator-impl lambda
bodies — (a, b) -> { a.amount == b.amount } becomes
def ==(b); amount == b.amount; end, no a = self shim.
Name-based, not symbol-identity-based, because Pattern::Binding doesn't carry the resolved Symbol::Variable.
32 33 34 |
# File 'lib/jade/codegen/context.rb', line 32 def self_var_name @self_var_name end |
#with_boundary_cache(cache) ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/jade/codegen/context.rb', line 87 def with_boundary_cache(cache) prev = @boundary_cache @boundary_cache = cache yield ensure @boundary_cache = prev end |
#with_dict_env(env) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/jade/codegen/context.rb', line 17 def with_dict_env(env) prev = @dict_env @dict_env = env yield ensure @dict_env = prev end |
#with_dispatched_methods(map) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/jade/codegen/context.rb', line 67 def with_dispatched_methods(map) prev = @dispatched_methods @dispatched_methods = map yield ensure @dispatched_methods = prev end |
#with_hoisted_records ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/jade/codegen/context.rb', line 50 def with_hoisted_records prev = @hoist_records @hoist_records = true yield ensure @hoist_records = prev end |
#with_self_var_name(name) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/jade/codegen/context.rb', line 36 def with_self_var_name(name) prev = @self_var_name @self_var_name = name yield ensure @self_var_name = prev end |