SirWumpus / post4

Post4 is an indirect threaded Forth dialect written in C.
Other
4 stars 1 forks source link

Consider re-implementing p4Repl() / QUIT more in Forth #20

Closed SirWumpus closed 1 week ago

SirWumpus commented 3 weeks ago

It seems, a correct include-file and quit far simpler implement in Forth than in C.

You're very comfortable with Forth, so you probably see things I don't.

I suspect my design choice to use setjmp/longjmp to catch signals like SIGINT maybe be an issue. However I believe it workable in the end. The code now is so close.

I have considered (and would like to) rewrite p4Repl()/QUIT with a QUIT written in Forth, but I have design concerns as to how best to bootstrap from C into Forth, define QUIT and all the words needed to get there. Many of your past examples from assorted sources seem circular with respect to the required words.

I had planned this as some future upgrade much much later.

Originally posted by @SirWumpus in https://github.com/SirWumpus/post4/issues/8#issuecomment-2294358011

ruv commented 3 weeks ago

It seems, a correct include-file and quit far simpler implement in Forth than in C.

I suspect my design choice to use setjmp/longjmp to catch signals like SIGINT maybe be an issue.

Yes, I mean exactly that. If an exception occurs during include-file (or included), and the nearest catch was called before this include-file, you need to transfer control into C-code, to restore the input source specification: https://github.com/SirWumpus/post4/blob/8b90e24b983726a2d284e13a48de52c1a2ff8b5f/src/post4.c#L2887-L2891 and then transfer control back into Forth-code, into the corresponding catch (or after it). But in other cases you don't need to transfer control to C-code.

If you save the input source specification in Forth-code (i.e., implement include-file in Forth), then, to restore the input source specification, you don't need to transfer control into C-code and back.

SirWumpus commented 3 weeks ago

If you save the input source specification in Forth-code (i.e., implement include-file in Forth), then, to restore the input source specification, you don't need to transfer control into C-code and back.

However, saving the input source spec in C allows for easier nesting of the data on the C stack vs using the Forth stack or allocated memory.

ruv commented 3 weeks ago

However, saving the input source spec in C allows for easier nesting of the data on the C stack vs using the Forth stack or allocated memory.

And what is the price of this? I look forward to your implementation 🙃

SirWumpus commented 3 weeks ago

😛 I'll figure out something. Also switching that core aspect at this point before I'm ready makes a mess of everything else. Prefer one fight at a time (and I'm not ready for that one just yet).