World: r3wp
[rebcode] Rebcode discussion
older newer | first last |
BrianH 25-Oct-2005 [889] | Submitted to RAMBO. |
Benjamin 26-Oct-2005 [890] | hoo third option seems fineto me |
BrianH 26-Oct-2005 [891] | Does anyone still need to vote? |
Ladislav 26-Oct-2005 [892] | looking at the checklist I see, that there was somebody not adhering to the rules :-) |
Henrik 26-Oct-2005 [893] | never send a checklist to do a voting applications' job :-) |
BrianH 26-Oct-2005 [894x2] | Yeah, I noticed that the votes didn't add up to a multiple of three. |
Whoops, I guess they do now. | |
Ladislav 26-Oct-2005 [896] | :-) |
Alan 26-Oct-2005 [897] | 1 |
DideC 26-Oct-2005 [898x2] | The survey helped (even with those who didn't play the game ;) Thans to all |
thanks | |
BrianH 26-Oct-2005 [900] | I've written a patch to the assembler that implements a working OFFSET directive and label value fixups. I will submit it to RAMBO as an enhancement request. |
[unknown: 5] 26-Oct-2005 [901] | I don't know enough about rebcode to do any voting - there any docs yet? |
BrianH 26-Oct-2005 [902x5] | ; You use it like this label x ;... offset y 5 sub y x braw y |
Note that label, offset and the branches all calculate relative to the end of their statements. | |
Just after the end, rather. | |
If anyone wants to test the patch, here it is. | |
REBOL [] use [fixup-rule label-rule label-fixup-rule label-error-rule here] [ ; Initialize the intermediate rules label-rule: make block! 0 label-fixup-rule: make block! 0 label-error-rule: make block! 0 ; Build the fixup-rule based on the opcode-rule fixup-rule: copy/deep rebcode*/opcode-rule parse fixup-rule [ some [ here: lit-word! block! '| ( unless find ['bra 'brat 'braf] here/1 [insert here/2 [label-error-rule |]] ) | lit-word! 'word! '| ( unless 'label = here/1 [here/2: [label-error-rule | word!]] ) | lit-word! | '| | 'block! | 'series! | 'word! (here/1: [label-error-rule | word!]) | 'any-type! (here/1: [label-fixup-rule | any-type!]) | into ['integer! '| 'word! | 'word! '| 'integer!] ( insert here/1 [label-fixup-rule |] ) | block! (insert here/1 [label-error-rule |]) ] ] ; Replace the fix-bl function rebcode*/fix-bl: func [block /local labels here there label rule] bind [ labels: make block! 16 block-action: :fix-bl if debug? [print "=== Fixing binding and labels... ==="] parse block [ some [ here: subblock-rule (here/1: bind here/1 words) | 'label word! (here/1: bind here/1 words insert insert tail labels here/2 index? here) | 'offset word! integer! ( here/1: bind 'set words here/3: 3 + here/3 + index? here if (here/3 < 1) or (here/3 > 1 + length? block) [ error/with here "Offset out of bounds:" ] ) | opcode-rule (here/1: bind here/1 words) | skip (error here) ] ] either 0 < length? labels [ label-rule: make block! length? labels foreach [key val] labels [insert insert tail label-rule to-lit-word key '|] clear back tail label-rule label-fixup-rule: [there: label-rule (there/1: 2 + select labels there/1)] label-error-rule: [label-rule (error/with here "Cannot use label here:")] rule: fixup-rule ] [ rule: opcode-rule ] parse block [ some [ here: ['bra word! | 'brat word! | 'braf word!] ( if not label: select labels here/2 [error/with here "Missing label:"] here/2: label - index? here ) | rule | skip (error here) ] ] ] rebcode* ] | |
Rebolek 27-Oct-2005 [907] | somebody must really like the add.i/add.d version. It's got priority 20 now :) |
Volker 27-Oct-2005 [908x2] | can i have preincrement/postdecrement then? |
if we go 68k. ;) | |
Rebolek 27-Oct-2005 [910] | I don't like, it doesn't look like REBOL with the dot. Is it tuple or url? No, it isn't. So why the dot? |
Volker 27-Oct-2005 [911x2] | because its assembler and 68k did it that way. dont like it too. |
have you voted already? :) | |
Rebolek 27-Oct-2005 [913] | Yes, for the addi/addd version. |
Pekr 27-Oct-2005 [914] | but it is not an assembly ;-) It is rebol dialect .... I agree with Kru .... |
Volker 27-Oct-2005 [915] | Have you voted? shall we vote again? :) |
Sunanda 27-Oct-2005 [916] | I agree with kru -- pity there is no option for making them look like refinements add/i add/d add -- default is /i or /d or whatever is chosen |
Volker 27-Oct-2005 [917] | suggested that to. Was told its technially no option, they must be words. |
Rebolek 27-Oct-2005 [918] | or add-i/add-d. More REBOLish than dot. |
Pekr 27-Oct-2005 [919x2] | exactly .... |
I-am-already-used-to-rebolish-way :-) | |
BrianH 27-Oct-2005 [921x2] | The only advantages I can see to the dot (as opposed to the - ) is that it is less visually imposing and that it is easier for me to reach on my keyboard. These advantages are not insignificant, though. |
Either dot or - would be OK to me. | |
Ladislav 28-Oct-2005 [923x4] | here is a poll |
Carl said: What I am thinking of for BRAW is this: BRAB [lab1 lab2 lab3] n If N is out of range, the BRAB does not happen. That allows DEFAULT case without needing to compute it before teh BRAB. | |
Should BRAB be zero-based or 1-based? | |
(see checklists for the poll) | |
BrianH 28-Oct-2005 [927x10] | Are the labels statically replaced with offsets like they are with bra, done with runtime lookups of the label declaration, done with label offsets assigned to the words, or done some way that hasn't occured to me? Can numeric offsets be used, and if so are they absolute (within the block) or relative? |
As for 0-based versus 1-based, let's compare: 0-based - would allow branching on the basis of a modulus calculation, or other calculations that can result in zero - would be more useful for implementing Duff's Device style switch statements, which I have found useful so far 1-based - is more REBOL-like (if such a thing can be said of a goto statement) - effectively has a 0-based branch with the default of continuing on (not as useful for Duff's Device stuff, as the 0 branch is usually the last in the code) - is in keeping with the rest of the 0-based opcodes having the letter z on the end, while BRAB doesn't | |
I vote for 0-based, or both (BRAB/BRABZ). | |
If both is added as a choice to the poll, I'll change my vote from 0-based. | |
Last question, can the block be passed in a word? Keep in mind that I am not requesting this, as there would be some negatives: - You couldn't replace the labels statically with offsets in the assembler - It would likely be slower and harder to JIT - Copy/paste or compose can accomplish the same thing | |
Still, this deals with the most common usage scenario that I've found for computed branches so far, so I'm really pleased! | |
(by the "this" in my last statement, I meant the BRAB opcode, not indirect blocks) | |
By the way, if the block is required to be a literal, numeric offsets could be decided to be specified in either absolute or relative form. If you allow the block to specified through a word, absolute numeric offsets are the only practical option - this is probably another negative for label blocks in a word. | |
Common usage scenarios for BRAB would be C-style switch statements, state machines and token-threaded interpreters. Direct-threaded interpreters would still need BRAW, though are only practical when branching to an absolute offset so the current BRAW wouldn't work for them either. | |
If we have BRAB, can anyone think of a decent use for a BRAW to a relative offset? Every other usage of computed branches I can think of requires branches to absolute offsets to be at all practical. Have I missed something? Once we have BRAB, is there any reason to treat BRAW as a relative branch, besides simple implementation issues? | |
Gabriele 28-Oct-2005 [937x2] | brab does accept a word for the first arg. offsets still need to be relative. |
if the block is literal, the assembler takes care of replacing labels with offsets. | |
older newer | first last |