[svn:parrot] r41834 - in branches/pcc_reapply: include/parrot src/call src/pmc
tene at svn.parrot.org
tene at svn.parrot.org
Mon Oct 12 23:08:08 UTC 2009
Author: tene
Date: Mon Oct 12 23:08:04 2009
New Revision: 41834
URL: https://trac.parrot.org/parrot/changeset/41834
Log:
[pcc]
* Handle positional returns in continuations, kind of.
* This is kind of evil; feel free to revert.
Modified:
branches/pcc_reapply/include/parrot/call.h
branches/pcc_reapply/src/call/args.c
branches/pcc_reapply/src/pmc/continuation.pmc
Modified: branches/pcc_reapply/include/parrot/call.h
==============================================================================
--- branches/pcc_reapply/include/parrot/call.h Mon Oct 12 09:08:16 2009 (r41833)
+++ branches/pcc_reapply/include/parrot/call.h Mon Oct 12 23:08:04 2009 (r41834)
@@ -307,6 +307,16 @@
FUNC_MODIFIES(*call_object);
PARROT_EXPORT
+void Parrot_pcc_fill_returns_from_continuation(PARROT_INTERP,
+ ARGMOD_NULLOK(PMC *call_object),
+ ARGIN(PMC *raw_sig),
+ ARGIN(PMC *from_call_obj))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(3)
+ __attribute__nonnull__(4)
+ FUNC_MODIFIES(*call_object);
+
+PARROT_EXPORT
void Parrot_pcc_fill_returns_from_op(PARROT_INTERP,
ARGMOD_NULLOK(PMC *call_object),
ARGIN(PMC *raw_sig),
@@ -344,6 +354,11 @@
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(signature))
+#define ASSERT_ARGS_Parrot_pcc_fill_returns_from_continuation \
+ __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(raw_sig) \
+ , PARROT_ASSERT_ARG(from_call_obj))
#define ASSERT_ARGS_Parrot_pcc_fill_returns_from_op \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
Modified: branches/pcc_reapply/src/call/args.c
==============================================================================
--- branches/pcc_reapply/src/call/args.c Mon Oct 12 09:08:16 2009 (r41833)
+++ branches/pcc_reapply/src/call/args.c Mon Oct 12 23:08:04 2009 (r41834)
@@ -138,6 +138,13 @@
__attribute__nonnull__(2);
PARROT_CANNOT_RETURN_NULL
+static INTVAL intval_arg_from_continuation(PARROT_INTERP,
+ ARGIN(PMC *cs),
+ INTVAL arg_index)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+PARROT_CANNOT_RETURN_NULL
static INTVAL intval_arg_from_op(PARROT_INTERP,
ARGIN(opcode_t *raw_args),
INTVAL arg_index)
@@ -178,6 +185,13 @@
__attribute__nonnull__(2);
PARROT_CANNOT_RETURN_NULL
+static FLOATVAL numval_arg_from_continuation(PARROT_INTERP,
+ ARGIN(PMC *cs),
+ INTVAL arg_index)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+PARROT_CANNOT_RETURN_NULL
static FLOATVAL numval_arg_from_op(PARROT_INTERP,
ARGIN(opcode_t *raw_args),
INTVAL arg_index)
@@ -230,6 +244,13 @@
__attribute__nonnull__(2);
PARROT_CANNOT_RETURN_NULL
+static PMC* pmc_arg_from_continuation(PARROT_INTERP,
+ ARGIN(PMC *cs),
+ INTVAL arg_index)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+PARROT_CANNOT_RETURN_NULL
static PMC* pmc_arg_from_op(PARROT_INTERP,
ARGIN(opcode_t *raw_args),
INTVAL arg_index)
@@ -272,6 +293,13 @@
__attribute__nonnull__(2);
PARROT_CANNOT_RETURN_NULL
+static STRING* string_arg_from_continuation(PARROT_INTERP,
+ ARGIN(PMC *cs),
+ INTVAL arg_index)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+PARROT_CANNOT_RETURN_NULL
static STRING* string_arg_from_op(PARROT_INTERP,
ARGIN(opcode_t *raw_args),
INTVAL arg_index)
@@ -339,6 +367,9 @@
#define ASSERT_ARGS_intval_arg_from_c_args __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(args))
+#define ASSERT_ARGS_intval_arg_from_continuation __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(cs))
#define ASSERT_ARGS_intval_arg_from_op __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(raw_args))
@@ -357,6 +388,9 @@
#define ASSERT_ARGS_numval_arg_from_c_args __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(args))
+#define ASSERT_ARGS_numval_arg_from_continuation __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(cs))
#define ASSERT_ARGS_numval_arg_from_op __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(raw_args))
@@ -380,6 +414,9 @@
#define ASSERT_ARGS_pmc_arg_from_c_args __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(args))
+#define ASSERT_ARGS_pmc_arg_from_continuation __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(cs))
#define ASSERT_ARGS_pmc_arg_from_op __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(raw_args))
@@ -398,6 +435,9 @@
#define ASSERT_ARGS_string_arg_from_c_args __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(args))
+#define ASSERT_ARGS_string_arg_from_continuation __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(cs))
#define ASSERT_ARGS_string_arg_from_op __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(raw_args))
@@ -2046,6 +2086,59 @@
return;
}
+/*
+
+=item C<void Parrot_pcc_fill_returns_from_continuation(PARROT_INTERP, PMC
+*call_object, PMC *raw_sig, PMC *from_call_obj)>
+
+Evil function. Fill results from arguments passed to a continuation.
+Only works for positional arguments.
+
+=cut
+
+*/
+
+PARROT_EXPORT
+void
+Parrot_pcc_fill_returns_from_continuation(PARROT_INTERP, ARGMOD_NULLOK(PMC *call_object),
+ ARGIN(PMC *raw_sig), ARGIN(PMC *from_call_obj))
+{
+ ASSERT_ARGS(Parrot_pcc_fill_returns_from_continuation)
+ INTVAL raw_return_count = VTABLE_elements(interp, raw_sig);
+ INTVAL err_check = 0;
+ static pcc_get_funcs function_pointers = {
+ (intval_func_t)intval_arg_from_continuation,
+ (numval_func_t)numval_arg_from_continuation,
+ (string_func_t)string_arg_from_continuation,
+ (pmc_func_t)pmc_arg_from_continuation,
+
+ (intval_func_t)intval_arg_from_continuation,
+ (numval_func_t)numval_arg_from_continuation,
+ (string_func_t)string_arg_from_continuation,
+ (pmc_func_t)pmc_arg_from_continuation,
+ };
+
+
+ /* Check if we should be throwing errors. This is configured separately
+ * for parameters and return values. */
+ if (PARROT_ERRORS_test(interp, PARROT_ERRORS_RESULT_COUNT_FLAG))
+ err_check = 1;
+
+ /* A null call object is fine if there are no arguments and no returns. */
+ if (PMC_IS_NULL(call_object)) {
+ if (raw_return_count > 0) {
+ if (err_check)
+ Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
+ "too many return values: %d passed, 0 expected",
+ raw_return_count);
+ }
+ return;
+ }
+
+ fill_results(interp, call_object, raw_sig, from_call_obj, &function_pointers);
+
+ return;
+}
/*
@@ -2296,6 +2389,42 @@
PARROT_CANNOT_RETURN_NULL
static INTVAL
+intval_arg_from_continuation(PARROT_INTERP, ARGIN(PMC *cs), INTVAL arg_index)
+{
+ ASSERT_ARGS(intval_arg_from_continuation)
+ const INTVAL ret = VTABLE_get_integer_keyed_int(interp, cs, arg_index);
+ return ret;
+}
+
+PARROT_CANNOT_RETURN_NULL
+static FLOATVAL
+numval_arg_from_continuation(PARROT_INTERP, ARGIN(PMC *cs), INTVAL arg_index)
+{
+ ASSERT_ARGS(numval_arg_from_continuation)
+ const FLOATVAL ret = VTABLE_get_number_keyed_int(interp, cs, arg_index);
+ return ret;
+}
+
+PARROT_CANNOT_RETURN_NULL
+static STRING*
+string_arg_from_continuation(PARROT_INTERP, ARGIN(PMC *cs), INTVAL arg_index)
+{
+ ASSERT_ARGS(string_arg_from_continuation)
+ const STRING *ret = VTABLE_get_string_keyed_int(interp, cs, arg_index);
+ return ret;
+}
+
+PARROT_CANNOT_RETURN_NULL
+static PMC*
+pmc_arg_from_continuation(PARROT_INTERP, ARGIN(PMC *cs), INTVAL arg_index)
+{
+ ASSERT_ARGS(pmc_arg_from_continuation)
+ const PMC *ret = VTABLE_get_pmc_keyed_int(interp, cs, arg_index);
+ return ret;
+}
+
+PARROT_CANNOT_RETURN_NULL
+static INTVAL
intval_arg_from_op(PARROT_INTERP, ARGIN(opcode_t *raw_args), INTVAL arg_index)
{
ASSERT_ARGS(intval_arg_from_op)
Modified: branches/pcc_reapply/src/pmc/continuation.pmc
==============================================================================
--- branches/pcc_reapply/src/pmc/continuation.pmc Mon Oct 12 09:08:16 2009 (r41833)
+++ branches/pcc_reapply/src/pmc/continuation.pmc Mon Oct 12 23:08:04 2009 (r41834)
@@ -241,35 +241,16 @@
PMC *from_ctx = CURRENT_CONTEXT(interp);
PMC *to_ctx = cc->to_ctx;
opcode_t *pc = cc->address;
+ PMC *call_obj = Parrot_pcc_get_signature(interp, to_ctx);
+ PMC *from_obj = Parrot_pcc_get_signature(interp, from_ctx);
+ PMC *raw_sig = VTABLE_get_attr_str(interp, from_obj, CONST_STRING(interp, "arg_flags"));
UNUSED(next)
Parrot_continuation_check(interp, SELF);
Parrot_continuation_rewind_environment(interp, SELF);
-#if 0
- FIXME FIXME FIXME Continuation results passing should be updated. Or maybe fully removed?
- /* pass args to where caller wants result */
- if (cc->current_results)
- Parrot_pcc_set_results(interp, to_ctx, cc->current_results);
-
- if (Parrot_pcc_get_results(interp, to_ctx) && INTERP->current_args) {
- /*
- * the register pointer is already switched back
- * to the caller, therefore the registers of the
- * sub we are returning from aren't marked, if
- * inside argument passing a GC run is triggered
- * therefore we have to block GC
- */
- opcode_t *src_indexes = interp->current_args;
- opcode_t *dest_indexes = Parrot_pcc_get_results(interp, to_ctx);
- interp->current_args = NULL;
-
- Parrot_block_GC_mark(INTERP);
- parrot_pass_args(INTERP, from_ctx, to_ctx,
- src_indexes, dest_indexes, PARROT_PASS_PARAMS);
- Parrot_unblock_GC_mark(INTERP);
- }
-#endif
+ Parrot_pcc_fill_returns_from_continuation(interp, call_obj, raw_sig, from_obj);
+
/* switch segment */
INTERP->current_args = NULL;
More information about the parrot-commits
mailing list