SamCoVT / TaliForth2

A Subroutine Threaded Code (STC) ANSI-like Forth for the 65c02
Other
29 stars 5 forks source link

Is there an existing word like asciiz> ( zaddr -- addr n ) for converting zero-terminated strings to counted ones? #39

Closed patricksurry closed 5 months ago

patricksurry commented 6 months ago

I ended up writing a native word for this since I couldn't find one but maybe buried in Tali internals somewhere?

I think it can be implemented in forth as dup begin count 0= until 1- over - but is a lot more efficient natively, and I have a bunch of these strings. It it's useful happy to contribute but not sure that it's a standard word.

SamCoVT commented 6 months ago

There isn't currently such a word, as Tali only uses C-style strings internally for things like the error messages. All of the strings used from Forth are either counted strings (pretty rare, but was used in older Forths - this is a Pascal-style string with the first byte containing the length) or addr u (this is what all the cool Forth kids are using these days) type strings. Tali compiles them in memory as their starting address and length.

If I had a need for such a word and were going to use it a lot, I'd probably write it in assembly.

I don't see myself using it, but you're welcome to put it in the examples if you find it useful and would like to share it.