Class: Stone::AST::ProgramUnit::MixedUnionValueConverter

Inherits:
Object
  • Object
show all
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

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

#convertObject



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