Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/rdl/wrap.rb,
lib/rdl/typecheck.rb
Instance Method Summary collapse
-
#__rdl_dyn_type_check(__rdl_meth, node_id, *args, &block) ⇒ Object
Method to replace dependently typed methods, and insert dynamic checks of types.
- #singleton_method_added(meth) ⇒ Object
Instance Method Details
#__rdl_dyn_type_check(__rdl_meth, node_id, *args, &block) ⇒ Object
Method to replace dependently typed methods, and insert dynamic checks of types.
This method will check that given args satisfy given type, run the original method,
then check that the returned value satisfies the returned type, and finally return that value.
[+ __rdl_meth +] is a Symbol naming the method being replaced.
[+ node_id +] is an Integer representing the object_id of the relevant AST node to be looked up in the comp_type_map.
[+ *args ], [ &block +] are the original arguments and blocked passed in a method call.
returns whatever is returned by calling the given method with the given args and block.
2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 |
# File 'lib/rdl/typecheck.rb', line 2140 def __rdl_dyn_type_check(__rdl_meth, node_id, *args, &block) tmeth, tmeth_old, tmeth_res, self_klass, trecv_old, targs_old, binds = RDL::Globals.comp_type_map[node_id] raise RuntimeError, "Could not find cached type-level computation results for method #{__rdl_meth}." unless tmeth if RDL::Config.instance.rerun_comp_types tmeth_new = RDL::Typecheck.compute_types(tmeth_old, self_klass, trecv_old, targs_old, binds) unless tmeth_new == tmeth_res raise RDL::Type::TypeError, "Type-level computation evaluated to different result from type checking time for class #{self_klass} method #{__rdl_meth}.\n Got #{tmeth_res} the first time, but #{tmeth_new} the second time." end end bind = binding inst = nil inst = @__rdl_type.to_inst if ((defined? @__rdl_type) && @__rdl_type.is_a?(RDL::Type::GenericType)) klass = self.class.to_s inst = Hash[RDL::Globals.type_params[klass][0].zip []] if (not(inst) && RDL::Globals.type_params[klass]) inst = {} if not inst matches, args, _, bind = RDL::Type::MethodType.check_arg_types("#{__rdl_meth}", self, bind, [tmeth], inst, *args, &block) ret = self.send(__rdl_meth, *args, &block) if matches ret = RDL::Type::MethodType.check_ret_types(self, "#{__rdl_meth}", [tmeth], inst, matches, ret, bind, *args, &block) unless __rdl_meth == :initialize end return ret end |
#singleton_method_added(meth) ⇒ Object
816 817 818 819 820 821 822 |
# File 'lib/rdl/wrap.rb', line 816 def singleton_method_added(meth) klass = self.to_s klass = "Object" if (klass.is_a? Object) && (klass.to_s == "main") sklass = RDL::Util.add_singleton_marker(klass) RDL::Wrap.do_method_added(self, true, sklass, meth) nil end |