Plan 9 from Bell Labs’s /usr/web/sources/contrib/fgb/root/sys/src/cmd/4th/lib/strstack.4th

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


\ 4tH library - STRING STACK - Copyright 2004,2009 J.L. Bezemer
\ You can redistribute this file and/or modify it under
\ the terms of the GNU General Public License

[UNDEFINED] N! [IF]
INCLUDE lib/ncoding.4th
[THEN]

[UNDEFINED] STRING-STACK [IF]
1 nell [*] +constant +sp
2 nell [*] +constant +s0
8 nell [*] +constant +slack

: s@ n@ n@ count ;                        ( s -- a n)
: s> dup n@ tuck nell- swap n! n@ count ; ( s -- a n)
                                          \ initialize the stack
: string-stack                            ( a n --)
  chars over + over over over             ( a s0 a s0 a)
  +sp n! +s0 tuck n! swap n!              ( --)
;
                                          \ put a string on the stack
: >s                                      ( a n s --)
  over 1+ chars over +sp n@ swap -        ( a n s p)
  over n@ nell+ dup >r +slack over >      ( a n s p f)
  if drop 2dup +s0 n@ swap 1+ chars - then
  >r -rot r@ place r@ over                ( s p s)
  +sp n! r> r@ n! r> swap n!              ( --)
;

[DEFINED] 4TH# [IF]
hide +sp
hide +s0
hide +slack
[THEN]
[THEN]

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.