On Sat, Sep 6, 2008 at 3:34 AM, Christoph Otto via RT
<[EMAIL PROTECTED]> wrote:
> On Sat Feb 16 17:23:47 2008, coke wrote:
>> The example in the PDD now reads:
>>
>> $P0 = new 'String'
>> $P0 = "something bad happened"
>> $P1 = new ['parrot';'exception'], $P0 # create new exception object
>> throw $P1 # throw it
>>
>
>
> This code continues to not work. Would it be DTRT to copy/pasta some
> code from t/pmc/exception.t, such as the "throw - no handler" test?
The attached patch makes it work. It also allows:
$P0 = new 'Hash'
$P0 ['severity'] = 1
$P0 ['message'] = 'something bad happened'
$P1 = new ['parrot';'exception'], $P0 # create new exception object
throw $P1 # throw it
Not sure if this is the desired design. Comments?
--
Salu2
Index: src/pmc/exception.pmc
===================================================================
--- src/pmc/exception.pmc (revision 30822)
+++ src/pmc/exception.pmc (working copy)
@@ -101,6 +101,40 @@
/*
+=item C<void init_pmc()>
+
+Initializes the exception with supplied values.
+
+=cut
+
+*/
+
+ VTABLE void init_pmc(PMC *values) {
+ Parrot_Exception * const core_struct =
+ mem_allocate_zeroed_typed(Parrot_Exception);
+ INTVAL ishash = VTABLE_isa(interp, values, CONST_STRING(interp, 'Hash'));
+
+ /* Set flags for custom DOD mark and destroy. */
+ PObj_custom_mark_SET(SELF);
+ PObj_active_destroy_SET(SELF);
+
+ /* Set up the core struct and default values for the exception object. */
+ PMC_data(SELF) = core_struct;
+ core_struct->severity = ishash ?
+ VTABLE_get_integer_keyed_str(interp, values, CONST_STRING(interp, 'severity')) :
+ 0;
+ core_struct->handled = 0;
+ core_struct->message = ishash ?
+ VTABLE_get_string_keyed_str(interp, values, CONST_STRING(interp, 'message')) :
+ VTABLE_get_string(interp, values);
+ core_struct->payload = PMCNULL;
+ core_struct->resume = PMCNULL;
+ core_struct->stacktrace = PMCNULL;
+ core_struct->handler_iter = PMCNULL;
+ }
+
+/*
+
=item C<void mark()>
Mark any active exception data as live.