dslinux/user/perl/ext/B/ramblings cc.notes curcop.runtime flip-flop magic reg.alloc runtime.porting

cayenne dslinux_cayenne at user.in-berlin.de
Mon Dec 4 17:59:08 CET 2006


Update of /cvsroot/dslinux/dslinux/user/perl/ext/B/ramblings
In directory antilope:/tmp/cvs-serv17422/ext/B/ramblings

Added Files:
	cc.notes curcop.runtime flip-flop magic reg.alloc 
	runtime.porting 
Log Message:
Adding fresh perl source to HEAD to branch from

--- NEW FILE: reg.alloc ---
while ($i--) {
    foo();
}
exit

    PP code			if i an int register	if i an int but not a
				(i.e. can't be		register (i.e. can be
				implicitly invalidated)	implicitly invalidated)
    nextstate
    enterloop

							
  loop:
    gvsv  GV (0xe6078) *i	validates i		validates i
    postdec			invalidates $i		invalidates $i
    and if_false goto out;
				i valid; $i invalid	i valid; $i invalid

				i valid; $i invalid	i valid; $i invalid
    nextstate
    pushmark
    gv  GV (0xe600c) *foo
    entersub						validates $i; invals i

    unstack
    goto loop:

				i valid; $i invalid
  out:
    leaveloop
    nextstate
    exit

--- NEW FILE: magic ---
sv_magic()
----------
av.c
av_store()
	Storing a non-undef element into an SMAGICAL array, av,
	assigns the equivalent lowercase form of magic (of the first
	MAGIC in the chain) to the value (with obj = av, name = 0 and
	namlen = array index).

gv.c
gv_init()
	Initialising gv assigns '*' magic to it with obj = gv, name =
	GvNAME and namlen = GvNAMELEN.
