Class: Stone::AST::ProgramUnit

Inherits:
Stone::AST show all
Defined in:
lib/stone/ast/program_unit.rb,
lib/stone/ast/program_unit/top_function.rb

Defined Under Namespace

Classes: MixedUnionValueConverter, TaggedUnionConverter, TopFunction, UnionValueConverter

Constant Summary collapse

RESULT_CONVERTERS =
{
  "i64" => ->(r, _) { r.to_i },
  "boolean" => ->(r, _) { r.to_i != 0 },
  "null" => ->(_r, _) { nil },
  "pointer" => ->(r, _) { r.to_value_ptr.to_i }
}.freeze

Instance Attribute Summary

Attributes inherited from Stone::AST

#children, #name

Instance Method Summary collapse

Constructor Details

#initialize(children) ⇒ ProgramUnit

Returns a new instance of ProgramUnit.



12
13
14
15
16
# File 'lib/stone/ast/program_unit.rb', line 12

def initialize(children)
  super(:program_unit, children)
  @top_function = TopFunction.new(children)
  LLVM.init_jit
end

Instance Method Details

#eval(function_name = "__top__") ⇒ Object



22
23
24
25
26
27
28
# File 'lib/stone/ast/program_unit.rb', line 22

def eval(function_name = "__top__")
  result, result_type = run_function(global_function(function_name))
  convert_to_ruby(result, result_type)
ensure
  @type_constant_addresses = nil  # Clear cached addresses on dispose
  jit_engine&.dispose
end

#to_llirObject



18
19
20
# File 'lib/stone/ast/program_unit.rb', line 18

def to_llir
  module_ref
end