corto_function corto_valueFunction(corto_value* val) { corto_function result; switch(val->kind) { case CORTO_OBJECT: if (corto_class_instanceof(corto_procedure_o, corto_typeof(val->is.object.o))) { result = val->is.object.o; } else { corto_seterr("object '%s' in value is not a function", corto_fullpath(NULL, val->is.object.o)); result = NULL; } break; default: corto_seterr("value does not represent a function"); result = NULL; break; } return result; }
corto_int16 _corto_delegate_bind(corto_function object) { /* $begin(::corto::lang::delegate::bind) */ corto_object parent = corto_parentof(object); if (corto_class_instanceof(corto_interface_o, corto_typeof(parent))) { corto_interface type = corto_interface(corto_typeof(parent)); corto_id functionName; corto_member m = NULL; /* Get function name, lookup delegate, assign function */ corto_signatureName(corto_nameof(object), functionName); if (corto_checkState(corto_type_o, CORTO_DEFINED) && (m = corto_interface_resolveMember(type, functionName)) && (m->type->kind == CORTO_COMPOSITE) && (corto_interface(m->type)->kind == CORTO_DELEGATE)) { if (corto_delegate_instanceof(corto_delegate(m->type), object)) { /* Bind instance of function is a method */ if (corto_procedure(corto_typeof(object))->kind == CORTO_METHOD) { corto_setref(&((corto_delegatedata *) CORTO_OFFSET(parent, m->offset))->instance, parent); } /* Bind procedure */ corto_setref(&((corto_delegatedata *) CORTO_OFFSET(parent, m->offset))->procedure, object); } else { /* If there is a member that corresponds to a delegate but has a non matching * signature, always report error */ corto_id id1, id2; corto_error("member '%s' of delegate type '%s' does not match signature of '%s'", corto_nameof(m), corto_fullname(m->type, id1), corto_fullname(object, id2)); goto error; } } } return 0; error: return -1; /* $end */ }