Ticket #1001: boolean_dead_instantiate.patch
File boolean_dead_instantiate.patch, 1.8 KB (added by flh, 12 years ago) |
---|
-
src/pmc/boolean.pmc
25 25 26 26 /* 27 27 28 =item C< PMC *instantiate(PMC *sig)>28 =item C<void init_pmc(PMC *value)> 29 29 30 Object constructor. SELF is a Boolean Class object. Return a new 31 C<bool> object according to the passed PMC value. 30 Initialises SELF value according to the boolean value of the passed PMC. 32 31 33 32 =cut 34 33 35 34 */ 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 } 45 42 } 46 43 /* 47 44 -
t/pmc/boolean.t
19 19 20 20 .sub main :main 21 21 .include 'test_more.pir' 22 plan( 28)22 plan(30) 23 23 init_int_tests() 24 instantiate_tests() 24 25 num_tests() 25 26 string_tests() 26 27 pmc_to_pmc_tests() … … 46 47 is($I0, 1, "Boolean converts negative int to true") 47 48 .end 48 49 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 49 65 .sub num_tests 50 66 51 67 $P0 = new ['Boolean']