luser-dr00g / xpost

A PostScript interpreter in C
Other
93 stars 12 forks source link

optimize typechecks and polymorphic dispatch from procedure bodies in `bind` #37

Open luser-dr00g opened 8 years ago

luser-dr00g commented 8 years ago

bind is the postscript call to create an optimized, read-only procedure body.

We can add an additional optimization to the usual replacement of names with operator objects, and that is: input/output type analysis and removal of internal typechecks. As a simple example, the mod operator, if its inputs are correct, produces an integertype object, so if a procedure begins with the sequence mod copy ... say, then we know that this is the integer-case of copy and don't need to do dynamic typechecking and polymorphic dispatch at runtime to select the correct integer-case function; we can factor this out to a different representation at bind time.

One complication is that the procedure body remains accessible as a regular postscript array, so any operator objects extracted, using get perhaps, must decay back to their fully-typechecked, polymorphic version.