~vdupras/duskos

65de6583f2b08941150f620368399b2faa19cc53 — Virgil Dupras 17 days ago bfdd134
bootlo: rewrite fill and [c]? in HAL

Those words are often use in contexts where speed is important.
1 files changed, 12 insertions(+), 6 deletions(-)

M fs/xcomp/bootlo.fs
M fs/xcomp/bootlo.fs => fs/xcomp/bootlo.fs +12 -6
@@ 230,15 230,21 @@ alias execute | immediate
:iterator for2 ( lo hi -- )
  2dup < if to j to i begin yield to1+ i i j >= until else 2drop then unyield ;

: fill ( a u c -- ) rot> over + for2 dup i c! next drop ;
code fill ( a u c -- )
  W>A, PSP) 4 +) @, W<>A, 1 PSP) [+n], begin \ A=a W=c P+0=u+1
    -1 PSP) [+n], 0 NZ) branchC, 8 ps+, drop, exit, then
    A) 8b) !, 1 A+n, branch, drop

: allot0 ( n -- ) here over 0 fill allot ;
: nc, ( n -- ) for word runword c, next ;

\ index of "c" inside range "a u". -1 if not found
: [c]? ( c a u -- i )
  -1 >r swap >r 0 swap for2 ( c ) \ V1=res V2=a
  dup 8b to@+ V2 = if j to@! i to V1 then next ( c )
  drop rdrop r> ( i ) ;
code [c]? ( c a u -- i )
  W=0>Z, 0 Z) branchC,
    PSP) @!, W>A, 0 LIT>W, dup, begin \ P+8=c P+4=u P+0=i A=a
      A) 8b) @, PSP) 8 +) 8b) compare, 0 NZ) branchC, drop, 8 ps+, exit, then
      1 A+n, 1 PSP) [+n], PSP) @, PSP) 4 +) compare, NZ) branchC, drop
    drop, then
  8 ps+, -1 LIT>W, exit,

\ Emitting
$20 const SPC $0d const CR $0a const LF $08 const BS $1b const ESC