csb8
Priskribo de la ĉi-paĝa enhavo
Modelo de cirkla teksto-bufro por 8-bita Fortho.
csb8 estas reverko de csb2 celanta prototipe servi por inkludo en DZX-Forth. Ĝi do verkitas por 8-bita komputilo de unu-bitokaj signoj (chars
kaj char+
ne uzatas en la programo). Sed ĝi senŝanĝe funkcius en plimultaj Fortho-sistemoj. Krome ĝi estas verkita kun malplej da vortoj, por funckia rapido, eĉ se la fina versio estis verkota en Z80.
Fontkodo
\ csb8
\ csb8 is an implementation of a circular string buffer, to be used as
\ a prototype for an 8-bit Forth system with 1-byte characters.
\ Copyright (C) 2015 Marcos Cruz (programandala.net)
\
\ csb8 is free software distributed under the terms of the
\ Programandala License
\ See: <http://programandala.net/licence>
\ NO WARRANTY OF ANY KIND
\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\ Acknowledgment
\ csb8 is based on csb2
\ (http://programandala.net/es.programa.csb2.html). csb2 was partly
\ based on code by Wil Baden (published in Forth Dimensions,
\ 1996-07/08, volume 18, issue 2, page 6, http://forth.org).
\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\ History
\ 2015-01-29: Start.
\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\ Circular string buffer
512 constant /csb \ buffer size
/csb create csb-unused , \ unused buffer space
here /csb allot constant csb0 \ bottom address
\ XXX TODO -- rewrite, make it faster:
: ?csb ( len -- )
\ Make sure there's room for the given characters.
dup csb-unused @ > if /csb csb-unused ! then
negate csb-unused +! ;
: string-allocate ( len -- ca )
?csb csb0 csb-unused @ + ;
: save-string ( ca1 len1 -- ca2 len1 )
dup string-allocate swap 2dup 2>r move 2r> ;
: save-counted-string ( ca1 len1 -- ca2 )
dup 1+ string-allocate dup >r place r> ;
\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
\ String tools
: (s) ( compilation: ca len -- ) ( run-time: ca len -- ca2 len )
state @ if postpone sliteral else save-string then ;
: s| ( "ccc<|>" -- ca len ) [char] | parse (s) ; immediate
: s" ( "ccc<quote>" -- ca len ) [char] " parse (s) ; immediate
: lengths ( ca1 len1 ca2 len2 -- ca1 len1 ca2 len2 len1 len2 )
2 pick over ;
: smove ( ca1 len ca2 -- ) swap move ;
: s+ ( ca1 len1 ca2 len2 -- ca3 len3 )
\ Append the string ca2 len2 to the end of string ca1 len1
\ returning the resulting string ca2 len3.
lengths + >r ( ca1 len2 ca2 len2 ) ( R: len3 )
r@ string-allocate >r ( R: len3 ca3 )
2 pick r@ + ( ca1 len1 ca2 len2 len1+ca3 )
smove ( ca1 len1 ) \ second string to buffer
r@ smove \ first string to buffer
r> r> ;
: count ( ca1 -- ca2 len ) count save-string ;