convert the rest of the simple readers in cmop to xs
Jesse Luehrs [Wed, 17 Nov 2010 00:36:20 +0000 (18:36 -0600)]
because why not?

19 files changed:
lib/Class/MOP/Attribute.pm
lib/Class/MOP/Class.pm
lib/Class/MOP/Instance.pm
lib/Class/MOP/Method/Generated.pm
lib/Class/MOP/Method/Inlined.pm
lib/Class/MOP/Mixin/AttributeCore.pm
lib/Class/MOP/Mixin/HasAttributes.pm
lib/Class/MOP/Mixin/HasMethods.pm
mop.c
mop.h
xs/Attribute.xs [new file with mode: 0644]
xs/AttributeCore.xs
xs/Class.xs [new file with mode: 0644]
xs/Generated.xs [new file with mode: 0644]
xs/HasAttributes.xs [new file with mode: 0644]
xs/HasMethods.xs
xs/Inlined.xs [new file with mode: 0644]
xs/Instance.xs [new file with mode: 0644]
xs/MOP.xs

index a64dc8d..d0cf234 100644 (file)
@@ -158,9 +158,6 @@ sub _set_initial_slot_value {
     $instance->$initializer($value, $callback, $self);
 }
 
-sub associated_class   { $_[0]->{'associated_class'}   }
-sub associated_methods { $_[0]->{'associated_methods'} }
-
 sub get_read_method  { 
     my $self   = shift;    
     my $reader = $self->reader || $self->accessor;
index b53ecb0..b0ba266 100644 (file)
@@ -537,18 +537,6 @@ sub create {
     return $meta;
 }
 
-## Attribute readers
-
-# NOTE:
-# all these attribute readers will be bootstrapped
-# away in the Class::MOP bootstrap section
-
-sub instance_metaclass       { $_[0]->{'instance_metaclass'}          }
-sub immutable_trait          { $_[0]->{'immutable_trait'}             }
-sub constructor_class        { $_[0]->{'constructor_class'}           }
-sub constructor_name         { $_[0]->{'constructor_name'}            }
-sub destructor_class         { $_[0]->{'destructor_class'}            }
-
 # Instance Construction & Cloning
 
 sub new_object {
index c82e16e..07f2573 100644 (file)
@@ -73,8 +73,6 @@ sub _new {
 
 sub _class_name { $_[0]->{_class_name} ||= $_[0]->associated_metaclass->name }
 
-sub associated_metaclass { $_[0]{'associated_metaclass'} }
-
 sub create_instance {
     my $self = shift;
     bless {}, $self->_class_name;
index d1b50d6..cb4b1b0 100644 (file)
@@ -18,10 +18,6 @@ sub new {
     confess __PACKAGE__ . " is an abstract base class, you must provide a constructor.";
 }
 
-sub is_inline { $_[0]{is_inline} }
-
-sub definition_context { $_[0]{definition_context} }
-
 sub _initialize_body {
     confess "No body to initialize, " . __PACKAGE__ . " is an abstract base class";
 }
index 4d39824..e9b9fba 100644 (file)
@@ -12,8 +12,6 @@ our $AUTHORITY = 'cpan:STEVAN';
 
 use base 'Class::MOP::Method::Generated';
 
-sub _expected_method_class { $_[0]{_expected_method_class} }
-
 sub _uninlined_body {
     my $self = shift;
 
index 6ddf312..c5ac403 100644 (file)
@@ -22,16 +22,6 @@ sub has_default         { exists  $_[0]->{'default'} }
 sub has_initializer     { defined $_[0]->{'initializer'} }
 sub has_insertion_order { defined $_[0]->{'insertion_order'} }
 
-sub accessor             { $_[0]->{'accessor'} }
-sub reader               { $_[0]->{'reader'} }
-sub writer               { $_[0]->{'writer'} }
-sub predicate            { $_[0]->{'predicate'} }
-sub clearer              { $_[0]->{'clearer'} }
-sub builder              { $_[0]->{'builder'} }
-sub init_arg             { $_[0]->{'init_arg'} }
-sub initializer          { $_[0]->{'initializer'} }
-sub definition_context   { $_[0]->{'definition_context'} }
-sub insertion_order      { $_[0]->{'insertion_order'} }
 sub _set_insertion_order { $_[0]->{'insertion_order'} = $_[1] }
 
 sub has_read_method  { $_[0]->has_reader || $_[0]->has_accessor }
index 58cd4ba..eed360b 100644 (file)
@@ -12,9 +12,6 @@ use Scalar::Util 'blessed';
 
 use base 'Class::MOP::Mixin';
 
-sub _attribute_map      { $_[0]->{'attributes'} }
-sub attribute_metaclass { $_[0]->{'attribute_metaclass'} }
-
 sub add_attribute {
     my $self = shift;
 
index 939cd29..141bfa7 100644 (file)
@@ -15,8 +15,6 @@ use Sub::Name    'subname';
 
 use base 'Class::MOP::Mixin';
 
-sub method_metaclass         { $_[0]->{'method_metaclass'}            }
-sub wrapped_method_metaclass { $_[0]->{'wrapped_method_metaclass'}    }
 sub _meta_method_class       { 'Class::MOP::Method::Meta'             }
 
 sub _add_meta_method {
diff --git a/mop.c b/mop.c
index d1b252b..71c043f 100644 (file)
--- a/mop.c
+++ b/mop.c
@@ -188,14 +188,38 @@ static struct {
     SV *key;
     U32 hash;
 } prehashed_keys[key_last] = {
+    DECLARE_KEY(_expected_method_class),
+    DECLARE_KEY(ISA),
+    DECLARE_KEY(VERSION),
+    DECLARE_KEY(accessor),
+    DECLARE_KEY(associated_class),
+    DECLARE_KEY(associated_metaclass),
+    DECLARE_KEY(associated_methods),
+    DECLARE_KEY(attribute_metaclass),
+    DECLARE_KEY(attributes),
+    DECLARE_KEY(body),
+    DECLARE_KEY(builder),
+    DECLARE_KEY(clearer),
+    DECLARE_KEY(constructor_class),
+    DECLARE_KEY(constructor_name),
+    DECLARE_KEY(definition_context),
+    DECLARE_KEY(destructor_class),
+    DECLARE_KEY(immutable_trait),
+    DECLARE_KEY(init_arg),
+    DECLARE_KEY(initializer),
+    DECLARE_KEY(insertion_order),
+    DECLARE_KEY(instance_metaclass),
+    DECLARE_KEY(is_inline),
+    DECLARE_KEY(method_metaclass),
+    DECLARE_KEY(methods),
     DECLARE_KEY(name),
     DECLARE_KEY(package),
     DECLARE_KEY(package_name),
-    DECLARE_KEY(body),
+    DECLARE_KEY(predicate),
+    DECLARE_KEY(reader),
+    DECLARE_KEY(wrapped_method_metaclass),
+    DECLARE_KEY(writer),
     DECLARE_KEY_WITH_VALUE(package_cache_flag, "_package_cache_flag"),
-    DECLARE_KEY(methods),
-    DECLARE_KEY(VERSION),
-    DECLARE_KEY(ISA),
     DECLARE_KEY_WITH_VALUE(_version, "-version")
 };
 
diff --git a/mop.h b/mop.h
index e30510d..5547745 100644 (file)
--- a/mop.h
+++ b/mop.h
 void mop_call_xs (pTHX_ XSPROTO(subaddr), CV *cv, SV **mark);
 
 typedef enum {
+    KEY__expected_method_class,
+    KEY_ISA,
+    KEY_VERSION,
+    KEY_accessor,
+    KEY_associated_class,
+    KEY_associated_metaclass,
+    KEY_associated_methods,
+    KEY_attribute_metaclass,
+    KEY_attributes,
+    KEY_body,
+    KEY_builder,
+    KEY_clearer,
+    KEY_constructor_class,
+    KEY_constructor_name,
+    KEY_definition_context,
+    KEY_destructor_class,
+    KEY_immutable_trait,
+    KEY_init_arg,
+    KEY_initializer,
+    KEY_insertion_order,
+    KEY_instance_metaclass,
+    KEY_is_inline,
+    KEY_method_metaclass,
+    KEY_methods,
     KEY_name,
     KEY_package,
     KEY_package_name,
-    KEY_body,
+    KEY_predicate,
+    KEY_reader,
+    KEY_wrapped_method_metaclass,
+    KEY_writer,
     KEY_package_cache_flag,
-    KEY_methods,
-    KEY_VERSION,
-    KEY_ISA,
     KEY__version,
     key_last,
 } mop_prehashed_key_t;
diff --git a/xs/Attribute.xs b/xs/Attribute.xs
new file mode 100644 (file)
index 0000000..6314af8
--- /dev/null
@@ -0,0 +1,9 @@
+#include "mop.h"
+
+MODULE = Class::MOP::Attribute   PACKAGE = Class::MOP::Attribute
+
+PROTOTYPES: DISABLE
+
+BOOT:
+    INSTALL_SIMPLE_READER(Attribute, associated_class);
+    INSTALL_SIMPLE_READER(Attribute, associated_methods);
index 4381497..d495a16 100644 (file)
@@ -6,3 +6,13 @@ PROTOTYPES: DISABLE
 
 BOOT:
     INSTALL_SIMPLE_READER(Mixin::AttributeCore, name);
+    INSTALL_SIMPLE_READER(Mixin::AttributeCore, accessor);
+    INSTALL_SIMPLE_READER(Mixin::AttributeCore, reader);
+    INSTALL_SIMPLE_READER(Mixin::AttributeCore, writer);
+    INSTALL_SIMPLE_READER(Mixin::AttributeCore, predicate);
+    INSTALL_SIMPLE_READER(Mixin::AttributeCore, clearer);
+    INSTALL_SIMPLE_READER(Mixin::AttributeCore, builder);
+    INSTALL_SIMPLE_READER(Mixin::AttributeCore, init_arg);
+    INSTALL_SIMPLE_READER(Mixin::AttributeCore, initializer);
+    INSTALL_SIMPLE_READER(Mixin::AttributeCore, definition_context);
+    INSTALL_SIMPLE_READER(Mixin::AttributeCore, insertion_order);
diff --git a/xs/Class.xs b/xs/Class.xs
new file mode 100644 (file)
index 0000000..5c5d5c9
--- /dev/null
@@ -0,0 +1,12 @@
+#include "mop.h"
+
+MODULE = Class::MOP::Class   PACKAGE = Class::MOP::Class
+
+PROTOTYPES: DISABLE
+
+BOOT:
+    INSTALL_SIMPLE_READER(Class, instance_metaclass);
+    INSTALL_SIMPLE_READER(Class, immutable_trait);
+    INSTALL_SIMPLE_READER(Class, constructor_class);
+    INSTALL_SIMPLE_READER(Class, constructor_name);
+    INSTALL_SIMPLE_READER(Class, destructor_class);
diff --git a/xs/Generated.xs b/xs/Generated.xs
new file mode 100644 (file)
index 0000000..57db324
--- /dev/null
@@ -0,0 +1,9 @@
+#include "mop.h"
+
+MODULE = Class::MOP::Method::Generated   PACKAGE = Class::MOP::Method::Generated
+
+PROTOTYPES: DISABLE
+
+BOOT:
+    INSTALL_SIMPLE_READER(Method::Generated, is_inline);
+    INSTALL_SIMPLE_READER(Method::Generated, definition_context);
diff --git a/xs/HasAttributes.xs b/xs/HasAttributes.xs
new file mode 100644 (file)
index 0000000..dc59227
--- /dev/null
@@ -0,0 +1,9 @@
+#include "mop.h"
+
+MODULE = Class::MOP::Mixin::HasAttributes   PACKAGE = Class::MOP::Mixin::HasAttributes
+
+PROTOTYPES: DISABLE
+
+BOOT:
+    INSTALL_SIMPLE_READER(Mixin::HasAttributes, attribute_metaclass);
+    INSTALL_SIMPLE_READER_WITH_KEY(Mixin::HasAttributes, _attribute_map, attributes);
index 44bb8d5..0e617eb 100644 (file)
@@ -84,3 +84,5 @@ BOOT:
     mop_method_metaclass     = newSVpvs("method_metaclass");
     mop_associated_metaclass = newSVpvs("associated_metaclass");
     mop_wrap                 = newSVpvs("wrap");
+    INSTALL_SIMPLE_READER(Mixin::HasMethods, method_metaclass);
+    INSTALL_SIMPLE_READER(Mixin::HasMethods, wrapped_method_metaclass);
diff --git a/xs/Inlined.xs b/xs/Inlined.xs
new file mode 100644 (file)
index 0000000..a7f1f56
--- /dev/null
@@ -0,0 +1,8 @@
+#include "mop.h"
+
+MODULE = Class::MOP::Method::Inlined   PACKAGE = Class::MOP::Method::Inlined
+
+PROTOTYPES: DISABLE
+
+BOOT:
+    INSTALL_SIMPLE_READER(Method::Inlined, _expected_method_class);
diff --git a/xs/Instance.xs b/xs/Instance.xs
new file mode 100644 (file)
index 0000000..944caed
--- /dev/null
@@ -0,0 +1,8 @@
+#include "mop.h"
+
+MODULE = Class::MOP::Instance   PACKAGE = Class::MOP::Instance
+
+PROTOTYPES: DISABLE
+
+BOOT:
+    INSTALL_SIMPLE_READER(Instance, associated_metaclass);
index fd4bf1d..5644cd8 100644 (file)
--- a/xs/MOP.xs
+++ b/xs/MOP.xs
@@ -40,10 +40,16 @@ check_version (SV *klass, SV *required_version)
     return ret;
 }
 
+EXTERN_C XS(boot_Class__MOP__Mixin__HasAttributes);
 EXTERN_C XS(boot_Class__MOP__Mixin__HasMethods);
 EXTERN_C XS(boot_Class__MOP__Package);
 EXTERN_C XS(boot_Class__MOP__Mixin__AttributeCore);
 EXTERN_C XS(boot_Class__MOP__Method);
+EXTERN_C XS(boot_Class__MOP__Method__Inlined);
+EXTERN_C XS(boot_Class__MOP__Method__Generated);
+EXTERN_C XS(boot_Class__MOP__Class);
+EXTERN_C XS(boot_Class__MOP__Attribute);
+EXTERN_C XS(boot_Class__MOP__Instance);
 
 MODULE = Class::MOP   PACKAGE = Class::MOP
 
@@ -52,10 +58,16 @@ PROTOTYPES: DISABLE
 BOOT:
     mop_prehash_keys();
 
+    MOP_CALL_BOOT (boot_Class__MOP__Mixin__HasAttributes);
     MOP_CALL_BOOT (boot_Class__MOP__Mixin__HasMethods);
     MOP_CALL_BOOT (boot_Class__MOP__Package);
     MOP_CALL_BOOT (boot_Class__MOP__Mixin__AttributeCore);
     MOP_CALL_BOOT (boot_Class__MOP__Method);
+    MOP_CALL_BOOT (boot_Class__MOP__Method__Inlined);
+    MOP_CALL_BOOT (boot_Class__MOP__Method__Generated);
+    MOP_CALL_BOOT (boot_Class__MOP__Class);
+    MOP_CALL_BOOT (boot_Class__MOP__Attribute);
+    MOP_CALL_BOOT (boot_Class__MOP__Instance);
 
 # use prototype here to be compatible with get_code_info from Sub::Identify
 void