cforth icon indicating copy to clipboard operation
cforth copied to clipboard

Multiple copies of forth

Open jonsmirl opened this issue 1 year ago • 4 comments

If I init forth twice, can I use the two instances independently? I want two completely isolated instances only sharing the read-only data.

No global variables holding state? All state is in the dynamically allocated memory?

jonsmirl avatar Mar 29 '23 02:03 jonsmirl

My gut feel is that it would be a big job, but possible. You would have to root out each global variable. If I were doing this, I would start with CForth built for a Linux host, then iterate over the linker map to find everything that isn't dynamic.

quozl avatar Mar 29 '23 02:03 quozl

Most state is in the user area. VARIABLE, USER, VALUE, DEFER are all implemented in the user area. In order to get a shared variable, you pretty much have to use CREATE , DOES> @

That said, there are things that can trip you up, like pictured numeric output and the input buffer.

MitchBradley avatar Mar 29 '23 05:03 MitchBradley

init_compiler is the thing that establishes the addresses of all the RAM areas. It is called by prepare_dictionary which is called by init_forth. You should study how it works and figure out how to call it twice, or make a second variant of it. I think it might suffice to call it with different values for here and xlimit.

MitchBradley avatar Mar 29 '23 05:03 MitchBradley

This second copy is going to talk to Google Real-time DB, it is not user facing. It is going to monitor a bunch of things and then log them up to Google. Google RTDB has a REST interface and it is only going to put things into the db. Phone apps are used to look at the data. The things it is monitoring are already protected from multitasking issues.

jonsmirl avatar Mar 29 '23 12:03 jonsmirl