Class: Stone::AST::ProgramUnit::MixedUnionValueConverter
- Inherits:
-
Object
- Object
- Stone::AST::ProgramUnit::MixedUnionValueConverter
- Defined in:
- lib/stone/ast/program_unit.rb
Overview
Converts raw i64 payload values from mixed unions to Ruby values. For mixed unions (e.g., Int | String), the payload is extracted as i64. Without runtime type tag access, we use heuristics based on the alternatives:
- If Int is an alternative, and value looks like a valid Int, return as Int
- If String is an alternative, and value looks like a pointer, read as String NOTE: This has limitations - we can't distinguish Int(0) from NULL, or a small Int that happens to look like a valid pointer address.
Instance Method Summary collapse
- #convert ⇒ Object
-
#initialize(value, union_type) ⇒ MixedUnionValueConverter
constructor
A new instance of MixedUnionValueConverter.
Constructor Details
#initialize(value, union_type) ⇒ MixedUnionValueConverter
335 336 337 338 |
# File 'lib/stone/ast/program_unit.rb', line 335 def initialize(value, union_type) @value = value @alternatives = union_type.alternatives end |
Instance Method Details
#convert ⇒ Object
340 341 342 343 344 345 |
# File 'lib/stone/ast/program_unit.rb', line 340 def convert return nil if null_value? return convert_int_or_string if has?("Int") && has?("String") convert_single_type end |