6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Jun 02, 2024 12:21 am

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Fri Jan 30, 2015 11:19 am 
Offline

Joined: Wed Feb 05, 2014 7:02 pm
Posts: 158
Something I'm thinking about, maybe someone who has implemented a Forth can help me out a bit. Assume an ITC Forth.

ANS Forth requires that the Forth interpreter start by awaiting input from an interactive device.

From what I gather looking at Forth source code, Forth programs are created by compiling their own custom definitions into the dictionary and then stringing definitions together. Typically, the final word to be compiled could be considered analogous to "program invocation"; the entire program is compiled into a single word in the dictionary that executes/encompasses all the required Forth words. In effect, you create each program you want to use before invocation by feeding in source code (pretty cool). So unless you have a smart terminal emulator with copy/paste, a block device, a file device, or a second input device that can send/receive ASCII, one is expected to manually compile a Forth program before running it one line at a time. Additionally, a program cannot be invoked automatically- after compilation, one is expected to invoke the program manually (unless you include a line to run the previously compiled code at the end :P).

For an environment where one might to save code between power on and power off, or want code to run automatically in response to external non-interactive events (i.e. power on, reset, timer int), I can see this becoming tedious/limiting very quickly. Waiting for compilation could become tedious. It feels as if Forth could use an autoinit to bootstrap more (pre-compiled) definitions.

