[svn:parrot] r41555 - trunk/src/pmc
bacek at svn.parrot.org
bacek at svn.parrot.org
Tue Sep 29 12:44:38 UTC 2009
Author: bacek
Date: Tue Sep 29 12:44:38 2009
New Revision: 41555
URL: https://trac.parrot.org/parrot/changeset/41555
Log:
[core] Implement Exception.backtrace in terms of Context.backtrace
Modified:
trunk/src/pmc/context.pmc
trunk/src/pmc/exception.pmc
Modified: trunk/src/pmc/context.pmc
==============================================================================
--- trunk/src/pmc/context.pmc Tue Sep 29 12:25:37 2009 (r41554)
+++ trunk/src/pmc/context.pmc Tue Sep 29 12:44:38 2009 (r41555)
@@ -203,14 +203,12 @@
=cut
-XXX Stolen from Exception.backtrace. Only one difference in handling C<cont>
-TODO Investigate and implement Exception.backtrace in terms of Context.backtrace.
-
*/
- METHOD backtrace() {
+ METHOD backtrace(PMC *resume :optional, INTVAL has_resume :opt_flag) {
PMC *result = pmc_new(interp, enum_class_ResizablePMCArray);
PMC *cur_ctx = SELF;
+ Parrot_Continuation_attributes *cont = has_resume ? PMC_cont(resume) : NULL;
/* Get starting context, then loop over them. */
while (cur_ctx) {
@@ -232,7 +230,9 @@
if (sub->seg->annotations) {
PackFile_ByteCode *seg = sub->seg;
- opcode_t *pc = Parrot_pcc_get_pc(interp, cur_ctx);
+ opcode_t *pc = cont && cur_ctx == cont->to_ctx
+ ? cont->address
+ : Parrot_pcc_get_pc(interp, cur_ctx);
annotations = PackFile_Annotations_lookup(interp,
seg->annotations, pc - seg->base.data,
Modified: trunk/src/pmc/exception.pmc
==============================================================================
--- trunk/src/pmc/exception.pmc Tue Sep 29 12:25:37 2009 (r41554)
+++ trunk/src/pmc/exception.pmc Tue Sep 29 12:44:38 2009 (r41555)
@@ -742,53 +742,13 @@
/* We have a resume continuation, so we can get the address from
* that. */
cont = PARROT_CONTINUATION(resume);
- cur_ctx = cont->to_ctx;
+ Parrot_pcc_invoke_method_from_c_args(INTERP, cont->to_ctx, CONST_STRING(interp, "backtrace"), "P->P", resume, &result);
}
else {
/* No return continuation. Assuming we're being called */
cont = NULL;
GET_ATTR_thrower(interp, SELF, cur_ctx);
- }
-
- {
- while (cur_ctx) {
- PMC *frame = pmc_new(interp, enum_class_Hash);
- PMC *annotations = NULL;
- Parrot_Sub_attributes *sub;
-
- /* Get sub and put it in the hash. */
- PMC *sub_pmc = Parrot_pcc_get_sub(interp, cur_ctx);
-
- if (!sub_pmc)
- sub_pmc = PMCNULL;
-
- VTABLE_set_pmc_keyed_str(interp, frame, CONST_STRING(interp, "sub"), sub_pmc);
-
- /* Look up any annotations and put them in the hash. */
- if (!PMC_IS_NULL(sub_pmc)) {
- PMC_get_sub(interp, sub_pmc, sub);
-
- if (sub->seg->annotations) {
- PackFile_ByteCode *seg = sub->seg;
- opcode_t *pc = cont && cur_ctx == cont->to_ctx
- ? cont->address
- : Parrot_pcc_get_pc(interp, cur_ctx);
-
- annotations = PackFile_Annotations_lookup(interp,
- seg->annotations, pc - seg->base.data,
- NULL);
- }
- }
-
- if (!annotations)
- annotations = pmc_new(interp, enum_class_Hash);
-
- VTABLE_set_pmc_keyed_str(interp, frame, CONST_STRING(interp, "annotations"), annotations);
-
- /* Push frame and go to next caller. */
- VTABLE_push_pmc(interp, result, frame);
- cur_ctx = Parrot_pcc_get_caller_ctx(interp, cur_ctx);
- }
+ Parrot_pcc_invoke_method_from_c_args(INTERP, CURRENT_CONTEXT(INTERP), CONST_STRING(interp, "backtrace"), "->P", &result);
}
RETURN(PMC *result);
More information about the parrot-commits
mailing list