World: r3wp
[rebcode] Rebcode discussion
older newer | first last |
BrianH 20-Feb-2007 [1689] | Are you doing a compiler or an interpreter? A compiler would be faster, but would require you to translate branches. |
Steeve 20-Feb-2007 [1690x2] | it's an hybrid way |
i try to do the two things | |
BrianH 20-Feb-2007 [1692] | A JIT compiler, perhaps? |
Maxim 20-Feb-2007 [1693x2] | sort of like a JIT ? |
hehe | |
Steeve 20-Feb-2007 [1695x3] | first i parse Z80 opcodes and execute them step by step, then they are concatened to build sub-routines and cached, if sub-routines are mantory another time, then i call cached sub-routines instead of reparse the opcodes. |
*mandatory | |
(requested is better) | |
BrianH 20-Feb-2007 [1698] | Do you do basic block analysis of the source opcodes to determine where the subroutine boundaries are? For that matter, does the Z80 have indirect branches? |
Steeve 20-Feb-2007 [1699] | ;-_- |
BrianH 20-Feb-2007 [1700] | Sorry, I don't speak IRC. |
Steeve 20-Feb-2007 [1701x2] | yes indirect branches exist |
but it's not a problem, the management of branches is done in real time, it's in a stack, so i can manage fixed as indirect branches. | |
BrianH 20-Feb-2007 [1703] | How common are they? Can you analyze them to determine their destinations to convert them into branches or calls? |
Steeve 20-Feb-2007 [1704x2] | all branches are converted into call |
difficult to explain with my bad english | |
BrianH 20-Feb-2007 [1706x2] | Call of function or continuation? (Sorry if your English doesn't include computer-science terms) |
Meaning, does the call return? | |
Steeve 20-Feb-2007 [1708x2] | when i seek a Z80 branch opcode (direct or indirect), i stop the current rebcode function construction and i build new one for the folowing opcodes |
so each rebcode function (routines) must return the adress of the next branch | |
BrianH 20-Feb-2007 [1710x2] | Continuation then. |
How do you handle back-branches then? | |
Steeve 20-Feb-2007 [1712x2] | if a routine return an unknwon adress, then the parser jump a these adress and rebuild a new function. |
back-branches are treated in the same manner | |
BrianH 20-Feb-2007 [1714] | So, no basic block analysis at all. All branches are considered non-local. |
Steeve 20-Feb-2007 [1715] | yep |
BrianH 20-Feb-2007 [1716] | Would it be too difficult to translate branches to literal offsets into their rebcode equivalents, as an optimization? |
Steeve 20-Feb-2007 [1717x3] | here you can see my first try without rebcode http://perso.orange.fr/rebol/galaga.r |
i could try this as a final compilation step, perhaps | |
in the source you can see the concept of branches management i use | |
BrianH 20-Feb-2007 [1720] | Your trick of generating words for branch targets may need changing when you switch to rebcode. Pre-2.7 versions of REBOL had hard limits on the number of words possible at once (about 8000). You might consider issue! values instead with a lookup table (probably a hash!). |
Steeve 20-Feb-2007 [1721] | ok |
BrianH 20-Feb-2007 [1722x2] | It will be a little slower. You might then return references to the code rather than the names. |
That will cut down on lookups. Make it threaded. | |
Steeve 20-Feb-2007 [1724] | i think i will implement a cached routines cleaner (GC) , to keep in memory only routines which are frequently requested |
BrianH 20-Feb-2007 [1725] | There are some optimizations you can make to the code too, such as changing code like this: set [v1 v2] reduce [_d _e] to this: v1: _d v2: _e |
Steeve 20-Feb-2007 [1726x3] | i know but i have some constraint do to my parser |
anyway, with rebcode i changed my way | |
*due to | |
BrianH 20-Feb-2007 [1729] | No block set. |
Steeve 20-Feb-2007 [1730x4] | i know |
currently a rebuild the parser to generate rebcode instead of rebol instructions | |
*currently i | |
so i don' t use set block anymore ;-) | |
BrianH 20-Feb-2007 [1734] | It occurs to me that you might be able to do the fixups using a compile-time lookup table, or perhaps translating addresses to label statements. |
Steeve 20-Feb-2007 [1735x2] | i agree |
i add this to my to-do list | |
BrianH 20-Feb-2007 [1737] | It also occurs to me that you could assemble your own code and modify the code blocks at runtime to make lookups unnecessary. |
Steeve 20-Feb-2007 [1738] | but there's some difficulties toing that in real time |
older newer | first last |