This leads me to two questions:
  1. Does ANS Forth have provisions to load a previously compiled source file (input source doesn't matter, but in my case it's the serial console repurposed for binary transfer)? I.e. instead of adding a dictionary entries from reading a Forth source file from input, the interpreter reads and loads into memory already-compiled dictionary definitions. Or possibly even just a set of threads and relevant subroutines.
  2. Does ANS Forth have provisions to automatically compile and run a source file, or load and execute a pre-compiled set of dictionary definitions without having to wait for external input from the user (i.e. at Forth initialization, akin to Unix init- this isn't practical on my system since the serial device is interactive :P, but it makes sense on a Forth with mass storage access), or in response to an external event (i.e. in response to a timer interrupt- which occurs without user intervention, or a background process)?

Of course, I could implement this on my own. :P The question is- is this something that other Forth systems do? I mean, I'm sure in case of failure/reset, those satellites running Forth CPUs aren't going to an input prompt waiting for a program to run. :P


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 30, 2015 11:56 am 
Offline

Joined: Mon Jan 26, 2015 6:19 am
Posts: 85
You are probably thinking of TURNKEY which is available in a number of ANS Forths.


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 30, 2015 6:06 pm 
Offline

Joined: Tue Jan 07, 2014 8:40 am
Posts: 91
cr1901 wrote:
  1. Does ANS Forth have provisions to load a previously compiled source file (input source doesn't matter, but in my case it's the serial console repurposed for binary transfer)? I.e. instead of adding a dictionary entries from reading a Forth source file from input, the interpreter reads and loads into memory already-compiled dictionary definitions. Or possibly even just a set of threads and relevant subroutines.
  2. Does ANS Forth have provisions to automatically compile and run a source file, or load and execute a pre-compiled set of dictionary definitions without having to wait for external input from the user (i.e. at Forth initialization, akin to Unix init- this isn't practical on my system since the serial device is interactive :P, but it makes sense on a Forth with mass storage access), or in response to an external event (i.e. in response to a timer interrupt- which occurs without user intervention, or a background process)?


1. To the best of my knowledge, ANS Forth does not have provisions to load an "object file" (previously compiled source). A few Forth implementations can do this, but it is not a standardized function.

2a. I don't believe this is mentioned by the ANS Standard, but most Forths that execute under an operating system can do this, either by (a) accepting a file name on the command line, or (b) accepting a Forth command on the command line (and that command could be "INCLUDE filename"). For example, I can type "gforth foobar.f" and gForth will load and execute foobar.f.

2b. For embedded systems, again, the ANS Standard does not address this, but I have seen several different approaches to "autostart" an application. (Interrupts are a completely separate issue.) For one example, on reset, MSP430 CamelForth will automatically execute the last word added to the dictionary.

Important caveat: I have not been following the efforts of the Forth 200x committee, and it's possible that they have addressed one or both of these issues.

_________________
Because there are never enough Forth implementations: http://www.camelforth.com


Top
 Profile  
Reply with quote  
PostPosted: Sat Jul 06, 2019 11:35 pm 
Offline

Joined: Fri May 05, 2017 9:27 pm
Posts: 864
cr1901 wrote:
Of course, I could implement this on my own. :P The question is- is this something that other Forth systems do?

Fleet Forth does not load object files ( it's for the Commodore 64 ) but it does have a word to save the current system as a new Forth. Since it prompts for a name, the new system need not replace the original one. I'm still sanding the rough edges off of the utilities though.
Blazin' Forth by Scott Ballantyne also has a word to save the current Forth system.
Fleet Forth has a deferred word INITIAL which is in the high level part of the cold start routine. It is normally set to a no-op, but can be set to a word to run upon startup or coldstart. There is also a deferred word ERR to modify the error handling. It is also normally set to a no-op.
Blazin' Forth has a variable, STARTUP , which normally holds the address of QUIT . Its contents are fetched and executed upon startup and upon error handling.
Quote:
I mean, I'm sure in case of failure/reset, those satellites running Forth CPUs aren't going to an input prompt waiting for a program to run. :P

No, I imagine they already have their application compiled and a similar means to launch it upon reset.


Top
 Profile  
Reply with quote  
PostPosted: Sun Jul 07, 2019 3:04 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8448
Location: Southern California
JimBoyd wrote:
cr1901 wrote:
I mean, I'm sure in case of failure/reset, those satellites running Forth CPUs aren't going to an input prompt waiting for a program to run. :P

No, I imagine they already have their application compiled and a similar means to launch it upon reset.

What I did in the software version of the automated test equipment I released to our production people nearly 30 years ago was to replace QUERY INTERPRET in QUIT with the name of the word to launch into upon boot-up. (COLD calls ABORT, and ABORT calls QUIT.) From there they could select the test modes, what they were going to test, set time & date, etc., through menus. The test operator did not have access to the command line or know anything about Forth.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
PostPosted: Fri Aug 30, 2019 7:59 pm 
Offline

Joined: Wed Aug 21, 2019 6:10 pm
Posts: 217
cr1901 wrote:
Something I'm thinking about, maybe someone who has implemented a Forth can help me out a bit. ...

This leads me to two questions:
  1. Does ANS Forth have provisions to load a previously compiled source file (input source doesn't matter, but in my case it's the serial console repurposed for binary transfer)? I.e. instead of adding a dictionary entries from reading a Forth source file from input, the interpreter reads and loads into memory already-compiled dictionary definitions. Or possibly even just a set of threads and relevant subroutines.
  2. Does ANS Forth have provisions to automatically compile and run a source file, or load and execute a pre-compiled set of dictionary definitions without having to wait for external input from the user (i.e. at Forth initialization, akin to Unix init- this isn't practical on my system since the serial device is interactive :P, but it makes sense on a Forth with mass storage access), or in response to an external event (i.e. in response to a timer interrupt- which occurs without user intervention, or a background process)?


(1) No, ANS Forth is a communications standard, not a specification for an implementation. TURNKEY or SAVESYSTEM is beyond the scope of the standard, as it requires detailed "carnal knowledge" of the implementation ... and of the system context, whether bare metal or working within an OS.

(2) Ditto.

But it is a widely available feature OF ANS Forth implementations. How it is does varies by implementation. In Brad Rodrigez's Camel Forth for Z80 & CP/M, he uses the CP/M SAVE function after exiting Forth. In porting Camel Forth to the C64, I am considering leaving a small Basic space intact and having a utility menu in Basic that performs the SAVESYSTEM function.

Basically TURNKEY is often just SAVESYSTEM after redirecting the start-up process from the QUIT loop to the desired main operating word.


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 02, 2019 2:36 pm 
Offline

Joined: Mon Sep 14, 2015 8:50 pm
Posts: 110
Location: Virginia USA
Just noticed how old this thread is (2015).

While not ANS Forth, RSC Forth had a mechanism for turnkey operations built in.
viewtopic.php?f=3&t=5226

Cheers,
Andy


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: