2022-03-02 07:36:35 remexre: Well, ?DUP is useful for IF ... THEN, though not so much for IF ... THEN ... ELSE. ?DUP does DUP only if the top of stack is true. So ?DUP IF ... THEN will have the IF consume an item. If the ... is executed (IF passes), it uses the second copy. If the IF fails, there is no second copy so the one consumed by the IF is the only one. 2022-03-02 07:36:52 So it precisely eliminates the variant stack effect of the IF ... THEN clause. 2022-03-02 07:39:03 So I suppose ?DUP IF ... THEN is exactly equivalent to DUP IF ... ELSE DROP THEN 2022-03-02 09:03:46 KipIngram , would you mind sharing the definition of ME? 2022-03-02 09:04:28 I have a loop across words and I do not want to keep filling the stack. 2022-03-02 09:04:33 s/stack/return stack/ 2022-03-02 09:08:14 http://okturing.com/src/13208/body I am playing around with this. 2022-03-02 12:58:46 joe9: I'll do that; I'm about to start a phone call, though. Back in a bit. 2022-03-02 12:59:08 no hurries. 2022-03-02 14:15:02 joe9: So, I haven't put ME into the new system yet, but here's its definition from my previous one: 2022-03-02 14:15:09 ;;; : ME POSTPONE JUMP (ME) ; IMMEDIATE 2022-03-02 14:15:12 head_i "me", me 2022-03-02 14:15:14 me_d: defi p4lit-o, pjump-o 2022-03-02 14:15:16 ;;; : (ME) LATEST CELL + H@ SYSTEM + DP @ - , ; 2022-03-02 14:15:18 pme_d: defi odpstore-o, comma-o, latest-o, cell-o, plus-o, hload-o, psrel-o, load-o, plus-o 2022-03-02 14:15:20 defi dp-o, load-o, minus-o, comma-o, dosem-o 2022-03-02 14:15:50 SYSTEM + is an offset correction; I had to jump some squirrly hoops to get a Forth to work on MacOS. 2022-03-02 14:15:58 Just ignore the SYSTEM + 2022-03-02 14:16:25 System is the base address of my whole system, and that H@ just before it fetched an OFFSET. That's converting it to an actual address. 2022-03-02 14:16:41 In an ideal system I'd just have stored the address to start with. 2022-03-02 14:17:07 So you see, it basically uses LATEST to identify the most recent start of definition. 2022-03-02 14:18:13 All those -o bits on the end of everything - same issue. That's going from addresses to offsets. 2022-03-02 14:18:39 So "o" and SYSTEM boil down to the same number. SYSTEM is just r15 - I keep that base in a register for speed. 2022-03-02 14:19:01 But the -o is an assembly time thing. 2022-03-02 14:20:20 So LATEST gives the cfa of the latest word. CELL + turns that into a PFA pointer (and it is a POINTER in my system - the bodies don't just "follow" the CFA like in FIG), and H@ fetches the 32-bit contents of that PFA pointer. 2022-03-02 14:20:39 So I wind up with something pointing to the very beginning of the latest word's address list. 2022-03-02 14:21:42 So POSTPONE JUMP compiles a jump word; (ME) adds the jump distance. 2022-03-02 14:22:12 DP @ gets the base of the definition region - there's an offset involved there too. 2022-03-02 14:22:18 KipIngram: yeah, the thing with the earlier optimizer was that after inlining you'd get DUP IF DUP THEN IF ... THEN and the optimizer used to not be smart enough to realize the IFs were dependent on each other, so it would thing the entire definition had a variable stack effect 2022-03-02 14:22:28 would think* 2022-03-02 14:22:38 I see. 2022-03-02 14:22:58 I haven't played with anything like that - I just leave efficient code up to "myself." :-) 2022-03-02 14:23:23 yeah, this Forth is for using as a backend for a compiler, where I compile other languages to Forth 2022-03-02 14:24:21 so I expect the code to be fairly unidiomatic, and need many of the "traditional compiler optimizations" to be implemented in its compiler 2022-03-02 14:25:04 In my latest implementation I managed to not need that -o part - a typical nasm definition of a Forth word might look like this: 2022-03-02 14:25:08 ;;; : b, dp.b @ h! 4 dp.b +! ; 2022-03-02 14:25:11 def "b,", bcomma 2022-03-02 14:25:13 run dpb, load, hstore, four, dpb, pstore, dosem 2022-03-02 14:25:43 def and run are nasm macros that I worked pretty hard on. 2022-03-02 14:25:52 I was happy with how "streamlined" it all turned out. 2022-03-02 14:29:53 nasm's macro facilities turn out to be quite capable. All hte heavy lifting of building the dictionary structure and so on get "handled." 2022-03-02 14:30:23 Figures out the link distances, etc. 2022-03-02 14:30:52 Things that would have been a real pain to do manually (and WERE a real pain, back in earlier years when I did do the manually). 2022-03-02 17:17:52 KipIngram: thanks. 2022-03-02 17:30:13 a forth plan9 dhcpclient https://pastebin.com/raw/V85CvwS7 2022-03-02 17:30:33 my first big'ish forth program in a long time. 2022-03-02 18:11:11 joe9: you're gonna put that up somewhere more permanent? 2022-03-02 19:49:47 hopefully will be part of a 9ferno fork with forth userspace.