FreeForth and reverse-Polish languages

For discussions about programming, and for programming questions and advice


Moderator: Forum moderators

Post Reply
User avatar
cobaka
Posts: 523
Joined: Thu Jul 16, 2020 6:04 am
Location: Central Coast, NSW - au
Has thanked: 87 times
Been thanked: 49 times

FreeForth and reverse-Polish languages

Post by cobaka »

Hello @williams2

You might be interested in FreeForth

I will definitely look at FreeForth. I spent a lot of time with stack-machines similar to Forth.

I started a new topic, because my earlier "Q" was about the 6809 LEAX/LEAY instruction. But you mentioned Forth and Pythagorean squares. (Ha! I worked in a laboratory once. They had an Olivetti programmable calculator. On weekends I set it going calculating prime numbers. Very exciting, printing prime numbers! Would calculate for a whole weekend; on Mon AM would collect a long list of (very interesting) primes. This machine had a 256 program memory. Probably a mercury delay line (or something like that ... Have no idea how much it cost ... but I'll bet it was expensive ...) Yes, I'm quite mad. What's interesting about prime numbers?

I attached the first few pages of assembly code for a Forth-like engine I wrote for the 68HC11.
Few people will be interested so ... Plus - the original listing is over 500k, so I trimmed it - a lot. The first few pages will give an idea of capability. Nothing to do with Puppy/Linux/Bash, so ....

I say "Forth-like" because I got original source (for an 8085) from the chemistry dept of UoArizona.
Two fellows called Tilden/Bonner. Very generous. They asked that I retain/acknowledge their design as "Convers". I did that - even when I re-coded for a completely different uP. The 'HC11 version is interrupt-driven. I extended the concept of Forth "words" so that a work-space (with a separate stack) was allotted to a 'task'. Generally every task began on arrival of an interrupt. So ... do nothing until needed.

I wrote software to control an experimental brick-laying machine in the Convers language.
The program would measure distance travelled and "do things" to bricks and water and so on.

I've seen a small 8085 CPU run 4 loss-in-weight feeding systems simultaneously; the program calculated loss-in-weight by fitting a line of best fit to readings from a weighing-deck using the least-squares method.

Task hierarchy in the 'HC11 program was allocated by order in a "task-table". There were 8 task-spaces available.
Task switching was done by an optically isolated signal from the "outside" and based on assigned priority.
If a higher priority task interrupted a lower-priority task then the higher task would run to completion. After that the lower priority task would resume where it was interrupted.

I wrote this in 'HC11 assembly language. The code would be more elegant for a 6809 - but the '09 lacks the hardware capability of the 'HC11. The 'HC11 is a true microprocessor. The '09 is an 8-bit version of a mini-computer and would run C code very nicely. I say that because C is fundamentally a language built over a stack machine. But I'm rambling now; excuse me. I'll stop.

Собака

Attachments
11Si-4-0425.txt
(24.53 KiB) Downloaded 32 times

собака --> это Русский --> an old dog
"so-baka" (not "co", as in coast or crib).

User avatar
cobaka
Posts: 523
Joined: Thu Jul 16, 2020 6:04 am
Location: Central Coast, NSW - au
Has thanked: 87 times
Been thanked: 49 times

Re: FreeForth and reverse-Polish languages

Post by cobaka »

Maybe this should be in "way off topic" channel?

собака --> это Русский --> an old dog
"so-baka" (not "co", as in coast or crib).

muggins
Posts: 82
Joined: Mon Aug 31, 2020 1:31 am
Been thanked: 19 times

Re: FreeForth and reverse-Polish languages

Post by muggins »

Hello,

when you mention Convers it rings a distant bell for me, was Convers also stack based like forth? Do you have any links regarding Convers?

regards

User avatar
cobaka
Posts: 523
Joined: Thu Jul 16, 2020 6:04 am
Location: Central Coast, NSW - au
Has thanked: 87 times
Been thanked: 49 times

Re: FreeForth and reverse-Polish languages

Post by cobaka »

Hello @muggins
You:

was Convers also stack based like Forth?

Yes, Convers was a stack oriented language, rather like Forth, developed in (or by) the chemistry department at the UoArizona by prof Bonner Denton and Scott Tilden. I have the original paper published in '79. (somewhere).

A link: https://www.semanticscholar.org/paper/C ... eb256ece91

Another link: https://www.researchgate.net/publicatio ... laboratory

If the links don't work and you want a copy of the original article, pls let me know.
As I recall (I could be wrong) the original code provided positive integer arithmetic.
As I recall (I could be wrong) I modified this to give 16-bit signed integer arithmetic.
Amazing what you can do with integer arithmetic.
As I recall the original article provided floating point routines implemented in Convers code.
So - build the language and extend it to handle floating point - in code written in 'itself'.

If you want 8085 source - I think I could find it for you. Assembly language.
If you want 68HC11 code I can supply that too - but the source is hardware specific.

I also wrote a text editor - but that won't help much unless you have the memory-mapped video display board to match the editor software. It was stock-standard hardware for the 70s but primitive compared with what we have today. I would suggest writing/editing source under Windows/Linux and running a terminal emulator (eg TeraTerm).

All this is from a different age.

собака

собака --> это Русский --> an old dog
"so-baka" (not "co", as in coast or crib).

User avatar
cobaka
Posts: 523
Joined: Thu Jul 16, 2020 6:04 am
Location: Central Coast, NSW - au
Has thanked: 87 times
Been thanked: 49 times

Re: FreeForth and reverse-Polish languages

Post by cobaka »

question (see diagram below) I put free-FORTH here.
Is this a good location for the free FORTH directory? (I'm a beginner. That's why I ask.)

Tree+free_Forth.jpg
Tree+free_Forth.jpg (31.32 KiB) Viewed 576 times

Bye!
Собака

собака --> это Русский --> an old dog
"so-baka" (not "co", as in coast or crib).

User avatar
rockedge
Site Admin
Posts: 5847
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 2096 times
Been thanked: 2188 times
Contact:

Re: FreeForth and reverse-Polish languages

Post by rockedge »

I would move /ff and put it in /opt like /opt/ff

what goes into /opt/ff ? Do you need anything in the /ff folder to be in the $PATH?

williams2
Posts: 1026
Joined: Sat Jul 25, 2020 5:45 pm
Been thanked: 291 times

Re: FreeForth and reverse-Polish languages

Post by williams2 »

FreeForth is a bit different to, for example gForth.
You really need to read the help files.

In README it says:

"Installation instructions:

Create $HOME/ff as FreeForth-root-directory

create /usr/bin/ff as a link to $HOME/ff/ff

If you also want FreeForth source files of your own to be self-executable
even if not in FreeForth-root-directory, put as their first line:
#!/usr/bin/ff needs"

You need to read the documentation, because ff is different,
Especially read about "anonymous"
ff does not have a run mode and a compile mode.
If you type forth words it will compile them, just as it would compile a new forth word.
The compiled source does not have a word name linked to it.
It won't execute the commands you typed in until you type a semicolon.
FF does not need or use a compile STATE or an execute STATE.
So if you type in forth words like loopjng constructs or if...then constructs,
then the compiled words will work as if it was compiled into a new forth word.
Like this:

Code: Select all

# ff
\ Loading'ff.ff: help normal .now {{{ +longconds f. sqrt uart! hid'm
\ FreeForth 1.2 <http://christophe.lavarenne.free.fr/ff>  Try: help
 0; 2 3 + . ;
5  0; 
 0; bye
#

You need to read the files.

Code: Select all

# ff
\ Loading'ff.ff: help normal .now {{{ +longconds f. sqrt uart! hid'm
\ FreeForth 1.2 <http://christophe.lavarenne.free.fr/ff>  Try: help
 0; help
help` ( <name> -- ) displays name's related help (try: help bye)
  Items with no stack diagram are concepts, or hidden non-compilable words.
  Beginner: start with "help DATAstack" to understand "stack diagrams".
  Forth geek: look at "conditionals" and "flow-control" which are unusual,
    and at "anonymous" and "backquote" which are specific to FreeForth.
  Curious: start with the comments at beginning of file "ff.asm".
  see also: man win32.hlp bye ff.help  ff.ff
 0; 
 0; bye
 #

I just mentioned FreeForth, in passing. I thought it might be interesting. I didn't really expect anyone to spend a lot of time on it.

There is a fork of FreeForth somewhere in git. It changes some things, eg, allowing spaces in a string. But I don't think they ever published any files.

To execute a FF source file, you can do something like this:

ff needs /root/ff/pythag.ff

or:

cd /root/ff/
ff needs pythag.ff

User avatar
cobaka
Posts: 523
Joined: Thu Jul 16, 2020 6:04 am
Location: Central Coast, NSW - au
Has thanked: 87 times
Been thanked: 49 times

Re: FreeForth and reverse-Polish languages

Post by cobaka »

My question (about the installation directory) was based on the idea that Puppy Linux maintains a directory structure that is somewhat different. But I don't know anything about that, or the importance of that. At the same time putting an executable file in the wrong place can create ... errr ... problems.

I understand a little about the internal construction of RPN-stack machines.
I wrote two in assembly language (for Motorola & Intel) CPUs.
After that I wrote programs for the languages I coded.

You need to read the documentation, because ff is different,
Especially read about "anonymous"

Generally speaking, programs written in conventional languages (i.e. that use an algebraic notation) are easier to read than RPN/stack languages.
I suspect that the 'anonymous' mode is an attempt to resolve this - but at this early stage I'm guessing.

Fast-FORTH provides the capacity to access the bash command-line directly from within the language.
example: Type : !! ls -l ; <enter> and you will see the result of the common directory listing utility (from the bash CLI).
BUT! Not every facility from bash is available - or at least I haven't done that yet. Example: grep didn't work (for me) in F-F.
I-O redirection didn't seem to work (for me).
Fast Forth offers Linux system calls in the vocabulary. open, read, write & co.
Haven't tried any yet, but the concept is engaging.

Bye!

Собака

собака --> это Русский --> an old dog
"so-baka" (not "co", as in coast or crib).

williams2
Posts: 1026
Joined: Sat Jul 25, 2020 5:45 pm
Been thanked: 291 times

Re: FreeForth and reverse-Polish languages

Post by williams2 »

Forth is a language but it could be an operating system too.

A Forth operating system might expect to have access to the raw data of a floppy drive or even a hard drive.
fig forth (Forth Interest Group) could be setup with a floppy drive accessed as screens.
Each screen might be 64 bytes, for example.
The floppy drive would have no file system on it. So no files and no dirs.

You could type something like 0 load to make the fig Forth OS read the data on the first screen (64 bytes) of data and execute the data, which could be ascii text that a human could read and write.
Some of the source could be instructions to load other screens. For example, the first screen might have on it:

1 loaad 2 load 3 load 4 load 5 load

You could have an editor which you could use to edit screen 50 like this:

50 edit

There is a list if fog Forth editor words here: http://www.grm.net/~mikevald/4thedit.html

It's not a WYSIWYG. editor. You wold type command to edit a line, print a line, replace a line, insert a line, delete a line, move a line, copy a line, paste a line, etc, etc.The standard fig Forth editor is a line editor.

https://groups.google.com/g/comp.lang.f ... rlXphzuKlg

Many Forth have been written using files in a file system rather than raw screens.

There's a block editor in the FreeForth dir called bed.ff.
If it actually writes to your hard drive, it would destroy the file system on the hard drive.
So I.m guessing that it doesn't write directly to the hard drive.
But I really don't know for sure.

anonymous allows forth to not need the interactive state, everything that is typed in is compiled ready to be executed, and all the loops and if...thens works properly.

Most languages allow you to execute shell commands, so they can use gtkdialog guis.

Post Reply

Return to “Programming”