develooper Front page | perl.perl5.porters | Postings from March 2008

left_shift problem

Thread Next
From:
Reini Urban
Date:
March 23, 2008 15:45
Subject:
left_shift problem
Message ID:
47E6DDA6.1020201@x-ray.at
Im writing the perloptreeguts document at 
http://www.perlfoundation.org/perl5/index.cgi?optree_guts
I got stuck at the first simple, and most innocent looking op I tried to 
use as an example.

left_shift	left bitshift (<<)	ck_bitop	fsT2	S S
PP(pp_left_shift)
{
     dVAR; dSP; dATARGET; tryAMAGICbin(lshift,opASSIGN);
     {
       const IV shift = POPi;
       if (PL_op->op_private & HINT_INTEGER) {
	const IV i = TOPi;
	SETi(i << shift);
       }
       else {
	const UV u = TOPu;
	SETu(u << shift);
       }
       RETURN;
     }
}

What makes we wonder is why the IV/UV discrimination is stored in the op 
(PL_op->op_private & HINT_INTEGER), and not taken from the type of the 
1st arg at TOPi - 1st pop, 2nd arg -, which is here also used as return 
value.

To my lisp trained eye, the signedness should be taken dynamically from 
the variable, and not stored at compile-time in the function.

At compile-time the compiler must check the type of the arg and store it 
in the left_shift op. But what is when the type of the arg is upgraded 
from an IV to an UV? Or vice versa.
Is this possible, or is the IV guaranteed to be static?
Or, what if the arg is a UV, but the op has HINT_INTEGER?
Well, it is degraded to a signed than.
-- 
Reini Urban
http://phpwiki.org/  http://murbreak.at/

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About