 music |
 | | OSdata.com |
Forth-like routines for UNIX/Linux shell
summary
This subchapter looks at a set of Forth-like routines for use in the BASH UNIX (Linux, Mac OS X) shell.
Forth-like routines for UNIX/Linux shell
This subchapter looks at a set of Forth-like routines for use in the BASH UNIX (Linux, Mac OS X) shell.
basic approach
This supplementary material describes a method for creating Forth-like routines for use in the BASH shell.
The data and return stacks will be stored using a pair of shell variables, one of which is an array and the other is an ordinary scalar variable.
The Forth-like routines will be created as shell functions.
Everything will be stored in a shell function file that can be loaded manually or loaded as part of the normal shell start-up.
Eventually I intend to write two sets of C source code, one that people can commpile into their own copy of the official BASH source code and one that is part of an entirely new open source shell project that doesnt have the GNU infecting license. This alternative shell will be designed so that it can run on bare metal, allowing it to be used to deploy embedded systems.
stacks
Forth uses two stacks: the main data stack and the return stack.
For the purposes of the BASH shell, we will implement both stacks with a combination of a top of stack pointer variable and an array for the stack. The top of stack pointer will hold the array index of the top of the stack. The stack will build up from the array indexed as one. An empty stack is indicated by having the top of stack pointer variable point to the zero index of the stack array variable. The bottom of the stack will actually be the one index of the stack array variable.
$ export DataStackPointer=0
$ declare -a DataStack='zero'; export DataStack
$ export ReturnStackPointer=0
$ declare -a ReturnStack='zero'; export ReturnStack
$
Thats it for the required variables! And, yes, those could all be placed on one line, but I spread them over four lines for additional clarity.
functions
These are the functions for a Forth-like working environment. Not all of these functions exist in a real Forth. Most of these functions are have modifications from standard Forth. Many standard Forth functions are missing.
In particular, this approach treats the stack as a stack of objects. No matter how much memory space an object takes up, it only takes up a single stack slot. In a real Forth, data is stored on the stack as raw binary strings, characters, or numbers and the programmer is responsble for keeping track of how much memory every item actually uses.
free music player coding example
Coding example: I am making heavily documented and explained open source code for a method to play music for free almost any song, no subscription fees, no download costs, no advertisements, all completely legal. This is done by building a front-end to YouTube (which checks the copyright permissions for you).
View music player in action: www.musicinpublic.com/.
Create your own copy from the original source code/ (presented for learning programming).
Work on this project is very slow because I am homeless. I am available for work if someone can provide an indoor place to work in Costa Mesa, California, electricity, internet connections, a flat raised working surface (such as a table or desk), a sitting device (such as a chair or stool), and a fully functional reasonably modern used computer. Im already homeless, so you dont need to pay me (and I understand how much business people hate the minimum wage law). Just give me a chance to work.
Because I no longer have the computer and software to make PDFs, the book is available as an HTML file, which you can convert into a PDF.
Names and logos of various OSs are trademarks of their respective owners.