[svn:parrot] r48789 - in trunk/src: ops pmc
chromatic at svn.parrot.org
chromatic at svn.parrot.org
Sat Sep 4 18:29:27 UTC 2010
Author: chromatic
Date: Sat Sep 4 18:29:27 2010
New Revision: 48789
URL: https://trac.parrot.org/parrot/changeset/48789
Log:
[ops] Gutted addattribute thanks to polymorphism.
The default PMC now throws an exception for invalid use of addattribute
because, truly, it's the invocant PMC's responsibility to do something sane or
explain why it won't.
Modified:
trunk/src/ops/core_ops.c
trunk/src/ops/object.ops
trunk/src/pmc/default.pmc
Modified: trunk/src/ops/core_ops.c
==============================================================================
--- trunk/src/ops/core_ops.c Sat Sep 4 18:13:04 2010 (r48788)
+++ trunk/src/ops/core_ops.c Sat Sep 4 18:29:27 2010 (r48789)
@@ -20453,32 +20453,14 @@
opcode_t *
Parrot_addattribute_p_s(opcode_t *cur_opcode, PARROT_INTERP) {
const Parrot_Context * const CUR_CTX = Parrot_pcc_get_context_struct(interp, interp->ctx);
- STRING * const class_name = string_from_literal(interp, "Class");
- STRING * const role_name = string_from_literal(interp, "Role");
-
- if (VTABLE_isa(interp, PREG(1), class_name) || VTABLE_isa(interp, PREG(1), role_name))
- VTABLE_add_attribute(interp, PREG(1), SREG(2), PMCNULL);
- else {
- opcode_t *handler = Parrot_ex_throw_from_op_args(interp, NULL,
- EXCEPTION_INVALID_OPERATION,
- "Cannot add attribute to non-class");return (opcode_t *)handler;
- }
+ VTABLE_add_attribute(interp, PREG(1), SREG(2), PMCNULL);
return (opcode_t *)cur_opcode + 3;}
opcode_t *
Parrot_addattribute_p_sc(opcode_t *cur_opcode, PARROT_INTERP) {
const Parrot_Context * const CUR_CTX = Parrot_pcc_get_context_struct(interp, interp->ctx);
- STRING * const class_name = string_from_literal(interp, "Class");
- STRING * const role_name = string_from_literal(interp, "Role");
-
- if (VTABLE_isa(interp, PREG(1), class_name) || VTABLE_isa(interp, PREG(1), role_name))
- VTABLE_add_attribute(interp, PREG(1), CONST(2).u.string, PMCNULL);
- else {
- opcode_t *handler = Parrot_ex_throw_from_op_args(interp, NULL,
- EXCEPTION_INVALID_OPERATION,
- "Cannot add attribute to non-class");return (opcode_t *)handler;
- }
+ VTABLE_add_attribute(interp, PREG(1), CONST(2).u.string, PMCNULL);
return (opcode_t *)cur_opcode + 3;}
Modified: trunk/src/ops/object.ops
==============================================================================
--- trunk/src/ops/object.ops Sat Sep 4 18:13:04 2010 (r48788)
+++ trunk/src/ops/object.ops Sat Sep 4 18:29:27 2010 (r48789)
@@ -463,17 +463,7 @@
=cut
inline op addattribute(invar PMC, in STR) :object_classes {
- STRING * const class_name = string_from_literal(interp, "Class");
- STRING * const role_name = string_from_literal(interp, "Role");
-
- if (VTABLE_isa(interp, $1, class_name) || VTABLE_isa(interp, $1, role_name))
- VTABLE_add_attribute(interp, $1, $2, PMCNULL);
- else {
- opcode_t *handler = Parrot_ex_throw_from_op_args(interp, NULL,
- EXCEPTION_INVALID_OPERATION,
- "Cannot add attribute to non-class");
- goto ADDRESS(handler);
- }
+ VTABLE_add_attribute(interp, $1, $2, PMCNULL);
}
=item B<removeattribute>(invar PMC, in STR) B<(unimplemented)>
Modified: trunk/src/pmc/default.pmc
==============================================================================
--- trunk/src/pmc/default.pmc Sat Sep 4 18:13:04 2010 (r48788)
+++ trunk/src/pmc/default.pmc Sat Sep 4 18:29:27 2010 (r48789)
@@ -533,6 +533,22 @@
/*
+=item C<void PMC *add_attribute(STRING *name, PMC *type)>
+
+Throws an exception, as you can only add an attribute to something Class-y or
+Role-y.
+
+=cut
+
+*/
+
+ VTABLE void add_attribute(STRING *name, PMC *type) {
+ Parrot_ex_throw_from_c_args(INTERP, NULL, EXCEPTION_INVALID_OPERATION,
+ "Cannot add attribute to non-class");
+ }
+
+/*
+
=item C<PMC *get_namespace>
Return the namespace for this PMC.
More information about the parrot-commits
mailing list