[svn:parrot] r38878 - branches/tt504_annotations/src/pmc
bacek at svn.parrot.org
bacek at svn.parrot.org
Sun May 17 21:33:01 UTC 2009
Author: bacek
Date: Sun May 17 21:33:00 2009
New Revision: 38878
URL: https://trac.parrot.org/parrot/changeset/38878
Log:
Proposed changes to PackfileAnnotations/PackfileAnnotation.
Modified:
branches/tt504_annotations/src/pmc/packfileannotation.pmc
branches/tt504_annotations/src/pmc/packfileannotations.pmc
Modified: branches/tt504_annotations/src/pmc/packfileannotation.pmc
==============================================================================
--- branches/tt504_annotations/src/pmc/packfileannotation.pmc Sun May 17 21:03:10 2009 (r38877)
+++ branches/tt504_annotations/src/pmc/packfileannotation.pmc Sun May 17 21:33:00 2009 (r38878)
@@ -22,9 +22,13 @@
#include "parrot/parrot.h"
pmclass PackfileAnnotation {
- ATTR INTVAL value;
- ATTR INTVAL offset;
- ATTR INTVAL key_id;
+ ATTR STRING *name;
+ ATTR INTVAL offset;
+ ATTR INTVAL value_type;
+ /* This 3 attributes should be in single union. But Pmc2c isn't smart enough to handle it */
+ ATTR INTVAL int_value;
+ ATTR FLOATVAL num_value;
+ ATTR STRING *str_value;
/*
@@ -95,30 +99,30 @@
/*
-=item C<INTVAL get_key_id()>
+=item C<STRING* get_name()>
-Fetch the ID of the key of the annotation.
+Fetch the name of the annotation.
=cut
*/
- METHOD get_key_id() {
- INTVAL key_id = PARROT_PACKFILEANNOTATION(SELF)->key_id;
- RETURN(INTVAL key_id);
+ METHOD get_name() {
+ STRING * name = PARROT_PACKFILEANNOTATION(SELF)->name;
+ RETURN(STRING * name);
}
/*
-=item C<void set_key_id(INTVAL key_id)>
+=item C<void set_name(STRING* name)>
-Set the ID of the key of the annotation.
+Set the name of the annotation.
=cut
*/
- METHOD set_key_id(INTVAL key_id) {
- PARROT_PACKFILEANNOTATION(SELF)->key_id = key_id;
+ METHOD set_name(STRING * name) {
+ PARROT_PACKFILEANNOTATION(SELF)->name = name;
}
@@ -126,27 +130,99 @@
=item C<INTVAL get_integer()>
-Fetch the value of the annotation.
+Fetch the integer value of the annotation.
=cut
*/
VTABLE INTVAL get_integer() {
- return PARROT_PACKFILEANNOTATION(SELF)->value;
+ Parrot_PackfileAnnotation_attributes * attrs = PARROT_PACKFILEANNOTATION(SELF);
+ if (attrs->value_type != PF_ANNOTATION_KEY_TYPE_INT)
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
+ "Trying to fetch wrong type of value from annotation");
+ return attrs->int_value;
}
/*
-=item C<void set_integer(INTVAL value)>
+=item C<void set_integer_native(INTVAL value)>
-Set the value of the annotation.
+Set the integer value of the annotation.
=cut
*/
VTABLE void set_integer_native(INTVAL value) {
- PARROT_PACKFILEANNOTATION(SELF)->value = value;
+ Parrot_PackfileAnnotation_attributes * attrs = PARROT_PACKFILEANNOTATION(SELF);
+ attrs->value_type = PF_ANNOTATION_KEY_TYPE_INT;
+ attrs->int_value = value;
+ }
+
+/*
+
+=item C<STRING * get_string()>
+
+Fetch the string value of the annotation.
+
+=cut
+
+*/
+ VTABLE STRING * get_string() {
+ Parrot_PackfileAnnotation_attributes * attrs = PARROT_PACKFILEANNOTATION(SELF);
+ if (attrs->value_type != PF_ANNOTATION_KEY_TYPE_STR)
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
+ "Trying to fetch wrong type of value from annotation");
+ return attrs->str_value;
+ }
+
+
+/*
+
+=item C<void set_string_native(STRING * value)>
+
+Set the string value of the annotation.
+
+=cut
+
+*/
+ VTABLE void set_string_native(STRING * value) {
+ Parrot_PackfileAnnotation_attributes * attrs = PARROT_PACKFILEANNOTATION(SELF);
+ attrs->value_type = PF_ANNOTATION_KEY_TYPE_STR;
+ attrs->str_value = value;
+ }
+
+/*
+
+=item C<INTVAL get_number()>
+
+Fetch the float value of the annotation.
+
+=cut
+
+*/
+ VTABLE FLOATVAL get_number() {
+ Parrot_PackfileAnnotation_attributes * attrs = PARROT_PACKFILEANNOTATION(SELF);
+ if (attrs->value_type != PF_ANNOTATION_KEY_TYPE_NUM)
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
+ "Trying to fetch wrong type of value from annotation");
+ return attrs->num_value;
+ }
+
+
+/*
+
+=item C<void set_number_native(INTVAL value)>
+
+Set the float value of the annotation.
+
+=cut
+
+*/
+ VTABLE void set_number_native(FLOATVAL value) {
+ Parrot_PackfileAnnotation_attributes * attrs = PARROT_PACKFILEANNOTATION(SELF);
+ attrs->value_type = PF_ANNOTATION_KEY_TYPE_NUM;
+ attrs->num_value = value;
}
}
Modified: branches/tt504_annotations/src/pmc/packfileannotations.pmc
==============================================================================
--- branches/tt504_annotations/src/pmc/packfileannotations.pmc Sun May 17 21:03:10 2009 (r38877)
+++ branches/tt504_annotations/src/pmc/packfileannotations.pmc Sun May 17 21:33:00 2009 (r38878)
@@ -233,12 +233,15 @@
annotation = pmc_new(interp, enum_class_PackfileAnnotation);
/* Poke directly to annotation attributes. */
+ /* FIXME We should just create proper Annotations */
+ /*
annotation_attrs = PARROT_PACKFILEANNOTATION(annotation);
annotation_attrs->value = a->entries[i]->value;
annotation_attrs->key_id = a->entries[i]->key;
annotation_attrs->offset = a->entries[i]->bytecode_offset;
VTABLE_set_pmc_keyed_int(interp, attrs->annotations, i, annotation);
+ */
}
}
@@ -263,6 +266,8 @@
res->base.type = PF_ANNOTATIONS_SEG;
/* Copy keys */
+ /* FIXME We should create PackFile_Annotations_Keys here from Annotation */
+ /*
num = VTABLE_elements(interp, attrs->keys);
res->num_keys = num;
res->keys = mem_allocate_n_typed(num, PackFile_Annotations_Key*);
@@ -273,8 +278,10 @@
"I->I", i, &res->keys[i]->name);
res->keys[i]->type = VTABLE_get_integer_keyed_int(interp, attrs->keys, i);
}
+ */
/* Copy entities */
+ /*
num = VTABLE_elements(interp, attrs->annotations);
res->num_entries = num;
res->entries = mem_allocate_n_typed(num, PackFile_Annotations_Entry*);
More information about the parrot-commits
mailing list