class TypedRb::Model::TmSequencing

Attributes

terms[RW]

Public Class Methods

new(terms, node) click to toggle source
Calls superclass method TypedRb::Model::Expr::new
# File lib/typed/model/tm_sequencing.rb, line 7
def initialize(terms, node)
  super(node)
  @terms = terms.reject(&:nil?)
end

Public Instance Methods

check_type(context) click to toggle source
# File lib/typed/model/tm_sequencing.rb, line 12
def check_type(context)
  process_terms_before_return(@terms, context)
end

Private Instance Methods

make_final_return(type_a, type_b) click to toggle source
# File lib/typed/model/tm_sequencing.rb, line 39
def make_final_return(type_a, type_b)
  return (type_a || type_b) if type_a.nil? || type_b.nil?
  either_types = [type_a, type_b].map{ |type| Types::TyEither.wrap(type) }
  reduced_final_type = either_types.reduce { |a,b| a.compatible_either?(b) }.unwrap
  if type_a.stack_jump? || type_b.stack_jump?
    jump_kind = [type_a, type_b].detect {|type| type.stack_jump? }.jump_kind
    reduced_final_type[jump_kind]
  else
    reduced_final_type
  end
end
process_terms_after_return(terms, context) click to toggle source
# File lib/typed/model/tm_sequencing.rb, line 34
def process_terms_after_return(terms, context)
  terms.each { |term| term.check_type(context) }
end
process_terms_before_return(terms, context, processed_terms=[], potential_return=nil) click to toggle source
# File lib/typed/model/tm_sequencing.rb, line 18
def process_terms_before_return(terms, context, processed_terms=[], potential_return=nil)
  if terms.empty?
    make_final_return(processed_terms.last, potential_return)
  else
    term_type = terms.first.check_type(context)
    if term_type.stack_jump?
      process_terms_after_return(terms.drop(1), context)
      make_final_return(term_type, potential_return)
    elsif term_type.either?
      process_terms_before_return(terms.drop(1), context, processed_terms << nil, make_final_return(term_type, potential_return))
    else
      process_terms_before_return(terms.drop(1), context, processed_terms << term_type, potential_return)
    end
  end
end