SamCoVT / TaliForth2

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

Refactor sliteral and use standard NUXI ordering for 2literal etc #123

Closed patricksurry closed 2 weeks ago

patricksurry commented 1 month ago

Switching to standard NUXI memory layout for 2literal PFA became a bit of an odyssey where I refactored sliteral as well.

It now compiles like jsr sliteral_runtime / .word length / .text <string> instead of jmp skip / .text <string> / jsr sliteral_runtime addr n. This makes string literal a little smaller and faster but also native-compilable since it loses the jmp. It also simplifies disassembly a lot.

I noticed that s" was always reserving space for the string even when interpreted, so every string claims space in the dictionary. Presumably that's safer but you'll run out of space faster. The spec you shared suggests that it could be a temp buffer "...an implementation may choose to provide only one buffer for interpreted strings, an interpreted string is subject to being overwritten by the next execution of S" in interpretation state...".

In the PR currently it writes interpreted s" strings at cp+$200 (beyond pad), which meant a minor test change to name a constant string, e.g. : foo s" const" drop ; instead of s" const" drop constant foo which isn't safe.

I don't have strong feelings so happy to revert that if you like the safe alloc instead.

I made a few cosmetic/byte-saving changes to dump like avoiding writing temp data at cp, and adding space padding - lmk if you prefer without. Also in disasm to show a snippet of sliteral string. Overall image is about 100 bytes smaller, or more if we dropped cosmetic changes. Example:

see block-ramdrive-init 
nt: C882  xt: AEC4 
flags: CO 0 IM 0 AN 0 NN 0 HC 0 | UF 1 ST 0 
size (decimal): 291 

AEC4  20 27 D8 20 29 A2 18 01  62 61 73 65 20 40 20 73   '. )... base @ s
...
AFD4  77 61 70 20 62 6C 61 6E  6B 20 62 61 73 65 20 21  wap blan k base !
AFE4  20 8E 88                                           ..

AEC4   D827 jsr     1 STACK DEPTH CHECK
AEC7   A229 jsr     SLITERAL 118 base @ swap dec...
AFE4   888E jsr     evaluate
 ok
SamCoVT commented 3 weeks ago

I think, overall, I like the string runtime with length just before the string data. I think all the S" strings should be compiled into the dictionary, unless you want to talk me into a special buffer for S" in interpreted mode (see my previous note with way more information on why).

patricksurry commented 3 weeks ago

sounds good. i'll revert the temp string change as i merge the other PR, later today or tomorrow. the other PRs should be udpated now.