Class: Stone::AST::ProgramUnit::TaggedUnionConverter

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

Overview

Converts tagged union structs from memory to Ruby values using the runtime type tag. The union struct layout is: { ptr type_tag, [N x i8] payload } The type_tag is a pointer to a Stone::Type constant, which we compare to known type constants.

Instance Method Summary collapse

Constructor Details

#initialize(union_ptr_addr, union_type, address_lookup) ⇒ TaggedUnionConverter



235
236
237
238
239
240
# File 'lib/stone/ast/program_unit.rb', line 235

def initialize(union_ptr_addr, union_type, address_lookup)
  @union_ptr = FFI::Pointer.new(union_ptr_addr)
  @union_type = union_type
  @alternatives = union_type.alternatives
  @address_lookup = address_lookup  # Proc that takes type_name and returns JIT address
end

Instance Method Details

#convertObject



242
243
244
245
246
# File 'lib/stone/ast/program_unit.rb', line 242

def convert
  type_tag_addr = read_type_tag
  type_name = identify_type(type_tag_addr)
  read_and_convert_payload(type_name)
end