Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make the entire float stack visible?

Tags:

stack

forth

The Forth programming language uses a stack to pass parameters between functions. Instead of given a subfunction a number as a direct information, the value is put first to the datastack and the other function is taken the value from the stack.

A special feature of Forth is to handle integer values and floating point values on different stacks. That means, it's not possible to push a float value to the datastack. While writing short programs in Forth, it's often needed to debug the codelines.

This is possible with printing out the content of the stack. If the developer sees, what's on the stack right now, he/she understands easily what's wrong with the code. Printing out the content of the stack is important for bugtracking.

After pushing two numbers to the normal datastack, it's possible to show its content. In the example, both integer numbers are printed out after entering the “.s” command. But, if I'm pushing two float numbers to the dedicated float stack, only the last element is shown. How can I make the entire float stack visible?

gforth example.fs
1 2 .s cr        \ <2> 1 2
1.0e 2.0e f. cr  \ 2.
bye
like image 805
Manuel Rodriguez Avatar asked Dec 18 '22 19:12

Manuel Rodriguez


1 Answers

Gforth has the f.s word, doing exactly what you need.

See the "Examining" section of the Gforth manual:

like image 199
Vlad Avatar answered Jan 09 '23 04:01

Vlad