Class: Stone::AST::ProgramUnit::UnionValueConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/stone/ast/program_unit.rb

Overview

Converts raw i64 values from LLVM to Ruby values based on union type alternatives. NOTE: This is a temporary solution until proper runtime type dispatch is implemented. The limitation is that Int(0) in Int | Null will return nil, not 0.

Instance Method Summary collapse

Constructor Details

#initialize(value, union_type) ⇒ UnionValueConverter



291
292
293
294
# File 'lib/stone/ast/program_unit.rb', line 291

def initialize(value, union_type)
  @value = value
  @alternatives = union_type.alternatives
end

Instance Method Details

#convertObject



296
297
298
299
300
301
302
303
304
# File 'lib/stone/ast/program_unit.rb', line 296

def convert
  return nil if null_value?
  return convert_string if string_only?
  return convert_record if record_only?
  return @value if has?("Int")
  return @value != 0 if has?("Bool")

  @value
end