301 questions
2
votes
0
answers
16
views
Forth: Use 'I' as its value with 'CHAR'
I try to use special loop variable I with [CHAR].
With this minimal example:
: ex ( -- )
10 0 DO
[CHAR] I EMIT
LOOP
;
I expected '0123456789' to be printed but -obviously- I get '...
3
votes
2
answers
79
views
Why is : y : x ; legal? What does it mean?
I found that
: x : y ;
is legal (in gforth at least), but I can't think of a use case for this construct.
As I understand, executing x start a redefinition of y, but throw error at the closing ...
3
votes
1
answer
99
views
do, ?do and loop implementation
The DO ... LOOP execute always at least one time. If I want to skip execution when limit = index, I can put the loop inside a if ... then :
2DUP <> IF DO ... LOOP THEN
The recommended ...
3
votes
1
answer
52
views
Semantic of double WHILE
According to Forth Standard, you can implement PARSE-NAME using a combination of words that include this xt-skip:
: xt-skip ( addr1 n1 xt -- addr2 n2 )
\ skip all characters satisfying xt ( c -- f )...
3
votes
2
answers
62
views
How CREATE and buffers works?
This code create a buffer:
: bytes create allot does> + ;
When you execute
10 bytes a
create first create the header for the definition, and then insert one operation that pushed next address ...
2
votes
1
answer
111
views
Why do I get this error in gforth random number generotor random.fs?
I’m trying this word shuffle:
: random-range ( n -- r )
dup 1- random mod
;
: shuffle ( array len -- )
1- 0 do
i random-range swap rot over !
loop ;
but gforth is giving this error:...
2
votes
1
answer
87
views
How to avoid overwriting built-in words?
Just starting learning Forth. While practicing I defined a word I named min. It turns out that min is a built-in word. Now when I try to find the minimum of two numbers my own min runs!
Is there a way ...
2
votes
1
answer
103
views
How to insert literals in a colon definition?
I wrote a Forth interpreter for the J1 CPU, which I am now porting to Z80. In the new version, a colon word is a list of addresses to be called by the interpreter.
My problem is how to insert literals ...
3
votes
2
answers
130
views
Forth: What is the standard way to define a word using machine code?
I wrote a Forth interpreter in Assembler (core set), but is there a standard way to define a Forth word using Assembler instructions or directly machine code?
Example
I want to define "+" (...
4
votes
2
answers
80
views
Redefined but still alive
In section 4 of Starting Forth tutorial, the answer to the 5th question is:
: STAR [CHAR] * EMIT ;
: STARS ( #stars -- ) 0 ?DO STAR LOOP ;
: STARS ( n -- ) ?DUP IF STARS THEN ;
The third ...
3
votes
1
answer
173
views
How exit a BEGIN loop in Forth?
In many languages there is the BREAK statement, which allows you to escape an iterative cycle.
I can't find a word to escape a BEGIN-AGAIN or BEGIN-UNTIL cycle in Forth
I want to implement this code
...
3
votes
1
answer
67
views
Restrictions on stack use when defining words?
I was testing the use of [] inside a definition, I got an error:
: x [ here ] ;
:2: unstructured
: x [ here ] >>>;<<<
I understand that the cause of the error is having grown/...
2
votes
1
answer
74
views
Does CREATE waste space?
In gforth, CREATE, by itself, creates a variable, which takes some memory space: a few bytes to store the value plus two instructions to put the address on the stack and return:
create a ok
42 a ! ...
3
votes
1
answer
105
views
How can I use a word, which parses its input inside a definition of another word?
Suppose there is a word string which works like so: 64 string var$, and the result of var$ execution is an address of the first byte of the allocated memory and '0' to reflect the used space of the 64 ...
0
votes
0
answers
160
views
How can I transfer ASCII-files to the *console* of Picocom while being connected to a microcontroller
Setup
Using a Linux PC.
Via picocom I am connected to an ESP32 board running ESP32Forth, which gives me a REPL (kinda console).
Task to acchieve
Since cut and paste is highly unreliable I need to ...
2
votes
1
answer
358
views
Files I/O handling in Forth
While learning Forth I have the following issue, concerning files I/O handling.
I am reading this tutorial https://www.complang.tuwien.ac.at/forth/gforth/Docs-html/Files-Tutorial.html and trying to ...
1
vote
3
answers
179
views
Create a new word from string on stack in Forth
I need to use create on a string that I got from parse-name. Possible? Perhaps using the word evaluate?
3
votes
1
answer
111
views
How can I check whether enough arguments are passed to a word in Forth?
I have written this word to multiply two floating point numbers:
: fpmult { F: a F: b }
cr
." Result: "
a b f* f.
;
This works fine as long as there are either two fp's on the fstack ...
4
votes
1
answer
98
views
A weird problem in Forth when printing out the data stack and floating-point stack
I've started exploring Forth using Gforth on a Kali Linux computer. Thinking about stacks I always imagine the picture of the HP calculator stacks like so:
T <- bottom of the stack
Z
Y
X <- top ...
4
votes
1
answer
124
views
Making use of the return stack in the fibsum example in Forth
While learning gforth I have implemented the Fibonacci sequence in a few forms.
Below are some implementations of the fibsum definition, which sums up all the Fibonacci values up to a certain rank.
In ...
3
votes
1
answer
162
views
gforth : using the return stack
I am in the process of learning GForth.
Now trying to understand and get some practice using the return stack.
Can somebody with more experience tell me what I am missing ?
Here is the issue.
If use ...
2
votes
1
answer
370
views
How to write a GUI for Gforth
I would like to learn GUI for Linux Gforth, but documentation about that are, from my point of view, awful obsolete or both :) to be honest.
I already searched and tried many from all of What is the ...
3
votes
1
answer
62
views
gforth : Attempt to use zero-length string as a name
I am a beginner in this language : GForth.
Can someone with some experience tell me what the problem is in the code below ?
Here is a definition.
: collatzcount
variable count
0 count !
{ ini } ini
...
1
vote
1
answer
117
views
how to trigger capslock from code in gnuforth on linux host
how to trigger caps lock from code in gnu-forth ?
currently as a temporary solution I use
: caps s" xdotool key Caps_Lock" system ;
I'm looking for either a full gforth code solution ...
3
votes
1
answer
100
views
how to trap/disable CTRL+C in GFORTH
how to trap/disable CTRL+C in GFORTH ?
I often use common case...endcase statement on key but ctl+c is still possible to user.
I would add a function or something to disable it inside a word like
...
0
votes
0
answers
137
views
Why does this simple C program depend on the GCC optimization level?
I came across this surprising tidbit while translating jonesforth.s from x86 ASM to C with GCC extensions. depends_on_optimization.c is a "simple" C program which depends on whether it's ...
3
votes
1
answer
147
views
Forth: associate a name with a memory address
I use a word ->list that creates and returns an address. I don't always need to associate this address with a variable name, but I'd like that to be possible.
For the moment, if I want to do so, ...
4
votes
1
answer
101
views
gforth 2constant; explanation of the content?
in gforth, when I want to see the inner of the word 2constant , I use the command
see 2constant
then the output is..
: 2Constant
Create 2, 140549207084808 (does>2) ;
I could not find so far ...
4
votes
2
answers
189
views
How can I get a words string representation on the data stack in Forth (gforth)?
In gforth I can see a word's definition with see wordname and even get its execution token with ' wordname and also some information with the see subwords such as ' wordname seecol
I have not been ...
0
votes
1
answer
51
views
how to get a filename in gnuforth from user input to save it
currently I try to add a save function to a code from gforth 0.7.3
currently the version I have works fine if savefile is already existing (filled or empty as no importance both use-case are OK)
here ...
2
votes
1
answer
132
views
How to call a forth function from within assembler created through forth
If I create a forth word that simply calls ., I can see that it looks like this
: mytest . ;
see mytest
MYTEST
( 0010D7B0 E8BB70F1FF ) CALL 00024870 .
( 0010D7B5 C3 ) ...
2
votes
1
answer
175
views
How is the Forth data stack accessed in assembler?
I'm just starting to get into both forth and assembler.
In forth, if I create a word as follows:
: push5 5 ;
I have created a word that simply puts 5 on the stack.
If I ask to see the created ...
2
votes
1
answer
127
views
How can I write my own colon definition in ColorForth?
How can I write my own colon definitions in ColorForth?
I tried to write : in interpretation mode, but it shows :?.
Do I need to change the entry colour in interpretation mode?
Do I need to use the ...
2
votes
1
answer
277
views
How would one go about implementing a vector or dynamic array in forth?
I need to a dynamic array in forth, but I don't have any idea of how I could implement it. I searched online, and couldn't find any results either. I'm very new to forth, and just starting to learn it....
3
votes
2
answers
381
views
How is a Forth value different from a variable?
Reading the Gforth manual, a value can be changed using the word TO, so how is it different than a variable?
https://gforth.org/manual/Values.html
0
votes
1
answer
169
views
Why do I need to call `clear` after `initscr` with ncurses?
I have solved this problem in the sense I have code that does what I want, but I don't understand why it is necessary to do what I do, and I cannot see this behaviour documented, so I wonder if ...
1
vote
0
answers
110
views
Does Collapse OS have a "WORDS" word?
I have recently built Dusk OS (a Collapse OS derivative).
I was surprised to see that it does not have a WORDS word.
Does Collapse OS or Dusk OS have a word that shows all words in the dictionary?
1
vote
1
answer
148
views
FORTH implementation for embedded SOCs
I'm wondering if there is a good resource for FORTH implementations on recent SOCs.
I'm mostly interested in bare metal versions, something that can sit net to RTOS on an ESP32 or RISC-V for instance (...
3
votes
1
answer
220
views
forth implementation with JIT write protection?
I believe Apple has disabled being able to write and execute memory at the same time on the ARM64 architecture, see:
See mmap() RWX page on MacOS (ARM64 architecture)?
This makes it difficult to port ...
2
votes
2
answers
495
views
How do you keep track of all strings allocated in Forth and free them on time?
I see a lot of Forth code just doing s" Hello " s" world" s+ like it's nothing, but now that I think about it, this actually allocates 3 pointers, and lose two of them to the great ...
8
votes
1
answer
1k
views
What does "local variable" mean in the Forth programming language?
In C, local variables exist inside of a function and contain the values like this:
void main(){
int a = 5;
int b = 9;
}
In the Gforth manual, they describe the local variables like this:
: ...
5
votes
1
answer
228
views
How can I exit Forth with a non-zero exit status?
I would like to exit a Forth program (using Gforth 0.7.3) with a non-zero exit status.
I've tried:
1 bye
But the 1 is not interpreted as an argument to bye (and I didn't expect this to work anyway; I ...
2
votes
2
answers
220
views
How can I find and change a variable in an embedded Forth controller?
In repairing an instrument cluster, I need to replace a controller which is built on an Motorola MC68HC11 using Forth. While I was able to dump the whole memory, it is unknown which Forth is used and ...
5
votes
1
answer
207
views
How can I access a shadowed definition in Forth?
When a word is redefined, is it possible to access the old word?
Imagine there is a word foo defined and redefined
: foo ( n -- 2*n ) 2* ; ok
: foo ( n -- 2*n+1 ) foo 1+ ; redefined foo ok
10 foo . ...
7
votes
4
answers
638
views
Print double quotes in Forth
The word ." prints a string. More precisely it compiles the (.") and the string up to the next " in the currently compiled word.
But how can I print
That's the "question".
...
3
votes
1
answer
321
views
Multiline command-line editing in Gforth console
I have just started learning the Forth programming language.
I'm using Gforth on Ubuntu. In Gforth interactive console, I want to do indentation but it requires changing line. Enter key didn't work, ...
3
votes
1
answer
2k
views
What might cause a SIGILL (other than an illegal instruction) on RISC-V?
I am trying to load some Forth into my Forth compiler running on a RISC-V SBC (I do not believe this is a Forth-related question though):
>load /root/repos/riscyforth/test2.4th
: cuboid * * [ The ...
1
vote
2
answers
140
views
Skip over input stream in ATLAST forth
I'm trying to implement a kind of "conditional :" in ATLAST, the reasoning being I have a file that gets FLOADed multiple times to handle multiple steps of my program flow (I'm essentially ...
1
vote
1
answer
114
views
Get day name from a user specified date in Gforth
I tried to apply Zeller's convergence simplified method to get the day name from a user input date.
Simplified algorithm from
\ Zeller's Congruence
variable year 2 allot
variable day 2 ...
3
votes
1
answer
409
views
Strategy for AMD64 cache optimization - stacks, symbols, variables and strings tables
Intro
I am going to write my own FORTH "engine" in GNU assembler (GAS) for Linux x86-64 (specifically for AMD Ryzen 9 3900X that is siting on my table).
(If it will be success, I may use ...