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

left_shift problem

Thread Next
Reini Urban
March 23, 2008 15:45
left_shift problem
Message ID:
Im writing the perloptreeguts document at
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
     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);

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 

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

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About