Class: Kumi::Syntax::Root
- Inherits:
-
Struct
- Object
- Struct
- Kumi::Syntax::Root
- Includes:
- Node
- Defined in:
- lib/kumi/syntax/root.rb
Overview
Represents the root of the Abstract Syntax Tree. It holds all the top-level declarations parsed from the source.
Instance Attribute Summary collapse
-
#imports ⇒ Object
Returns the value of attribute imports.
-
#inputs ⇒ Object
Returns the value of attribute inputs.
-
#traits ⇒ Object
Returns the value of attribute traits.
-
#values ⇒ Object
Returns the value of attribute values.
Attributes included from Node
Class Method Summary collapse
-
.stable_encode(value) ⇒ Object
Recursively encode an AST fragment into a string whose format does not depend on the Ruby version (unlike ‘inspect`/`to_s`).
Instance Method Summary collapse
Methods included from Node
Instance Attribute Details
#imports ⇒ Object
Returns the value of attribute imports
7 8 9 |
# File 'lib/kumi/syntax/root.rb', line 7 def imports @imports end |
#inputs ⇒ Object
Returns the value of attribute inputs
7 8 9 |
# File 'lib/kumi/syntax/root.rb', line 7 def inputs @inputs end |
#traits ⇒ Object
Returns the value of attribute traits
7 8 9 |
# File 'lib/kumi/syntax/root.rb', line 7 def traits @traits end |
#values ⇒ Object
Returns the value of attribute values
7 8 9 |
# File 'lib/kumi/syntax/root.rb', line 7 def values @values end |
Class Method Details
.stable_encode(value) ⇒ Object
Recursively encode an AST fragment into a string whose format does not depend on the Ruby version (unlike ‘inspect`/`to_s`). Structs are encoded by class name + ordered members; collections and scalars by an explicit tagged form. `loc` is intentionally excluded — it does not affect codegen.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/kumi/syntax/root.rb', line 34 def self.stable_encode(value) case value when Kumi::Syntax::Node members = value.respond_to?(:members) ? value.members : [] fields = members.map { |m| "#{m}=#{stable_encode(value[m])}" } "#{value.class.name}(#{fields.join(',')};hints=#{stable_encode(value.hints)})" when Array "[#{value.map { |v| stable_encode(v) }.join(',')}]" when Hash pairs = value.map { |k, v| "#{stable_encode(k)}=>#{stable_encode(v)}" }.sort "{#{pairs.join(',')}}" when Symbol ":#{value}" when String value.dump else value.to_s end end |
Instance Method Details
#children ⇒ Object
10 |
# File 'lib/kumi/syntax/root.rb', line 10 def children = [inputs, values, traits, imports] |
#digest ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/kumi/syntax/root.rb', line 12 def digest # The digest must be stable and depend on anything that could change the # compiled output: the AST and the Kumi version (compiler changes). It is # deliberately Ruby-version-independent — the generated code is plain Ruby # with identical semantics across supported Rubies, so a version-sensitive # digest would needlessly bust the compile cache and make the codegen # goldens unverifiable across the CI Ruby matrix. # # The AST is serialized through a format-pinned encoder rather than # `inspect`/`to_s`, because `Struct#to_s` and `Hash#inspect` changed their # rendering in Ruby 3.4 (`{:a=>1}` → `{a: 1}`), which would otherwise leak # the Ruby version into the hash. digest_input = "#{Kumi::VERSION}-#{Digest::SHA256.hexdigest(self.class.stable_encode([self, hints]))}" # Ruby constants cannot start with a number, so we add a prefix. "KUMI_#{Digest::SHA256.hexdigest(digest_input)}" end |