[svn:parrot] r41791 - in branches/pcc_optimize_sig: src/pmc t/pmc
allison at svn.parrot.org
allison at svn.parrot.org
Sat Oct 10 10:54:02 UTC 2009
Author: allison
Date: Sat Oct 10 10:54:02 2009
New Revision: 41791
URL: https://trac.parrot.org/parrot/changeset/41791
Log:
[pcc] Copying over CallSignature PMC and tests for independent development.
Modified:
branches/pcc_optimize_sig/src/pmc/callsignature.pmc
branches/pcc_optimize_sig/t/pmc/callsignature.t
Modified: branches/pcc_optimize_sig/src/pmc/callsignature.pmc
==============================================================================
--- branches/pcc_optimize_sig/src/pmc/callsignature.pmc Sat Oct 10 10:33:56 2009 (r41790)
+++ branches/pcc_optimize_sig/src/pmc/callsignature.pmc Sat Oct 10 10:54:02 2009 (r41791)
@@ -28,9 +28,11 @@
PARROT_CAPTURE(obj)->hash = pmc_new((i), enum_class_Hash);
pmclass CallSignature extends Capture auto_attrs provides array provides hash {
- ATTR PMC *returns; /* Result PMCs, if they were passed with the call */
- ATTR PMC *type_tuple; /* Cached argument types for multiple dispatch */
- ATTR STRING *short_sig; /* Simple string signature args & returns */
+ ATTR PMC *results; /* Storage for return arguments */
+ ATTR PMC *type_tuple; /* Cached argument types for multiple dispatch */
+ ATTR STRING *short_sig; /* Simple string signature args & returns */
+ ATTR PMC *arg_flags; /* Integer array of argument flags */
+ ATTR PMC *return_flags; /* Integer array of return argument flags */
/*
@@ -47,7 +49,7 @@
(Parrot_CallSignature_attributes *) PMC_data(SELF);
SUPER();
sig_struct->type_tuple = PMCNULL;
- sig_struct->returns = PMCNULL;
+ sig_struct->results = PMCNULL;
}
/*
@@ -128,10 +130,20 @@
=over
-=item returns
+=item results
Stores the return signature, an array of PMCs.
+=item arg_flags
+
+Stores a set of flags for the call signature arguments, an array of
+integers.
+
+=item return_flags
+
+Stores a set of flags for the call signature return arguments, an array
+of integers.
+
=back
=cut
@@ -139,8 +151,24 @@
*/
VTABLE void set_attr_str(STRING *key, PMC *value) {
- Parrot_CallSignature_attributes * const sig_struct = PARROT_CALLSIGNATURE(SELF);
- sig_struct->returns = value;
+
+ if (Parrot_str_equal(INTERP, key, CONST_STRING(INTERP, "results"))) {
+ SET_ATTR_results(interp, SELF, value);
+ }
+ else if (Parrot_str_equal(INTERP, key, CONST_STRING(INTERP, "returns"))) {
+ SET_ATTR_results(interp, SELF, value);
+ }
+ else if (Parrot_str_equal(INTERP, key, CONST_STRING(INTERP, "arg_flags"))) {
+ SET_ATTR_arg_flags(interp, SELF, value);
+ }
+ else if (Parrot_str_equal(INTERP, key, CONST_STRING(INTERP, "return_flags"))) {
+ SET_ATTR_return_flags(interp, SELF, value);
+ }
+ else {
+ /* If unknown attribute name, throw an exception. */
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_ATTRIB_NOT_FOUND,
+ "No such attribute '%S'", key);
+ }
}
/*
@@ -151,10 +179,24 @@
=over
-=item returns
+=item results
Retrieves the return signature, an array of PMCs.
+=item arg_flags
+
+Retrieves the flags for the call signature arguments, an array of
+integers.
+
+=item return_flags
+
+Retrieves the flags for the call signature return arguments, an array of
+integers.
+
+=item named
+
+Retrieves the hash of named arguments.
+
=back
=cut
@@ -162,8 +204,30 @@
*/
VTABLE PMC *get_attr_str(STRING *key) {
- Parrot_CallSignature_attributes * const sig_struct = PARROT_CALLSIGNATURE(SELF);
- return sig_struct->returns;
+ PMC *value = PMCNULL;
+
+ if (Parrot_str_equal(INTERP, key, CONST_STRING(INTERP, "results"))) {
+ GET_ATTR_results(interp, SELF, value);
+ }
+ else if (Parrot_str_equal(INTERP, key, CONST_STRING(INTERP, "returns"))) {
+ GET_ATTR_results(interp, SELF, value);
+ }
+ else if (Parrot_str_equal(INTERP, key, CONST_STRING(INTERP, "arg_flags"))) {
+ GET_ATTR_arg_flags(interp, SELF, value);
+ }
+ else if (Parrot_str_equal(INTERP, key, CONST_STRING(INTERP, "return_flags"))) {
+ GET_ATTR_return_flags(interp, SELF, value);
+ }
+ else if (Parrot_str_equal(INTERP, key, CONST_STRING(INTERP, "named"))) {
+ GET_ATTR_hash(interp, SELF, value);
+ }
+ else {
+ /* If unknown attribute name, throw an exception. */
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_ATTRIB_NOT_FOUND,
+ "No such attribute '%S'", key);
+ }
+
+ return value;
}
/*
@@ -178,11 +242,14 @@
VTABLE void mark() {
Parrot_CallSignature_attributes * const attrs = PARROT_CALLSIGNATURE(SELF);
- if (attrs) {
- Parrot_gc_mark_PMC_alive(interp, attrs->returns);
- Parrot_gc_mark_PMC_alive(interp, attrs->type_tuple);
- Parrot_gc_mark_STRING_alive(interp, attrs->short_sig);
- }
+ if (!attrs)
+ return;
+
+ Parrot_gc_mark_PMC_alive(interp, attrs->results);
+ Parrot_gc_mark_PMC_alive(interp, attrs->type_tuple);
+ Parrot_gc_mark_STRING_alive(interp, attrs->short_sig);
+ Parrot_gc_mark_PMC_alive(interp, attrs->arg_flags);
+ Parrot_gc_mark_PMC_alive(interp, attrs->return_flags);
SUPER();
}
Modified: branches/pcc_optimize_sig/t/pmc/callsignature.t
==============================================================================
--- branches/pcc_optimize_sig/t/pmc/callsignature.t Sat Oct 10 10:33:56 2009 (r41790)
+++ branches/pcc_optimize_sig/t/pmc/callsignature.t Sat Oct 10 10:54:02 2009 (r41791)
@@ -19,19 +19,42 @@
.sub main :main
.include 'test_more.pir'
- plan(1)
+ plan(7)
- instantiate()
+ test_instantiate()
+ test_get_set_attrs()
.end
-.sub instantiate
-
+.sub test_instantiate
$P0 = new ['CallSignature']
ok(1, 'Instantiated CallSignature')
+.end
+.sub test_get_set_attrs
+ $P0 = new ['CallSignature']
+ $P5 = new 'String'
+
+ $P5 = 'foobar'
+ setattribute $P0, 'returns', $P5
+ ok(1, 'set returns attribute')
+ getattribute $P1, $P0, 'returns'
+ is($P1,'foobar', 'got returns attribute')
+
+ $P5 = 'moonbomb'
+ setattribute $P0, 'return_flags', $P5
+ ok(1, 'set return_flags attribute')
+ getattribute $P1, $P0, 'return_flags'
+ is($P5,'moonbomb', 'got return_flags attribute')
+
+ $P5 = 'cheese'
+ setattribute $P0, 'arg_flags', $P5
+ ok(1, 'set arg_flags attribute')
+ getattribute $P1, $P0, 'arg_flags'
+ is($P5,'cheese', 'got arg_flags attribute')
.end
+
# Local Variables:
# mode: pir
# fill-column: 100
More information about the parrot-commits
mailing list