gv_fetchpv()
	@ISA gets 'I' magic with obj = gv, zero name and namlen.
	%OVERLOAD gets 'A' magic with obj = gv, zero name and namlen.
	$1 to $9, $&, $`, $', $+ get '\0' magic with obj = gv,
	name = GvNAME and namlen = len ( = 1 presumably).
Gv_AMupdate()
	Stashes for overload magic seem to get 'c' magic with obj = 0,
	name = &amt and namlen = sizeof(amt).
hv_magic(hv, gv, how)
	Gives magic how to hv with obj = gv and zero name and namlen.

mg.c
mg_copy(sv, nsv, key, klen)
	Traverses the magic chain of sv. Upper case forms of magic
	(only) are copied across to nsv, preserving obj but using
	name = key and namlen = klen.
magic_setpos()
	LvTARG of a PVLV gets 'g' magic with obj = name = 0 and namlen = pos.

op.c
mod()
	PVLV operators give magic to their targs with
	obj = name = namlen = 0. OP_POS gives '.', OP_VEC gives 'v'
	and OP_SUBSTR gives 'x'.

perl.c
magicname(sym, name, namlen)
	Fetches/creates a GV with name sym and gives it '\0' magic
	with obj = gv, name and namlen as passed.
init_postdump_symbols()
	Elements of the environment get given SVs with 'e' magic.
	obj = sv and name and namlen point to the actual string
	within env.

pp.c
pp_av2arylen()
	$#foo gives '#' magic to the new SV with obj = av and
	name = namlen = 0.
pp_study()
	SV gets 'g' magic with obj = name = namlen = 0.
pp_substr()
	PVLV gets 'x' magic with obj = name = namlen = 0.
pp_vec()
	PVLV gets 'x' magic with obj = name = namlen = 0.

pp_hot.c
pp_match()
	m//g gets 'g' magic with obj = name = namlen = 0.

pp_sys.c
pp_tie()
	sv gets magic with obj = sv and name = namlen = 0.
	If an HV or an AV, it gets 'P' magic, otherwise 'q' magic.
pp_dbmopen()
	'P' magic for the HV just as with pp_tie().
pp_sysread()
	If tainting, the buffer SV gets 't' magic with
	obj = name = namlen = 0.

sv.c
sv_setsv()
	Doing sv_setsv(dstr, gv) gives '*' magic to dstr with
	obj = dstr, name = GvNAME, namlen = GvNAMELEN.

util.c
fbm_compile()
	The PVBM gets 'B' magic with obj = name = namlen = 0 and SvVALID
	is set to indicate that the Boyer-Moore table is valid.
	magic_setbm() just clears the SvVALID flag.

hv_magic()
----------

gv.c
gv_fetchfile()
	With perldb, the HV of a gvfile gv gets 'L' magic with obj = gv.
gv_fetchpv()
	%SIG gets 'S' magic with obj = siggv.
init_postdump_symbols()
	%ENV gets 'E' magic with obj = envgv.

--- NEW FILE: runtime.porting ---
Notes on porting the perl runtime PP engine.
Importance: 1 = who cares?, 10 = vital
Difficulty: 1 = trivial, 10 = very difficult. Level assumes a
reasonable implementation of the SV and OP API already ported.

OP		Import	Diff	Comments
null		10	1
stub		10	1
scalar		10	1
pushmark	10	1	PUSHMARK
wantarray	7	3	cxstack, dopoptosub
const		10	1	
gvsv		10	1	save_scalar
gv		10	1	
gelem		3	3	
padsv		10	2	SAVECLEARSV, provide_ref
padav		10	2
padhv		10	2
padany		1	1
pushre		7	3	pushes an op. Blech.
rv2gv		6	5
rv2sv		10	4
av2arylen	7	3	sv_magic	
rv2cv		8	5	sv_2cv
anoncode	7	6	cv_clone
prototype	4	4	sv_2cv
refgen		8	3
srefgen		8	2
ref		8	3
bless		7	3
backtick	5	4
glob		5	2	do_readline
readline	8	2	do_readline	
rcatline	8	2
regcmaybe	8	1
regcreset	8	1
regcomp		8	9	pregcomp
match		8	10
qr		8	1
subst		8	10
substcont	8	7
trans		7	4	do_trans
sassign		10	3	mg_find, SvSETMAGIC
aassign		10	5	
chop		8	3	do_chop
schop		8	3	do_chop
chomp		8	3	do_chomp
schomp		8	3	do_chomp
defined		10	2
undef		10	3
study		4	5
pos		8	3	PVLV, mg_find
preinc		10	2	sv_inc, SvSETMAGIC
i_preinc
predec		10	2	sv_dec, SvSETMAGIC
i_predec
postinc		10	2	sv_dec, SvSETMAGIC
i_postinc
postdec		10	2	sv_dec, SvSETMAGIC
i_postdec
pow		10	1
multiply	10	1
i_multiply	10	1
divide		10	2
i_divide	10	1
modulo		10	2
i_modulo	10	1
repeat		6	4
add		10	1
i_add		10	1
subtract	10	1
i_subtract	10	1
concat		10	2	mg_get
stringify	10	2	sv_setpvn
left_shift	10	1
right_shift	10	1
lt		10	1
i_lt		10	1
gt		10	1
i_gt		10	1
le		10	1
i_le		10	1
ge		10	1
i_ge		10	1
eq		10	1
i_eq		10	1
ne		10	1
i_ne		10	1
ncmp		10	1
i_ncmp		10	1
slt		10	2
sgt		10	2
sle		10	2
sge		10	2
seq		10	2	sv_eq
sne		10	2
scmp		10	2
bit_and		10	2
bit_xor		10	2
bit_or		10	2
negate		10	3
i_negate	10	1
not		10	1
complement	10	3
atan2		6	1
sin		6	1
cos		6	1
rand		5	2
srand		5	2
exp		6	1
log		6	2
sqrt		6	2
int		10	2
hex		9	2
oct		9	2
abs		10	1
length		10	1
substr		10	4	PVLV
vec		5	4
index		9	3
rindex		9	3
sprintf		9	4	do_sprintf
formline	6	7
ord		6	2	
chr		6	2
crypt		3	2
ucfirst		6	2
lcfirst		6	2
uc		6	2
lc		6	2
quotemeta	6	3
rv2av		10	3	save_svref, mg_get, save_ary
aelemfast	10	2	av_fetch
aelem		10	3
aslice		9	4
each		10	3	hv_iternext
values		10	3	do_kv
keys		10	3	do_kv
delete		10	3
exists		10	3
rv2hv		10	3	save_svref, mg_get, save_ary, do_kv
helem		10	3	save_svref, provide_ref
hslice		9	4
unpack		9	6	lengthy
pack		9	6	lengthy
split		9	9
join		10	4	do_join
list		10	2
lslice		9	4
anonlist	10	2
anonhash	10	3
splice		9	6
push		10	2
pop		10	2
shift		10	2
unshift		10	2
sort		6	7
reverse		9	4
grepstart	6	5	modifies flow of control
grepwhile	6	5	modifies flow of control
mapstart	1	1
mapwhile	6	5	modifies flow of control
range		7	3	modifies flow of control
flip		7	4	modifies flow of control
flop		7	4	modifies flow of control
and		10	3	modifies flow of control
or		10	3	modifies flow of control
xor
cond_expr	10	3	modifies flow of control
andassign	7	3	modifies flow of control
orassign	7	3	modifies flow of control
method		8	5
entersub	10	7
leavesub	10	5
leavesublv
caller		2	8
warn		9	3
die		9	3
reset		2	2
lineseq		1	1
nextstate	10	1	Update stack_sp from cxstack. FREETMPS.
dbstate		3	7		
unstack
enter		10	3	cxstack, ENTER, SAVETMPS, PUSHBLOCK
leave		10	3	cxstack, SAVETMPS, LEAVE, POPBLOCK
scope		1	1
enteriter	9	4	cxstack
iter		9	3	cxstack
enterloop	10	4
leaveloop	10	4
return		10	5
last		9	6
next		9	6
redo		9	6
dump		1	9	pp_goto
goto		6	9
exit		9	2	my_exit
open		9	5	do_open
close		9	3	do_close
pipe_op		7	4
fileno		9	2
umask		4	2
binmode		4	2
tie		5	5	pp_entersub
untie		5	2	sv_unmagic
tied		5	2
dbmopen		4	5
dbmclose	4	2
sselect		4	4
select		7	3
getc		7	2
read		8	2	pp_sysread
enterwrite	4	4	doform
leavewrite	4	5
prtf		4	4	do_sprintf
print		8	6
sysopen		8	2
sysseek		8	2
sysread		8	4
syswrite	8	4	pp_send
send		8	4
recv		8	4	pp_sysread
eof		9	2
tell		9	3
seek		9	2
truncate	8	3
fcntl		8	4	pp_ioctl
ioctl		8	4
flock		8	2
socket		5	3
sockpair	5	3
bind		5	3
connect		5	3
listen		5	3
accept		5	3
shutdown	5	2
gsockopt	5	3	pp_ssockopt
ssockopt	5	3
getsockname	5	3	pp_getpeername
getpeername	5	3
lstat		5	4	pp_stat
stat		5	4	lengthy
ftrread		5	2	cando
ftrwrite	5	2	cando
ftrexec		5	2	cando
fteread		5	2	cando
ftewrite	5	2	cando
fteexec		5	2	cando
ftis		5	2	cando
fteowned	5	2	cando
ftrowned	5	2	cando
ftzero		5	2	cando
ftsize		5	2	cando
ftmtime		5	2	cando
ftatime		5	2	cando
ftctime		5	2	cando
ftsock		5	2	cando
ftchr		5	2	cando
ftblk		5	2	cando
ftfile		5	2	cando
ftdir		5	2	cando
ftpipe		5	2	cando
ftlink		5	2	cando
ftsuid		5	2	cando
ftsgid		5	2	cando
ftsvtx		5	2	cando
fttty		5	2	cando
fttext		5	4
ftbinary	5	4	fttext
chdir
chown
chroot
unlink
chmod
utime
rename
link
symlink
readlink
mkdir
rmdir
open_dir
readdir
telldir
seekdir
rewinddir
closedir
fork
wait
waitpid
system
exec
kill
getppid
getpgrp
setpgrp
getpriority
setpriority
time
tms
localtime
gmtime
alarm
sleep
shmget
shmctl
shmread
shmwrite
msgget
msgctl
msgsnd
msgrcv
semget
semctl
semop
require		6	9	doeval
dofile		6	9	doeval
entereval	6	9	doeval
leaveeval	6	5
entertry	7	4	modifies flow of control
leavetry	7	3
ghbyname
ghbyaddr
ghostent
gnbyname
gnbyaddr
gnetent
gpbyname
gpbynumber
gprotoent
gsbyname
gsbyport
gservent
shostent
snetent
sprotoent
sservent
ehostent
enetent
eprotoent
eservent
gpwnam
gpwuid
gpwent
spwent
epwent
ggrnam
ggrgid
ggrent
sgrent
egrent
getlogin
syscall
lock		6	1
threadsv	6	2	unused if not USE_5005THREADS, absent post 5.8
setstate	1	1	currently unused anywhere
method_named	10	2

--- NEW FILE: flip-flop ---
PP(pp_range)
{
    if (GIMME == G_ARRAY)
        return NORMAL;
    if (SvTRUEx(PAD_SV(PL_op->op_targ)))
	return cLOGOP->op_other;
    else
	return NORMAL;
}

pp_range is a LOGOP.
In list context, it just returns op_next.
In scalar context it checks the truth of targ and returns
op_other if true, op_next if false.

flip is an UNOP.
It "looks after" its child which is always a pp_range LOGOP.
In list context, it just returns the child's op_other.
In scalar context, there are three possible outcomes:
  (1) set child's targ to 1, our targ to 1 and return op_next.
  (2) set child's targ to 1, our targ to 0, sp-- and return child's op_other.
  (3) Blank targ and  TOPs and return op_next.
Case 1 happens for a "..." with a matching lineno... or true TOPs.
Case 2 happens for a ".." with a matching lineno... or true TOPs.
Case 3 happens for a non-matching lineno or false TOPs.

               $a = lhs..rhs;

        ,------->  range
        ^         /     \
        |    true/       \false
        |       /         \
   first|     lhs        rhs
        |      \   first   /
        ^--- flip <----- flop
                 \       /
                  \     /
                  sassign


/* range */
if (SvTRUE(curpad[op->op_targ]))
    goto label(op_other);
/* op_next */
...
/* flip */
/* For "..." returns op_next. For ".." returns op_next or op_first->op_other */
/* end of basic block */
goto out;
label(range op_other):
...
/* flop */
out:
...

--- NEW FILE: cc.notes ---
At entry to each basic block, the following can be assumed (and hence
must be forced where necessary at the end of each basic block):

The shadow stack @stack is empty.
For each lexical object in @pad, VALID_IV holds for each T_INT,
VALID_DOUBLE holds for each T_DOUBLE and VALID_SV holds otherwise.
The C shadow variable sp holds the stack pointer (not necessarily stack_sp).

write_back_stack
    Writes the contents of the shadow stack @stack back to the real stack.
    A write-back of each object in the stack is forced so that its
    backing SV contains the right value and that SV is then pushed onto the
    real stack. On return, @stack is empty.

write_back_lexicals
    Forces a write-back (i.e. achieves VALID_SV), where necessary, for each
    lexical object in @pad. Objects with the TEMPORARY flag are skipped. If
    write_back_lexicals is called with an (optional) argument, then it is
    taken to be a bitmask of more flags: any lexical object with one of those
    flags set is also skipped and not written back to its SV.

invalidate_lexicals($avoid)
    The VALID_INT and VALID_DOUBLE flags are turned off for each lexical
    object in @pad whose flags field doesn't overlap with $avoid.

reload_lexicals
    For each necessary lexical object in @pad, makes sure that VALID_IV
    holds for objects of type T_INT, VALID_DOUBLE holds for objects for
    type T_DOUBLE, and VALID_SV holds for other objects. An object is
    considered for reloading if its flags field does not overlap with the
    (optional) argument passed to reload_lexicals.


--- NEW FILE: curcop.runtime ---
PP code uses of curcop
----------------------

pp_rv2gv
	when a new glob is created for an OPpLVAL_INTRO,
	curcop->cop_line is stored as GvLINE() in the new GP.
pp_bless
	curcop->cop_stash is used as the stash in the one-arg form of bless

pp_repeat
	tests (curcop != &compiling) to warn "Can't x= to readonly value"

pp_pos
pp_substr
pp_index
pp_rindex
pp_aslice
pp_lslice
pp_splice
	curcop->cop_arybase

pp_sort
	curcop->cop_stash used to determine whether to gv_fetchpv $a and $b

pp_caller
	tests (curcop->cop_stash == debstash) to determine whether
	to set DB::args

pp_reset
	resets vars in curcop->cop_stash

pp_dbstate
	sets curcop = (COP*)op

doeval
	compiles into curcop->cop_stash

pp_nextstate
	sets curcop = (COP*)op




More information about the dslinux-commit mailing list