#include "rubype.h" VALUE rb_mRubype, rb_cContract, rb_eRubypeArgumentTypeError, rb_eRubypeReturnTypeError, rb_eInvalidTypesigError; static ID id_is_a_p, id_to_s, id_meth, id_owner, id_arg_types, id_rtn_type; #define error_fmt "\nfor %"PRIsVALUE"\nExpected: %"PRIsVALUE"\nActual: %"PRIsVALUE"" #define unmatch_type_p(obj, type_info) !(match_type_p(obj, type_info)) int match_type_p(VALUE obj, VALUE type_info) { switch (TYPE(type_info)) { case T_SYMBOL: return rb_respond_to(obj, rb_to_id(type_info)); break; case T_MODULE: return (int)rb_funcall(obj, id_is_a_p, 1, type_info); break; case T_CLASS: return (int)rb_funcall(obj, id_is_a_p, 1, type_info); break; default: return 0; break; } } VALUE expected_mes(VALUE expected) { switch (TYPE(expected)) { case T_SYMBOL: return rb_sprintf("respond to #%"PRIsVALUE, expected); break; case T_MODULE: return rb_funcall(expected, id_to_s, 0); break; case T_CLASS: return rb_funcall(expected, id_to_s, 0); break; default: return rb_str_new2(""); break; } } #define assing_ivars VALUE meth_caller, meth, arg_types, rtn_type;\ meth_caller = rb_ivar_get(self, id_owner);\ meth = rb_ivar_get(self, id_meth);\ arg_types = rb_ivar_get(self, id_arg_types);\ rtn_type = rb_ivar_get(self, id_rtn_type); static VALUE rb_rubype_assert_args_type(VALUE self, VALUE args) { int i; VALUE target; VALUE arg, arg_type; assing_ivars for (i=0; i