Class: Yadriggy::C::OclTypeChecker

Inherits:
ClangTypeChecker show all
Defined in:
lib/yadriggy/c/opencl.rb

Constant Summary

Constants included from CType

CType::Float32Array, CType::Float32Type, CType::FloatArray, CType::Int, CType::IntArray, CType::Void

Constants included from Yadriggy

DynType, Undef, VERSION, Void

Instance Attribute Summary collapse

Attributes inherited from ClangTypeChecker

#instance_variables, #local_vars_table

Instance Method Summary collapse

Methods inherited from ClangTypeChecker

#binary_cexpr_type, #check_duplicate, #declare_type, #is_subsumed_by?, #typedecl_type, #valid_type?, #valid_var_type?

Methods included from CType

#arrayof, #typedecl

Methods inherited from RubyTypeInferer

#binary_type, #bind_local_var, #get_instance_variable_type, #get_return_type, #is_attr_accessor?, #to_non_instance_type

Methods inherited from RubyTypeChecker

#bind_local_var, #clear_references, #get_call_expr_type, #get_name_type, #get_return_type, #lookup_builtin, #lookup_ruby_classes, #references, #type_assert_params, #type_assert_subsume, #type_parameters

Methods inherited from TypeChecker

#add_typedef, #check, #error_group, #make_base_env, #type, #type_as, #type_assert, #type_assert_false, #type_assert_later, #type_env, #typecheck, #typedef

Methods inherited from Yadriggy::Checker

all_rules, #apply_typing_rule, #ast, #ast_env, #check, #check_all, check_init_class, #check_later, #error, #error_found!, #error_group, find_rule_entry, #make_base_env, #proceed, rule

Methods included from Yadriggy

debug, debug=, define_syntax, reify

Constructor Details

#initialize(syntax = nil) ⇒ OclTypeChecker

Returns a new instance of OclTypeChecker.



88
89
90
91
92
# File 'lib/yadriggy/c/opencl.rb', line 88

def initialize(syntax=nil)
  super(syntax)
  @blocks = {}
  @block_count = 0
end

Instance Attribute Details

#blocksHash<Block,Tuple<String,Hash<Symbol,Type>,Set<Object>>] a map to tuples of a block name, ... (readonly)

A map from blocks to their names and free variables.

Returns:

  • (Hash<Block,Tuple<String,Hash<Symbol,Type>,Set<Object>>] a map to tuples of a block name, free variables, and instance variables accessed in the block.)

    Hash<Block,Tuple<String,Hash<Symbol,Type>,Set<Object>>] a map to tuples of a block name, free variables, and instance variables accessed in the block.



86
87
88
# File 'lib/yadriggy/c/opencl.rb', line 86

def blocks
  @blocks
end

Instance Method Details

#method_with_block?(name) ⇒ Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/yadriggy/c/opencl.rb', line 94

def method_with_block?(name)
  super || name == 'ocl_times'
end

#typecheck_call_with_block(ast) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/yadriggy/c/opencl.rb', line 98

def typecheck_call_with_block(ast)
  if ast.name.name == 'ocl_times'
    type_assert(type(ast.receiver) == RubyClass::Integer,
                'the receiver must be an integer')
    type_assert(ast.block.params.size == 1,
                "wrong number of block parameters")
    tenv = FreeVarFinder.new(type_env)
    type_as(ast.block.params[0], RubyClass::Integer)
    tenv.bind_name(ast.block.params[0], RubyClass::Integer)
    tenv.bind_name(:return, Void)

    old_ins_vars = @instance_variables
    @instance_variables = Set.new
    type(ast.block, tenv)
    captured_ins_vars = @instance_variables
    @instance_variables = old_ins_vars
    @instance_variables += captured_ins_vars

    @blocks[ast.block] = ["block#{@block_count}", tenv.free_variables,
      captured_ins_vars]
    @block_count += 1
    Void
  else
    super
  end
end