![]() |
You. Forth. Simplicity. |
reload node | edit | recent changes | front page
Several ports of the RetroEditor have been written. You can review them here, and help make improvements. If you port it to another Forth, please add the source to this page so that all can enjoy it.
: (block) current-block @ : block 512 * there + ;
: (line) 64 * (block) + ;
: p 1 current-block -! ;
: n 1 current-block +! ;
: d (line) 64 32 fill ;
: x (block) 512 32 fill ;
: eb (block) 512 eval ;
: el (line) 64 eval ;
: e 8 for 8 r - el next ;
: s current-block ! ;
: i 0 swap : ia (line) + lnparse rot swap move ;
: \ 1 s e ;
loc:
: .block ." Block: " current-block @ . ." of " #-of-blocks 1- . ;
: status .block ." Stack: " .s cr ;
: row dup 64 type 64 + cr ;
: .line -8 + negate . ;
: rows 8 for r .line row next ;
: x--- 4 for ." +---:---+---:---" next ;
: --- space space x--- cr ;
:: --- current-block @ block rows drop --- status ;
;loc is v
:: clear v ;
: edit literal { is ui } ;
This version makes use of several RetroForth-specific features and will require some modifications to work on other Forths. "edit" in particular is tied closely to RetroForth.
here 50000 + constant offset
variable blk
: block 512 * offset + ;
: (block) blk @ block ;
: (line) 64 * (block) + ;
: s blk ! ;
: ia (line) + >r 0 parse r> swap move ;
: i 0 swap ia ;
: d (line) 64 bl fill ;
: x (block) 512 bl fill ;
: p -1 blk +! ;
: n 1 blk +! ;
: v (block) 8 for 64 2dup type + cr next drop cr cr ;
The RetroEditor is also included with JS-Forth. To load it, do the following:
8 load
11 load
v
Please note that the version included with JS-Forth has been modified to operate on traditional 16x64 blocks, rather than an 8x64 block.
here 50000 + constant offset
variable blk
: block 512 * offset + ;
: (block) blk @ block ;
: (line) 64 * (block) + ;
: row dup 64 type 64 + cr ;
: .rows 7 for r@ 8 - negate . row next ;
: .block ." Block: " blk @ . ;
: x--- ." +---:---+---:---" ;
: --- space space x--- x--- x--- x--- cr ;
: vb --- blk @ block .rows drop --- ;
: .stack ." Stack: " .s ;
: status .block .stack ;
: v cr vb status ;
: s blk ! v ;
: ia (line) + >r 10 parse r> swap move v ;
: i 0 swap ia v ;
: d (line) 64 bl fill v ;
: x (block) 512 bl fill v ;
: p -1 blk +! v ;
: n 1 blk +! v ;
this version used the build in block storage of gForth. it used the variable scr instead of blk, as the ANSI standard defines scr as the "...containing the block number of the block most recently LISTed" and that is what v does. It uses c/l instead of the hardcoded line-length 64 (c/l stands for characters per line, although not ANSI standard, it is available in most Forth systems, and if not, it can be quickly defined). v* marks the current block as modified before printing it so that it can be saved to disk with flush. .block will print a plus sign if the buffer is unmodified, and an asterisk if the buffer has been modified but not saved. This should be almost ANSI forth except for c/l and updated?. (Carsten Strotmann, 20100123)
here 50000 + constant offset
variable blk
: block 512 * offset + ;
: (block) blk @ block ;
: (line) 64 * (block) + ;
: s blk ! ;
: ia (line) + >r 10 parse r> swap cmove ;
: i 0 swap ia ;
: d (line) 64 bl fill ;
: x (block) 512 bl fill ;
: p -1 blk +! ;
: n 1 blk +! ;
: v (block) 7 0 do 64 2dup type + cr loop drop cr cr ;
| Adoption of RetroForth Block Editor (http://www.retroforth.org)
| * Released into the public domain *
| Requires: mallot FileIO
context editor~
enter editor~
512 10 * constant buffersize
variable (buffer)
doer buffer
variable blk
: block blk @ 512 * buffer + ;
: header buffer drop ." Block: " blk @ . cr ;
: across 4 spaces 64 for '- emit loop cr ;
: row dup 64 type 64 + ;
: line '| emit row '| emit cr ;
: lines 8 for 8 r - dup . line loop ;
: s blk ! [ | Select a new block
: v page header across block lines across drop ;
: i 64 * block + >r 10 parse r> swap cmove v ; | Update a line
: d 64 * block + 64 32 fill v ; | Delete a line
: x block 512 32 fill v ; | Delete the current block
: e block 512 eval ; | Run the current block
file Blockfile
doer blockfile make blockfile Blockfile " blocks" ;
variable (rbfsem)
: rbf (rbfsem) @ if ;; then
(rbfsem) on blockfile file~ open/r
buffer buffersize file~ read file~ close
if drop ." blocks loaded. " else ." blocks *not* loaded! " then (rbfsem) off ;
: wbf buffer blockfile file~ creat
buffersize file~ write file~ close
file~ result @ if ." blocks *not* written! " ;; then ." blocks written. " ;
make buffer
buffersize mallot (buffer) !
make buffer (buffer) @ ;and
buffer dup buffersize 32 fill rbf ;
;enter
with editor~
The word "v" is used to display a block. In the above examples, it's pretty minimal in most ports. In RetroForth it also provides line numbers and column markers to aid in editing.