World: r3wp
[rebcode] Rebcode discussion
older newer | first last |
BrianH 20-Feb-2007 [1678] | You can do code snippets for your emulation/debugger, and concatenation for direct execution. |
Steeve 20-Feb-2007 [1679] | it's what i do |
BrianH 20-Feb-2007 [1680x2] | As long as you are careful the semantics shouldn't change. |
Remember that these branch statements group statements together into basic blocks, so you should break up your code into snippets on boundaries between these blocks. | |
Steeve 20-Feb-2007 [1682x2] | that why i don't use branch statements |
branchements are controled outside rebcodes functions | |
BrianH 20-Feb-2007 [1684x2] | For non-generated code, the only useful branch statement in rebcode is BRAB. All others have better structured equivalents. |
BTW, the English word for branchements is branches. | |
Steeve 20-Feb-2007 [1686x2] | i have a main loop wich do the branchements and call the rebcode routines |
sorry | |
BrianH 20-Feb-2007 [1688x2] | Just trying to help :) |
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 [1726x2] | i know but i have some constraint do to my parser |
anyway, with rebcode i changed my way | |
older newer | first last |