# New Ticket Created by François PERRAD # Please include the string: [perl #61286] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=61286 >
The new opcode 'box' is limited by its 3 signatures that target Float, Integer & String. I propose the 3 following new opcodes : - true - false - undef or nil (less Perlish) After some experiments with bytecode translation, in WMLScript (r33655) and in Lua (r33760), it seems obvious that we need them. François.
Index: src/ops/pmc.ops =================================================================== --- src/ops/pmc.ops (revision 33750) +++ src/ops/pmc.ops (working copy) @@ -607,6 +607,29 @@ VTABLE_set_string_native(interp, $1, $2); } +=item B<true>(out PMC) + +=item B<false>(out PMC) + +=item B<undef>(out PMC) + +Create a literal HLL-mapped PMC. + +=cut + +op true(out PMC) { + $1 = pmc_new(interp, Parrot_get_ctx_HLL_type(interp, enum_class_Boolean)); + VTABLE_set_bool(interp, $1, 1); +} + +op false(out PMC) { + $1 = pmc_new(interp, Parrot_get_ctx_HLL_type(interp, enum_class_Boolean)); +} + +op undef(out PMC) { + $1 = pmc_new(interp, Parrot_get_ctx_HLL_type(interp, enum_class_Undef)); +} + =back =head1 COPYRIGHT Index: t/op/box.t =================================================================== --- t/op/box.t (revision 33750) +++ t/op/box.t (working copy) @@ -16,13 +16,15 @@ =cut -.const int TESTS = 24 +.const int TESTS = 34 # must set these up before the .HLL_map statements later .sub '__setup' :immediate $P0 = subclass 'Integer', 'MyInt' $P0 = subclass 'String', 'MyString' $P0 = subclass 'Float', 'MyFloat' + $P0 = subclass 'Boolean', 'MyBoolean' + $P0 = subclass 'Undef', 'MyUndef' .end .sub 'main' :main @@ -33,6 +35,9 @@ 'box_int'() 'box_num'() 'box_string'() + 'true_'() + 'false_'() + 'undef_'() .local pmc box_int_hll box_int_hll = get_root_global [ 'for_test' ], 'box_int' @@ -43,9 +48,21 @@ .local pmc box_string_hll box_string_hll = get_root_global [ 'for_test' ], 'box_string' + .local pmc true_hll + true_hll = get_root_global [ 'for_test' ], 'true_' + + .local pmc false_hll + false_hll = get_root_global [ 'for_test' ], 'false_' + + .local pmc undef_hll + undef_hll = get_root_global [ 'for_test' ], 'undef_' + box_int_hll() box_num_hll() box_string_hll() + true_hll() + false_hll() + undef_hll() .end .sub 'box_int' @@ -92,14 +109,37 @@ isa_ok( $P0, 'String', 'string boxed to appropriate base type from reg' ) .end +.sub 'true_' + $P0 = true + $I0 = $P0 + is( $I0, 1, 'good value' ) + + isa_ok( $P0, 'Boolean', 'good base type' ) +.end + +.sub 'false_' + $P0 = false + $I0 = $P0 + is( $I0, 0, 'good value' ) + + isa_ok( $P0, 'Boolean', 'good base type' ) +.end + +.sub 'undef_' + $P0 = undef + $I0 = $P0 + isa_ok( $P0, 'Undef', 'good base type' ) +.end + .HLL 'for_test' .HLL_map 'Integer' = 'MyInt' .HLL_map 'String' = 'MyString' .HLL_map 'Float' = 'MyFloat' +.HLL_map 'Boolean' = 'MyBoolean' +.HLL_map 'Undef' = 'MyUndef' .sub 'box_int' - .include 'include/test_more.pir' $P0 = box -100 $I0 = $P0 is( $I0, -100, 'value preserved when boxing int in HLL' ) @@ -144,6 +184,27 @@ isa_ok($P0, 'MyString', 'string boxed to appropriate type for HLL from reg') .end +.sub 'true_' + $P0 = true + $I0 = $P0 + is( $I0, 1, 'good value in HLL' ) + + isa_ok( $P0, 'MyBoolean', 'good base type for HLL' ) +.end + +.sub 'true_' + $P0 = true + $I0 = $P0 + is( $I0, 1, 'good value in HLL' ) + + isa_ok( $P0, 'MyBoolean', 'good base type for HLL' ) +.end + +.sub 'undef_' + $P0 = undef + isa_ok( $P0, 'MyUndef', 'good base type for HLL' ) +.end + # Local Variables: # mode: cperl # cperl-indent-level: 4