// Returns true if the given signature could possibly match an invocation where // the given tag maps to the given value. static bool can_match_eq(value_t signature, value_t tag, value_t value) { int64_t paramc = get_signature_parameter_count(signature); // First look for a matching parameter in the signature. value_t match = nothing(); for (int64_t i = 0; i < paramc; i++) { value_t param = get_signature_parameter_at(signature, i); value_t tags = get_parameter_tags(param); if (in_array(tags, tag)) { match = param; break; } } if (is_nothing(match)) { // There was no matching parameter so this can only match if the signature // permits it as an extra argument. return get_signature_allow_extra(signature); } else { value_t guard = get_parameter_guard(match); if (get_guard_type(guard) == gtEq) { value_t eq_value = get_guard_value(guard); return value_identity_compare(value, eq_value); } else { return true; } } }
void signature_print_on(value_t self, print_on_context_t *context) { string_buffer_printf(context->buf, "#<signature: "); for (int64_t i = 0; i < get_signature_parameter_count(self); i++) { if (i > 0) string_buffer_printf(context->buf, ", "); value_print_inner_on(get_signature_tag_at(self, i), context, -1); string_buffer_printf(context->buf, ":"); value_t param = get_signature_parameter_at(self, i); value_print_inner_on(get_parameter_guard(param), context, -1); } string_buffer_printf(context->buf, ">"); }
// Validates that it is safe to bind the given implementation to the given // surface-level method. static value_t validate_builtin_method_binding(value_t method, value_t impl) { value_t signature = get_method_signature(method); size_t posc = get_signature_parameter_count(signature) - 1 // subject - 1; // selector size_t required_posc = get_builtin_implementation_argument_count(impl); if (posc != required_posc) { ERROR("Argument count mismatch (found %i, expected %i) binding %9v to %9v", posc, required_posc, impl, signature); return new_condition(ccBuiltinBindingFailed); } return success(); }