[svn:parrot] r41743 - branches/pcc_reapply/src/call
allison at svn.parrot.org
allison at svn.parrot.org
Tue Oct 6 21:21:39 UTC 2009
Author: allison
Date: Tue Oct 6 21:21:38 2009
New Revision: 41743
URL: https://trac.parrot.org/parrot/changeset/41743
Log:
[pcc] Some logic fixes to the returns handling. Even though args==returns and
params==results, the code can't be translated directly by performing that text
substitution, because the logic is reversed for return/result handling. So,
fill_results needs to iterate over the array of results and the flags from the
returns. (This is the reverse of arg/param handling, which iterates over the
array of args and the flags of the params.) The fill_results function currently
also has to track the flags of the results, to detect slurpy results. It would
be better to mark "slurpy" on the CPointer, so we don't have to track two data
structures to get the result information.
Modified:
branches/pcc_reapply/src/call/args.c
Modified: branches/pcc_reapply/src/call/args.c
==============================================================================
--- branches/pcc_reapply/src/call/args.c Tue Oct 6 21:10:37 2009 (r41742)
+++ branches/pcc_reapply/src/call/args.c Tue Oct 6 21:21:38 2009 (r41743)
@@ -1354,7 +1354,7 @@
PMC *ctx = CURRENT_CONTEXT(interp);
PMC *named_used_list = PMCNULL;
INTVAL return_count = VTABLE_elements(interp, raw_sig);
- INTVAL result_count;
+ INTVAL positional_result_count;
INTVAL positional_returns = 0; /* initialized by a loop later */
INTVAL i = 0; /* used by the initialization loop */
STRING *result_name = NULL;
@@ -1379,14 +1379,14 @@
if (err_check)
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"too few returns: 0 passed, %d expected",
- result_count);
+ positional_result_count);
}
return;
}
positional_result_list = VTABLE_get_attr_str(interp, call_object, CONST_STRING(interp, "returns"));
result_sig = VTABLE_get_attr_str(interp, call_object, CONST_STRING(interp, "return_flags"));
- result_count = VTABLE_elements(interp, result_sig);
+ positional_result_count = VTABLE_elements(interp, positional_result_list);
/* the call obj doesn't have the returns as positionals, so instead we loop
* over raw_sig and count the number of non-named
@@ -1407,10 +1407,11 @@
PMC *result_item;
INTVAL constant;
- /* Check if we've used up all the results. */
- if (result_index >= result_count) {
- if (return_index >= positional_returns) {
- /* We've used up all the returns and results, we're done. */
+ /* Check if we've used up all the returns. */
+ if (return_index >= return_count) {
+ if (result_index >= positional_result_count) {
+ /* We've used up all the positional returns and results, we're
+ * done with this loop. */
break;
}
else if (err_check) {
@@ -1418,7 +1419,7 @@
* returns left over. */
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"too many positional returns: %d passed, %d expected",
- positional_returns, result_index);
+ return_index, positional_result_count);
}
return;
}
@@ -1444,7 +1445,8 @@
collect_positional = pmc_new(interp,
Parrot_get_ctx_HLL_type(interp, enum_class_ResizablePMCArray));
- for (; return_index < positional_returns; return_index++) {
+ /* Iterate over all positional arguments in the returns list. */
+ while (!(return_flags & PARROT_ARG_NAME)) {
return_flags = VTABLE_get_integer_keyed_int(interp, raw_sig, return_index);
constant = PARROT_ARG_CONSTANT_ISSET(return_flags);
switch (PARROT_ARG_TYPE_MASK_MASK(return_flags)) {
@@ -1473,6 +1475,7 @@
EXCEPTION_INVALID_OPERATION, "invalid return type");
break;
}
+ return_index++;
}
VTABLE_set_pmc(interp, result_item, collect_positional);
result_index++;
@@ -1480,13 +1483,11 @@
}
/* We have a positional return, fill the result with it. */
- if (return_index < positional_returns) {
+ if (result_index < positional_result_count) {
/* Fill a named result with a positional return. */
if (result_flags & PARROT_ARG_NAME) {
STRING *result_name;
- Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
- "named returns NYI");
if (!(result_flags & PARROT_ARG_STRING))
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
"named results must have a name specified");
@@ -1495,7 +1496,7 @@
: *accessor->string(interp, return_info, result_index);
named_count++;
result_index++;
- if (result_index >= result_count)
+ if (result_index >= positional_result_count)
continue;
result_flags = VTABLE_get_integer_keyed_int(interp,
raw_sig, result_index);
@@ -1556,7 +1557,7 @@
if (result_flags & PARROT_ARG_OPTIONAL) {
INTVAL next_result_flags;
- if (result_index + 1 < result_count) {
+ if (result_index + 1 < positional_result_count) {
next_result_flags = VTABLE_get_integer_keyed_int(interp,
raw_sig, result_index + 1);
if (next_result_flags & PARROT_ARG_OPT_FLAG) {
@@ -1580,7 +1581,7 @@
/* Mark the option flag for the result to FALSE, it was filled
* with a default value. */
- if (result_index + 1 < result_count) {
+ if (result_index + 1 < positional_result_count) {
next_result_flags = VTABLE_get_integer_keyed_int(interp,
raw_sig, result_index + 1);
if (next_result_flags & PARROT_ARG_OPT_FLAG) {
@@ -1615,7 +1616,7 @@
/* Check if we've used up all the results. We'll check for leftover
* named returns after the loop. */
- if (result_index >= result_count)
+ if (result_index >= positional_result_count)
break;
result_flags = VTABLE_get_integer_keyed_int(interp, raw_sig, result_index);
@@ -1674,7 +1675,7 @@
if (!STRING_IS_NULL(result_name)) {
/* The next result is the actual value. */
result_index++;
- if (result_index >= result_count)
+ if (result_index >= positional_result_count)
continue;
result_flags = VTABLE_get_integer_keyed_int(interp, raw_sig, result_index);
@@ -1714,7 +1715,7 @@
if (result_flags & PARROT_ARG_OPTIONAL) {
INTVAL next_result_flags;
- if (result_index + 1 < result_count) {
+ if (result_index + 1 < positional_result_count) {
next_result_flags = VTABLE_get_integer_keyed_int(interp,
raw_sig, result_index + 1);
if (next_result_flags & PARROT_ARG_OPT_FLAG) {
@@ -1731,7 +1732,7 @@
/* Mark the option flag for the result to FALSE, it was filled
* with a default value. */
- if (result_index + 1 < result_count) {
+ if (result_index + 1 < positional_result_count) {
next_result_flags = VTABLE_get_integer_keyed_int(interp,
raw_sig, result_index + 1);
if (next_result_flags & PARROT_ARG_OPT_FLAG) {
More information about the parrot-commits
mailing list