[net.lang.forth] Speaking of Princeton

keithd@cadovax.UUCP (Keith Doyle) (09/17/84)

While the recent distribution of Princeton FORTH is still fresh
on our computers, I've been evolving a list of "how do you do it"'s
and was wondering if any of you out there have had similar problems/
successes:

1. How do I implement the equivalent of ?TERMINAL  ?

2. How can I implement my own control structures ( such as Charles Eaker's
   CASE statement ) without resorting to otherwise unknown assembly language?

3. Is it absolutely impossible (under UNIX or on a VAX) to implement the
   capability to re-save FORTH after an application has been compiled?
   (useful when writing canned applications invoked from the O.S. - there's
   no need for some users to know what language it was written in, and
   there's little need to wait for your editor to compile EVERY time you
   enter FORTH )

Except for these problems, I find Princeton FORTH an excellent version,
and FAST!.

Keith Doyle
{ucbvax,decvax}!trwrb!cadovax!keithd

wls@astrovax.UUCP (William L. Sebok) (09/21/84)

As my subscription to Forth Dimensions has lapsed I may be somewhat behind on
what is current in forth.  Also I haven't myself directly had to deal with
a FigForth system.  My first forth system was a Forth Inc. system circa 1976,
which predated FigForth.  From after many of my own changes I went directly to 
Forth 79.

> While the recent distribution of Princeton FORTH is still fresh
> on our computers, I've been evolving a list of "how do you do it"'s
> and was wondering if any of you out there have had similar problems/
> successes:
> 
> 1. How do I implement the equivalent of ?TERMINAL  ?

Sorry, but what does ?TERMINAL do?

> 2. How can I implement my own control structures ( such as Charles Eaker's
>    CASE statement ) without resorting to otherwise unknown assembly language?

Again, could you define Charles Eaker's CASE statement? If a control structure
needs no more of the underlying architecture than conditional branches you
could define immediate words that contain (from the ASSEMBLER vocabulary):
COMPILE IF ,  COMPILE THEN ,  and COMPILE UNTIL  and COMPILE whatever else you
need.

	addr cond UNTIL		compiles an arbitrary conditional branch from
				HERE to addr.

	cond IF	 --- addr	compiles an uncompleted forward conditional
				branch from HERE (using a conditional branch
				around a two-byte-displacement unconditional
				branch).

	addr THEN		completes an IF. addr is the address returned
				by the IF.  The destination is HERE.

I had included a CASE statement but I am not sure if is identical to the
one you want.  If you send me the definition I will try to implement it.

> 3. Is it absolutely impossible (under UNIX or on a VAX) to implement the
>    capability to re-save FORTH after an application has been compiled?
>    (useful when writing canned applications invoked from the O.S. - there's
>    no need for some users to know what language it was written in, and
>    there's little need to wait for your editor to compile EVERY time you
>    enter FORTH )

No, its not impossible. I am working on it and the next version will contain
it.  I am also working on loading non-Forth subroutine as Forth words.

There is much more that can be added to Forth, limited only by my time to
work on it.

It looks like I might have accomplished one of the things I hoped by posting
Forth: to stir up some life in this otherwise rather dead newsgroup.
-- 
Bill Sebok			Princeton University, Astrophysics
{allegra,akgua,burl,cbosgd,decvax,ihnp4,noao,princeton,vax135}!astrovax!wls

toma@tekchips.UUCP (Tom Almy) (09/21/84)

----------
I have "solved" all the problems presented in the Forth I run under UNIX
(it is Forth-79 which I implemented, written in assembly and Forth like the
fig Model).

Q1: How do I implement ?TERMINAL
A1: Some UNIX systems have an IOCTL call to tell if a key has been typed.  Since
    the system I run on doesn't, I use the signal facility to catch control-C's.
    One control-C causes ?TERMINAL to return TRUE, while two in a row (before
    KEY is executed) will cause execution to abort and return to the outer
    interpreter loop.  This works quite well.

