Ticket #1001: boolean_dead_instantiate.patch

File boolean_dead_instantiate.patch, 1.8 KB (added by flh, 12 years ago)
  • src/pmc/boolean.pmc

     
    2525 
    2626/* 
    2727 
    28 =item C<PMC *instantiate(PMC *sig)> 
     28=item C<void init_pmc(PMC *value)> 
    2929 
    30 Object constructor. SELF is a Boolean Class object. Return a new 
    31 C<bool> object according to the passed PMC value. 
     30Initialises SELF value according to the boolean value of the passed PMC. 
    3231 
    3332=cut 
    3433 
    3534*/ 
    36     VTABLE PMC *instantiate(PMC *sig) { 
    37         /* XXX other types */ 
    38         const int argcP = REG_INT(interp, 3); 
    39         PMC * const res = pmc_new(interp, enum_class_Boolean); 
    40  
    41         if (argcP) 
    42             SELF.set_bool(VTABLE_get_bool(interp, REG_PMC(interp, 5))); 
    43  
    44         return PMCNULL; /* TODO */ 
     35    VTABLE void init_pmc(PMC *value) { 
     36        if (!PMC_IS_NULL(value)) { 
     37            SELF.set_bool(VTABLE_get_bool(INTERP, value)); 
     38        } 
     39        else { 
     40            SELF.set_bool(0); 
     41        } 
    4542    } 
    4643/* 
    4744 
  • t/pmc/boolean.t

     
    1919 
    2020.sub main :main 
    2121    .include 'test_more.pir' 
    22     plan(28) 
     22    plan(30) 
    2323    init_int_tests() 
     24    instantiate_tests() 
    2425    num_tests() 
    2526    string_tests() 
    2627    pmc_to_pmc_tests() 
     
    4647    is($I0, 1, "Boolean converts negative int to true") 
    4748.end 
    4849 
     50.sub instantiate_tests 
     51    $P0 = new ['Boolean'] 
     52 
     53    $P0 = 1 
     54    $P2 = get_class ['Boolean'] 
     55    $P1 = new $P2, $P0 
     56    $I0 = $P1 
     57    is($I0, 1, "Boolean instantiated to true") 
     58 
     59    $P0 = 0 
     60    $P1 = new ['Boolean'], $P0 
     61    $I0 = $P1 
     62    is($I0, 0, "Boolean instantiated to false") 
     63.end 
     64 
    4965.sub num_tests 
    5066 
    5167    $P0 = new ['Boolean']