World: r3wp
[rebcode] Rebcode discussion
older newer | first last |
Robert 5-Nov-2005 [1189] | Ok, you got the code? |
Volker 5-Nov-2005 [1190] | No. or lost. |
Robert 5-Nov-2005 [1191] | Ok, I send it to you. I have serveral versions, one using faces, one using draw (but has problems with layout that doesn't converge). IMO a version using draw and rebcode would be nice. |
Volker 5-Nov-2005 [1192] | the code is then public? since i can then develop public too. |
Robert 5-Nov-2005 [1193x2] | Send to Gmail account. |
Yep, no problem. | |
Volker 5-Nov-2005 [1195] | thanks |
Romano 5-Nov-2005 [1196] | BrianH: my argument is: case 1) given a block of absolute jump [ 15 36 40 46] and 2 statement added at line 37 i can adjust the block easy, case2 ) given a block of relative jump [-10 -5 15 30] and 2 statement added at line 37 i must know also the starting jump position, calc the new position of jump after the addition of code, calc (directly or indirectly) the absolute adresses of jumps , make the same work for case 1, and transform back jumps in relatives ones. A lot of work and a more information needed. |
Volker 5-Nov-2005 [1197] | maybe relative addresses are shorter than absolute ones? absolutes need 32/64bit, relatives 8. |
Gregg 5-Nov-2005 [1198] | Thanks Brian! |
BrianH 5-Nov-2005 [1199x4] | Any time Gregg! In particular, every time changes are made to the engine or docs :) |
Romano, I feel your pain. If you look at the history in this group, you will find that I have gone into great detail about how much I feel your pain :( | |
But given your cases here, keep in mind that the only instruction now that takes a block of offsets is BRAB. As I have said above, BRAB with relative jumps means that it is only practical to use an offset block from a single branch statement. Branching to a block referenced by a word is only practical for rather obscure circumatances (for instance a multistate machine). So for most code using brab the offset block will be placed right there in the statement., so you will definitely know the starting position. But your second case is a little off, because with relative jumps, you don't need to know the absolute position of anything. Assuming a branch offset block like the one in your second case, the relevant section of the code block you are using starts with the beginning position of the first target statement and ends with the beginning position of the last target statement. Branch offsets are calculated relative to the end of the branch statement, a position we will call the source. With relative jumps, you don't have to take into account the absolute position of the end of the branch statement, you just need to count the positions between the source source and the target. You don't need to know that any added instructions are on line 37 (a meaningless concept in rebcode because lines are ignored), you only need to tell whether the added instructions are in between the source and the target, and then increase the offsets on that side of the branch accordingly. For most branches you will probably be better off with labels and let the assembler do the work. But for code snippets, what I often do is just do the intiial writing with labels, put the code in a rebcode block and let the assembler do the offset calculations. Then I copy the fixed up code, remove any label statements and adjust affected offsets by two for every removed label statement. Let the assembler do most of the work. | |
(sorry, that could have used a little more proofreading) | |
Romano 6-Nov-2005 [1203x2] | maybe relative addresses are shorter than absolute ones? absolutes need 32/64bit, relatives 8 rebcode use 32 bit for relative jumps |
Brianh: tell me how to adjust the brab block [-10 -5 15 30] knowing that the statement "add a 1" has been added at index 37 (you do no like "line") in the same block in which brab appears. You do not know the absolute position of the brab block. | |
BrianH 6-Nov-2005 [1205x4] | Is the index 37 position relative to the beginning of the entire code block that contains the brab statement, or relative to the statement targeted by the -10 offset in your brab offset block? The "affected area" of your brab statement is the 40 instructions beginning with the one pointed to by the -10 and ending with that pointed to by the 30. This is also referred to as a "basic block". When your branches are relative, this area is the one that you should be concerned with. If you are counting your insertion index relative to the affected area then the only offset affected by the insertion would be the 30, which would need to be changed to 33. If you are counting your index of 37 as an absolute offset (actually, relative to the beginning of the code block that contains the branch statement), then you need to subtract the absolute offset of the branch statement to convert to the offset scale that matters, that relative to the branch statement. Coincidently, that is exactly the calculation performed by the label fixup phase of the assembler. Because of this I tend to suggest that when you are programming based on the whole code block, typical of programming-by-hand, that you use label statements and branch to them. When you use literal offsets you have to consider the range of instructions from the branch to the target as being one entity, a "basic block". When inserting instructions into a basic block, all you need to consider is how it affects that segment of code. These code segments are usually developed and tested independently, and then dropped whole into the greater stream of code without much change. Programming by stringing together a set of these basic blocks (or code snippets) is often what code-generating dialect processor (or "compiler") does. |
An optimizer does just the opposite: It converts the literal offset to a kind of virtual label statement (the difference being that the virtual one takes no space in the code); then after code insertions or deletes have happened, it changes the offsets to their new values, just like rerunning the fixup phase of the assembler. Of course optimizations like this can get a little more complicated when you have branch targets calculated at runtime - this was probably why they added BRAB and removed BRAW in the recent release, replacing general branch calculations with a simple lookup table. | |
As for whether the relative offsets are more efficient than absolute, that is only true of actual machine code, and then maybe only on older processors without an instruction cache. What we are calling an absolute offset here isn't a memory address like it is in machine code, it is really just an offset relative to the beginning of the code block, rather than the location of the branch statement. I think that the reason Carl chose offsets relative to the location of the branch statement is that he decided to only implement one branch method in the VM, and this method is more friendly to generated code (or maybe that was just luck). | |
Offsets relative to a fixed location are the (currently theoretical) "special case" of the BRAB statement. See RAMBO 3953 for details. | |
Gabriele 8-Nov-2005 [1209x2] | that case is no more theoretical, see new build. however, i don't think it has been tested much so far. |
so, the first argument of brab can now be either a literal block (with labels or integers), or a label. the second arg can only be a word referring to an integer. | |
Rebolek 8-Nov-2005 [1211] | Is there some changelog for 1.3.52 ? |
Pekr 8-Nov-2005 [1212] | yes, source, diff :-) |
BrianH 8-Nov-2005 [1213] | The great rename is here! Woohoo! |
Rebolek 8-Nov-2005 [1214x2] | ah, the dots |
so it's good to cheat in surveys... | |
BrianH 8-Nov-2005 [1216] | I didn't cheat. |
Rebolek 8-Nov-2005 [1217] | I don't know who did, but opinions here were different from the survey |
BrianH 8-Nov-2005 [1218] | The dots were one of my favorite choices. |
Rebolek 8-Nov-2005 [1219] | OK I know it's a dialect, not REBOL, but there is not a single word in REBOL that uses dot. Decimals and tupples use them, but not words. |
BrianH 8-Nov-2005 [1220x2] | You can use dots in words. |
Most don't. | |
Rebolek 8-Nov-2005 [1222] | I can live with dots but I don't like it, looks really un-REBOLish |
BrianH 8-Nov-2005 [1223x3] | Quick to type though, at least compared to - on my keyboard. |
So, why hasn't the syntax signiature of brab changed to match the new behavior? In theory, we can now specify a literal integer at the first position, as that is what the label fixup changes brab to in the special case. The syntax check doesn't allow it though, because it still looks for word! or block! only. | |
; BRAB should be like this brab: ["Branch block table" block! | word! | integer! word!] | |
Rebolek 8-Nov-2005 [1226] | Hm this is not directly related to ".", but now I realize I've got some 1000 lines of rebcode to rewrite :) |
BrianH 8-Nov-2005 [1227] | Search and replace :) |
Rebolek 8-Nov-2005 [1228] | :) |
Pekr 8-Nov-2005 [1229x2] | Brian - it was not about "qick to type" ;-) If so, we should replace path char with dots too ... |
I agree with Kru that once again probably the poll was only informative and the voice of most - ignored ... | |
BrianH 8-Nov-2005 [1231x4] | Well, the dot and dash versions were really arbitrary between them. We couldn't do paths and the no-change and no-seperator choices had significant negatives. |
At least the dot being unlikely in normal rebol code makes these opcodes more useful in rewrite rules, since you will know what to not look for. | |
I suggested the dash, but the dot is just as good to me. | |
And anyway, REBOL syntax is designed to be quick to type. That is why we use - instead of _ and [ ] instead of { } like other languages. | |
Pekr 8-Nov-2005 [1235] | but why not - |
Rebolek 8-Nov-2005 [1236] | As Cyphre said: because dot looks more like assembler ;) |
Pekr 8-Nov-2005 [1237] | never mind, I will probably never write rebcode leve code anyway :-) |
BrianH 8-Nov-2005 [1238] | It is a good visual reminder of the different semantic model, this is true... |
older newer | first last |