develooper Front page | perl.perl6.internals | Postings from June 2001

should vtables be vtables?

Thread Next
From:
Dave Mitchell
Date:
June 13, 2001 04:00
Subject:
should vtables be vtables?
Message ID:
200106131100.MAA01855@gizmo.fdgroup.co.uk
mad thought for the day:

I was thinking back to the earlier discusions on opcode dispatch,
and the fact that some people thought that a big switch was as good as,
or possibly faster than a dispatch table. Which led me to think...

should we abandon vtables (ie arrays of fn pointers indexed by op),
and just have a single hander function per type which has the op as an arg?

Then each type is free to handle things as it likes - from having its own
private dispatch table, to having a big switch statement, to having just
a single "if (IS_MODIFY_OP(op)) .. else ...." statement for a copy-on-write
wrapper type.

The big problem would be handling the variable number of args, but this
could be solved by passing a singe pointer to a block of args - ie
extending PDD 2's idea of the key array, to include the other args as
well.  This might be a win (easy for lightweight wrapper types like
copy-on-write to pass the same args to the real type below), or a loss
(lots of time wasted marshalling args). One of the main jobs of the
optimiser might end up being to maintain a scrathpad area of the
regiser file for use as by the arg pointer, in such as way that it
needs to be modified as little as possible between opcodes.

I think the biggest advantage to having a single handler function is that
it becomes very easy to create lightweight wrapper types without having
to construct a whopping big vtable each time.

For example:

readonly type:	if its a read op, pass on to underlying type, otherwise carp().
copy-on-write:	if its a write op, call clone(); then pass on to underlying
		type.
for $i (@a):	$i might be set to a simple iterator type that passes it's
		args plus the current index to the underlying array object.


But there are probably lots of disadvantages too that simply havent
occured to me...


Dave. 


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