X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=xs-src%2FMouse.xs;h=a905f63c97a9c8d5e7b51c03ccd1cc6d5f296325;hp=59070e42f790de414c5065109f62740b9dcd9cac;hb=1b812057da4c97ecef7dcd723ac05e249e5d6d4b;hpb=f48920c11c806b2a1fd60be145ff2cdf79750878 diff --git a/xs-src/Mouse.xs b/xs-src/Mouse.xs index 59070e4..a905f63 100644 --- a/xs-src/Mouse.xs +++ b/xs-src/Mouse.xs @@ -1,3 +1,4 @@ +#define NEED_newSVpvn_flags_GLOBAL #include "mouse.h" SV* mouse_package; @@ -5,7 +6,7 @@ SV* mouse_namespace; SV* mouse_methods; SV* mouse_name; -MODULE = Mouse PACKAGE = Mouse::Util +MODULE = Mouse PACKAGE = Mouse PROTOTYPES: DISABLE @@ -15,116 +16,9 @@ BOOT: mouse_methods = newSVpvs_share("methods"); mouse_name = newSVpvs_share("name"); + MOUSE_CALL_BOOT(Mouse__Util); MOUSE_CALL_BOOT(Mouse__Util__TypeConstraints); - - -bool -is_class_loaded(SV* sv) - -void -get_code_info(CV* code) -PREINIT: - GV* gv; - HV* stash; -PPCODE: - if((gv = CvGV(code)) && isGV(gv) && (stash = GvSTASH(gv))){ - EXTEND(SP, 2); - mPUSHs(newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U)); - mPUSHs(newSVpvn_share(GvNAME_get(gv), GvNAMELEN_get(gv), 0U)); - } - -SV* -get_code_package(CV* code) -PREINIT: - HV* stash; -CODE: - if(CvGV(code) && isGV(CvGV(code)) && (stash = GvSTASH(CvGV(code)))){ - RETVAL = newSVpvn_share(HvNAME_get(stash), HvNAMELEN_get(stash), 0U); - } - else{ - RETVAL = &PL_sv_no; - } -OUTPUT: - RETVAL - -CV* -get_code_ref(SV* package, SV* name) -CODE: -{ - HV* stash; - HE* he; - - if(!SvOK(package)){ - croak("You must define a package name"); - } - if(!SvOK(name)){ - croak("You must define a subroutine name"); - } - - stash = gv_stashsv(package, FALSE); - if(!stash){ - XSRETURN_UNDEF; - } - he = hv_fetch_ent(stash, name, FALSE, 0U); - if(he){ - GV* const gv = (GV*)hv_iterval(stash, he); - if(!isGV(gv)){ /* special constant or stub */ - STRLEN len; - const char* const pv = SvPV_const(name, len); - gv_init(gv, stash, pv, len, GV_ADDMULTI); - } - RETVAL = GvCVu(gv); - } - else{ - RETVAL = NULL; - } - - if(!RETVAL){ - XSRETURN_UNDEF; - } -} -OUTPUT: - RETVAL - -void -_generate_isa_predicate_for(SV* klass, const char* predicate_name = NULL) -PPCODE: -{ - STRLEN klass_len; - const char* klass_pv; - HV* stash; - CV* xsub; - - if(!SvOK(klass)){ - croak("You must define a class name for generate_for"); - } - klass_pv = SvPV_const(klass, klass_len); - klass_pv = mouse_canonicalize_package_name(klass_pv); - - if(strNE(klass_pv, "UNIVERSAL")){ - static MGVTBL mouse_util_type_constraints_vtbl; /* not used, only for identity */ - - xsub = newXS(predicate_name, XS_isa_check, __FILE__); - - stash = gv_stashpvn(klass_pv, klass_len, GV_ADD); - - CvXSUBANY(xsub).any_ptr = sv_magicext( - (SV*)xsub, - (SV*)stash, /* mg_obj */ - PERL_MAGIC_ext, - &mouse_util_type_constraints_vtbl, - klass_pv, /* mg_ptr */ - klass_len /* mg_len */ - ); - } - else{ - xsub = newXS(predicate_name, XS_isa_check_for_universal, __FILE__); - } - - if(predicate_name == NULL){ /* anonymous predicate */ - XPUSHs( newRV_noinc((SV*)xsub) ); - } -} + MOUSE_CALL_BOOT(Mouse__Meta__Method__Accessor__XS); MODULE = Mouse PACKAGE = Mouse::Meta::Module @@ -138,7 +32,7 @@ HV* namespace(SV* self) CODE: { - SV* const package = mouse_instance_get_slot(aTHX_ self, mouse_package); + SV* const package = get_slot(self, mouse_package); if(!(package && SvOK(package))){ croak("No package name defined"); } @@ -152,8 +46,8 @@ void add_method(SV* self, SV* name, SV* code, ...) CODE: { - SV* const package = mouse_instance_get_slot(aTHX_ self, mouse_package); /* $self->{package} */ - SV* const methods = mouse_instance_get_slot(aTHX_ self, mouse_methods); /* $self->{methods} */ + SV* const package = get_slot(self, mouse_package); /* $self->{package} */ + SV* const methods = get_slot(self, mouse_methods); /* $self->{methods} */ GV* gv; SV* code_ref; @@ -190,7 +84,7 @@ CODE: } sv_setsv_mg((SV*)gv, code_ref); /* *gv = $code_ref */ - mouse_instance_set_slot(aTHX_ methods, name, code); /* $self->{methods}{$name} = $code */ + set_slot(methods, name, code); /* $self->{methods}{$name} = $code */ /* TODO: name the CODE ref if it's anonymous */ //code_entity = (CV*)SvRV(code_ref); @@ -227,6 +121,7 @@ PPCODE: } } + MODULE = Mouse PACKAGE = Mouse::Meta::Role BOOT: @@ -277,69 +172,3 @@ BOOT: newCONSTSUB(gv_stashpvs("Mouse::Meta::Attribute", TRUE), "accessor_metaclass", newSVpvs("Mouse::Meta::Method::Accessor::XS")); -MODULE = Mouse PACKAGE = Mouse::Meta::TypeConstraint - -BOOT: - INSTALL_SIMPLE_READER(TypeConstraint, name); - INSTALL_SIMPLE_READER(TypeConstraint, parent); - INSTALL_SIMPLE_READER(TypeConstraint, message); - - INSTALL_SIMPLE_READER_WITH_KEY(TypeConstraint, _compiled_type_constraint, compiled_type_constraint); - INSTALL_SIMPLE_READER(TypeConstraint, _compiled_type_coercion); /* Mouse specific */ - - INSTALL_SIMPLE_PREDICATE_WITH_KEY(TypeConstraint, has_coercion, _compiled_type_coercion); - - -MODULE = Mouse PACKAGE = Mouse::Meta::Method::Accessor::XS - -CV* -_generate_accessor(klass, SV* attr, metaclass) -CODE: -{ - RETVAL = mouse_instantiate_xs_accessor(aTHX_ attr, mouse_xs_accessor); -} -OUTPUT: - RETVAL - -CV* -_generate_reader(klass, SV* attr, metaclass) -CODE: -{ - RETVAL = mouse_instantiate_xs_accessor(aTHX_ attr, mouse_xs_reader); -} -OUTPUT: - RETVAL - -CV* -_generate_writer(klass, SV* attr, metaclass) -CODE: -{ - RETVAL = mouse_instantiate_xs_accessor(aTHX_ attr, mouse_xs_writer); -} -OUTPUT: - RETVAL - -CV* -_generate_clearer(klass, SV* attr, metaclass) -CODE: -{ - SV* const slot = mcall0s(attr, "name"); - STRLEN len; - const char* const pv = SvPV_const(slot, len); - RETVAL = mouse_install_simple_accessor(aTHX_ NULL, pv, len, mouse_xs_simple_clearer); -} -OUTPUT: - RETVAL - -CV* -_generate_predicate(klass, SV* attr, metaclass) -CODE: -{ - SV* const slot = mcall0s(attr, "name"); - STRLEN len; - const char* const pv = SvPV_const(slot, len); - RETVAL = mouse_install_simple_accessor(aTHX_ NULL, pv, len, mouse_xs_simple_predicate); -} -OUTPUT: - RETVAL -