Module: Jade::Runtime
Constant Summary collapse
- INTRINSICS =
{}
- IMPLEMENTATIONS =
{}
- IMPL_CACHE =
{}
- RECORD_CLASSES =
{}
Instance Method Summary collapse
- #boot! ⇒ Object
-
#impl_for(interface_name, value) ⇒ Object
Cached per [interface_name, value.class]; ‘register_impl` invalidates.
- #intr(name) ⇒ Object
-
#record(*keys) ⇒ Object
Memoized class for anonymous record literals.
- #register(name, &block) ⇒ Object
- #register_impl(interface_name, ruby_class, functions) ⇒ Object
Methods included from Interop::Runtime
Instance Method Details
#boot! ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/jade/runtime.rb', line 77 def boot! return if @booted @booted = true require "jade/stdlib/basics" require "jade/stdlib/string" require "jade/stdlib/list" require "jade/stdlib/tuple" require "jade/stdlib/task" require "jade/stdlib/decode" require "jade/stdlib/encode" require "jade/stdlib/bytes" require "jade/stdlib/dict" require "jade/stdlib/set" end |
#impl_for(interface_name, value) ⇒ Object
Cached per [interface_name, value.class]; ‘register_impl` invalidates.
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/jade/runtime.rb', line 116 def impl_for(interface_name, value) boot! key = [interface_name, value.class] IMPL_CACHE[key] ||= begin raw = IMPLEMENTATIONS[key] || fail("No implementation of #{interface_name} for #{value.class}") raw.any? { |_, v| v.is_a?(::String) } \ ? raw.transform_values { |v| v.is_a?(::String) ? intr(v) : v } : raw end end |
#intr(name) ⇒ Object
93 94 95 96 |
# File 'lib/jade/runtime.rb', line 93 def intr(name) boot! INTRINSICS[name] || fail("Intrinsic #{name} does not exist") end |
#record(*keys) ⇒ Object
Memoized class for anonymous record literals. Without this, every ‘1, b: 2` expression evaluated in a hot loop would call `Data.define(:a, :b)` and allocate a fresh anonymous class, defeating YJIT’s inline cache on every subsequent property access.
106 107 108 |
# File 'lib/jade/runtime.rb', line 106 def record(*keys) RECORD_CLASSES[keys] ||= Data.define(*keys) end |
#register(name, &block) ⇒ Object
98 99 100 |
# File 'lib/jade/runtime.rb', line 98 def register(name, &block) INTRINSICS[name] = block end |
#register_impl(interface_name, ruby_class, functions) ⇒ Object
110 111 112 113 |
# File 'lib/jade/runtime.rb', line 110 def register_impl(interface_name, ruby_class, functions) IMPLEMENTATIONS[[interface_name, ruby_class]] = functions IMPL_CACHE.clear end |