How can I get GForth to compile? Or can it only interprete? If GForth
can't, is there a Forth compiler for Linux?
Hello, a Forth newbie here!
I read the newsgroup's FAQ and the gforth manual, but have still some questions.
How can I get GForth to compile? Or can it only interprete? If GForth
can't, is there a Forth compiler for Linux?
Kindregards
Peter Wiehe
Hello, a Forth newbie here!
I read the newsgroup's FAQ and the gforth manual, but have still some >questions.
How can I get GForth to compile? Or can it only interprete? If GForth
can't, is there a Forth compiler for Linux?
Kindregards
Peter Wiehe
How can I get GForth to compile? Or can it only interprete? If GForth
can't, is there a Forth compiler for Linux?
On Monday, November 20, 2023 at 4:33:19 PM UTC-5, Peter Wiehe wrote:
Hello, a Forth newbie here!
I read the newsgroup's FAQ and the gforth manual, but have still some
questions.
How can I get GForth to compile? Or can it only interprete? If GForth
can't, is there a Forth compiler for Linux?
Kindregards
Peter Wiehe
To further expand on this question, it sounds like your are looking for a way to compile Forth to standalone executable program.
GForth and most Forth systems are more like LISP in that they are image based. You compile your code into the image.
The entire image can be saved and run as an application on many systems but your are bringing along lots of extra stuff.
(although in some cases it is still less than some libraries in other languages.
To do what I think you are looking for, you may be able to use the GForth cross-compiler but I have never used it.
https://gforth.org/manual/Cross-Compiler.html
-----------------
Interpreting a compile-only word
-----------------begin<<< game_loop game_end until
So "begin" is not suitable for interpreting? Seems strange to me. Or
what is the reason why this code produces an error message?
Kind regards
Peter Wiehe
-----------------begin<<< game_loop game_end until
I get this error in GForth on Linux:
-----------------
Interpreting a compile-only word
-----------------begin<<< game_loop game_end until
So "begin" is not suitable for interpreting? Seems strange to me. Or
what is the reason why this code produces an error message?
Thanks for all the answers, they were really helpful.
Sorry that my question was unclear. I didn't mean compiling the Forth interpreter to an executable, but I meant compiling my little
programwritten in Forth to a binary.
BEGIN is a control-flow word, and control structures are implemented
by compiling unconditional or conditional branches; that only works
while compiling code inside colon definitions. Also, this is not just
an implementation choice, BEGIN leaves something on the control-flow
stack (which is the same as the data stack on Gforth and most other
systems) during compilation which is then consumed by the UNTIL in
this example. This works because the data stack is otherwise mostly
unused when compiling words.
A number of people have found the limitation of BEGIN etc. to colon definitions inconvenient, and have implemented various forms of
interpreted control structures (e.g., by switching to compile state
and temporarily compiling the code after the BEGIN).
However, all of the approaches I have seen have some other limitation,
so we did not implement any such approach in Gforth, except that there
is, e.g., [begin] ... [until], which uses a completely different
mechanism.
- anton
Thanks for all the answers, they were really helpful.
Sorry that my question was unclear. I didn't mean compiling the Forth >interpreter to an executable, but I meant compiling my little
programwritten in Forth to a binary.
I will check ciforth, lina etc. And yes, my background so far is C.
I have another question which seems to be related because the error
message seems to imply that:
I get this error in GForth on Linux:
-----------------
Interpreting a compile-only word
-----------------begin<<< game_loop game_end until
So "begin" is not suitable for interpreting? Seems strange to me. Or
what is the reason why this code produces an error message?
Kind regards
Peter Wiehe
I find Forth very fun to work with mostly because it makes you break
things into small functions. Which are easy to write and test. With complicated functions keeping track of what is one the stack gets to be
a pain.
Thanks for all the answers, they were really helpful.
Sorry that my question was unclear. I didn't mean compiling the Forth >interpreter to an executable, but I meant compiling my little
programwritten in Forth to a binary.
Kind regards
Peter Wiehe
David Schultz schrieb am Dienstag, 21. November 2023 um 21:10:00 UTC+1:
I find Forth very fun to work with mostly because it makes you break
things into small functions. Which are easy to write and test. With
complicated functions keeping track of what is one the stack gets to be
a pain.
If the stack depth becomes too unwieldy, I use locals.
Programming and debugging is then also faster.
On 22/11/2023 8:50 pm, minforth wrote:
David Schultz schrieb am Dienstag, 21. November 2023 um 21:10:00 UTC+1:
I find Forth very fun to work with mostly because it makes you break
things into small functions. Which are easy to write and test. With
complicated functions keeping track of what is one the stack gets to be
a pain.
If the stack depth becomes too unwieldy, I use locals.Locals don't eliminate unwieldy - they only make it manageable.
Programming and debugging is then also faster.For C programmers perhaps. A forth programmer would ask what's
wrong about this code that it has become unwieldy.
dxf schrieb am Mittwoch, 22. November 2023 um 11:39:15 UTC+1:
On 22/11/2023 8:50 pm, minforth wrote:
David Schultz schrieb am Dienstag, 21. November 2023 um 21:10:00 UTC+1: >>>> I find Forth very fun to work with mostly because it makes you breakLocals don't eliminate unwieldy - they only make it manageable.
things into small functions. Which are easy to write and test. With
complicated functions keeping track of what is one the stack gets to be >>>> a pain.
If the stack depth becomes too unwieldy, I use locals.
Programming and debugging is then also faster.For C programmers perhaps. A forth programmer would ask what's
wrong about this code that it has become unwieldy.
I know it's always the same red bandanna called locals you're barking at.
I don't want to see you stack juggling complex vectors. :o)
Hello, a Forth newbie here!Hi,
I read the newsgroup's FAQ and the gforth manual, but have still some questions.
How can I get GForth to compile? Or can it only interprete? If GForth
can't, is there a Forth compiler for Linux?
Kindregards
Peter Wiehe
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 503 |
Nodes: | 16 (2 / 14) |
Uptime: | 234:59:14 |
Calls: | 9,885 |
Calls today: | 7 |
Files: | 13,794 |
Messages: | 6,206,958 |
Posted today: | 2 |