From 7253d7b0afc955dcfae3a5e8f511bb3c2eaadf7c Mon Sep 17 00:00:00 2001 From: Mark Cave-Ayland Date: Wed, 9 Dec 2009 01:09:48 +0000 Subject: [PATCH] Revert r638, apply previous patch to extend control flow stack items to 2 data stack items, and fix the Fcode evaluator to use this new information to correctly resolve destination (br + (resolve-begin) + \ Find topmost control stack entry with a type of 1 (dest) + r> dup dup pick 1 = if + \ Move it to the top + roll + swap 1 - roll + \ Resolve it + (resolve-dest) + 1 \ force exit + else + drop + 2 + >r + 0 + then + (resolve-until) +; + +: begin setup-tmp-comp ['] (begin) , - here + here + 1 ; immediate - -: again + +: again ['] (again) , ['] dobranch , resolve-dest execute-tmp-comp ; compile-only - -: until + +: until ['] (until) , ['] do?branch , - resolve-dest + resolve-dest execute-tmp-comp ; compile-only - + : while setup-tmp-comp ['] (while) , ['] do?branch , - here 0 , swap + here 0 0 , 2swap ; immediate - -: repeat + +: repeat ['] (repeat) , ['] dobranch , resolve-dest resolve-orig execute-tmp-comp ; compile-only + \ \ 7.3.8.4 Counted loops \ @@ -267,13 +285,14 @@ variable leaves 0 leaves ! here over - \ -- *leaves leaves here-leaves swap ! \ -- *leaves repeat - here - , + here nip - , leaves ! ; -: do +: do setup-tmp-comp - leaves @ here + leaves @ + here 2 ['] (do) , 0 leaves ! ; immediate @@ -282,7 +301,7 @@ variable leaves 0 leaves ! setup-tmp-comp leaves @ ['] (?do) , - here + here 2 here leaves ! 0 , ; immediate @@ -299,6 +318,7 @@ variable leaves 0 leaves ! execute-tmp-comp ; immediate + \ Using primitive versions of i and j \ speeds up loops by 300% \ : i r> r@ swap >r ; @@ -325,15 +345,15 @@ variable leaves 0 leaves ! 0 ; immediate -: endcase +: endcase ['] drop , - 0 ?do + 0 ?do ['] then execute loop execute-tmp-comp ; immediate -: of +: of 1 + >r ['] over , ['] = , @@ -342,13 +362,12 @@ variable leaves 0 leaves ! r> ; immediate -: endof +: endof >r ['] else execute r> ; immediate - \ \ 7.3.8.5 Other control flow commands \ diff --git a/forth/device/fcode.fs b/forth/device/fcode.fs index 3c8c830..9083ed0 100644 --- a/forth/device/fcode.fs +++ b/forth/device/fcode.fs @@ -451,15 +451,13 @@ defer fcode-c@ \ get byte : bbranch fcode-offset 0< if \ if we jump backwards, we can forsee where it goes ['] dobranch , - \ Backwards branches are resolved from the bottom of the cstack - depth cstack-startdepth @ 1+ - roll resolve-dest execute-tmp-comp else setup-tmp-comp ['] dobranch , - here + here 0 0 , - swap + 2swap then ; immediate @@ -470,13 +468,11 @@ defer fcode-c@ \ get byte : b?branch fcode-offset 0< if \ if we jump backwards, we can forsee where it goes ['] do?branch , - \ Backwards branches are resolved from the bottom of the cstack - depth cstack-startdepth @ 1+ - roll resolve-dest execute-tmp-comp else setup-tmp-comp ['] do?branch , - here + here 0 0 , then ; immediate @@ -487,7 +483,7 @@ defer fcode-c@ \ get byte : b(