Q2: How do I implement Eaker's Case without droping to assembly language?
A2: The originally published description was in high level.  If you only have
    a version showing a code word, (OF), then use this version of OF instead:
    : OF   4 ?PAIRS COMPILE OVER COMPILE = COMPILE 0BRANCH
      HERE 0 , COMPILE DROP  5 ; IMMEDIATE
    All of the other words remain the same.  You may have to alter this if
    yours is not a standard fig-Forth system.

Q3: How do I save the Forth image for later execution?
A3: This is conceptually simple, but in practice the code must be tailored
    for the system (each system I have has to do this with different code).
    1. The origin table must be patched so that upon a cold start the initial
       dictionary pointer, fence, etc., will be correct (so that the application
       will appear present).
    2. Creat a new file (I use "f.out" on unix).  Write to it the file header
       necessary for proper loading (this is system dependent).  The header
       contains the "magic number" and the sizes of the code data and bss
       segments.
    3. Write out the image.
    4. Close the file.

    I have successfully done this for V7 UNIX, our internal UNIX implementation
for a 68000 system here at Tektronix, CP/M 68k (which has executable files that
look suspiciously like UNIX), and CP/M 86.

	Of course the major problem with my solutions for Q1 and Q3 is that you
have to be able to do UNIX system calls.  If you don't have that ability then
you must add a CODE word to do it.  Mine takes the call number and a pointer
to the argument structure as arguments, thus it can do any system call.  I
add another layer to give functions which match section II of the UNIX manual.

Tom Almy
Tektronix Inc
(many hub systems)!tektronix!tekchips!toma

wls@astrovax.UUCP (William L. Sebok) (09/29/84)

Here are a few answers to a couple of recent questions.  These words have
been tested on the Forth at astrovax.

> While the recent distribution of Princeton FORTH is still fresh
> on our computers, I've been evolving a list of "how do you do it"'s
> and was wondering if any of you out there have had similar problems/
> successes:
> 
> 1. How do I implement the equivalent of ?TERMINAL  ?

A definition for ?TERMINAL (called KEY? in Forth 83) in Princeton Forth under
either BSD 4.2 or 4.1 would be:

HEX
find 4.2BSD #if  4004667f  #else 667F #then  CONSTANT FIONREAD
DECIMAL

VARIABLE NBYTES

: ?TERMINAL  NBYTES FIONREAD TYPER @ A1+ @ $IOCTL ?UERROR  DROP
 NBYTES @ ;

This returns the number of characters waiting to be input.  Ordinarily it only
knows about full lines of characters.  However when the terminal is in raw
mode (set by <KEY and KEY> ) it knows about individual characters.  Beware
that both <KEY and KEY> flush input, i.e. forget all pending input characters.
This is known as living with what Unix provides.  The next version of my vax
forth is likely to have ordinary input in CBREAK mode (to provide extra
interactive features) so it may not have those restrictions.

> 2. How can I implement my own control structures ( such as Charles Eaker's
>    CASE statement ) without resorting to otherwise unknown assembly language?

A version of the CASE you requested would be:

VARIABLE CSP

: OF  COMPILE OVER  COMPILE =  [COMPILE] IF  COMPILE DROP ;
 IMMEDIATE

: CASE  'S CSP ! ; IMMEDIATE

: ENDOF  [COMPILE] ELSE ; IMMEDIATE

: ENDCASE  COMPILE DROP
 BEGIN  'S CSP @ <> WHILE  [COMPILE] THEN  REPEAT ; IMMEDIATE

Alternatively OF could be

: OF  [COMPILE] CASE ; IMMEDIATE

using the old CASE, which does the same thing as OF should do.

This has no compile time testing.  I should consider adding some of that to
this implementation.  Right now this implementation shows its Forth Inc. forth
ancestry and little or no compile time checking.
-- 
Bill Sebok			Princeton University, Astrophysics
{allegra,akgua,burl,cbosgd,decvax,ihnp4,noao,princeton,vax135}!astrovax!wls