-
Notifications
You must be signed in to change notification settings - Fork 1
turnimator/tpforth
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
TP-FORTH is just an experiment, but I've decided to develop it as much as I can. Updates will be Forth-coming every week, so watch this space if you're interested. TP-Forth is easy to hack--if you want to add something please tell me. One day, it could become a full Forth. Quirks that may or mayy not be fixed in the near future: To print a string, you have to do this " This is the string I want tc o print" S. Alternatively " This is the string I want to print" TYPE Strings a C-strings To SEE a word, you have to " X" SEE \ where X is the word you want to SEE. To load a program: LOAD ( s -- ) Example: " exec.fs" LOAD will load and execute the program stored in exec.fs To edit a program: EDIT ( s -- ) Example: " exec.fs" EDIT To run a Linux command like: SYYSTEM (s -- ) Example: " ls" SYSTEM will run the OS command "ls". Explanation of the program remote_exec.fs: ------------------------------------------ Words used: ----------- TP-Forth is case sensitive. All built-in words must be in UPPER CASE. VARIABLE(X) creates a variable with the name X ! ( X V -- ) Stores the value V in the variable X NQCREATE(s n--a) - takes a string on the form "IP_address/port", - an integer specifying the queues length (how many bytes you can write to it before it blocks), - creates a network queue, - and stores its reference on the stack. SEXEC ( S -- ) takes a string S and executes it as a word (for now, this only works with dictionary words) <NQ ( Q -- S ) receives data coming in on the queue Q and places it on the stack as a string S @ ( X -- C ) takes a variable X and places the contents C on the stack S. ( S -- ) prints a string S. You can also use the more familiar TYPE. SPAWN ( XT -- ) Runs the XT as a background task ' ( W -- XT ) Takes a word W and leaves an XT on the sttack The program ------------ VARIABLE myq myq " 192.168.7.100/5000" 128 NQCREATE ! : rd myq @ <NQ SEXEC ; : rl 100 0 DO rd CR LOOP ; : t1 " This is t1" S. CR ; : t2 " This is t2" S. CR ; : t3 " This is t3" S. CR ; : t4 " This is t4" S. CR ; : t5 " This is t5" S. CR ; ' rd SPAWN Create a variable called myq VARIABLE myq Create a queue to communicate with the TP-Forth running on machine with ip 192.168.7.100, port 500 and store it in myq. +Place myyq on the stack | + Create the queue, placing its reference on the stack | | + Store the reference in the queue +--+----------------------------------+--- myq " 192.168.7.100/5000" 128 NQCREATE ! Define a word that will read data from myq and execute them : rd myq @ <NQ SEXEC ; Do 100 reads : rl 100 0 DO rd CR LOOP ; : t1 " This is t1" S. CR ; : t2 " This is t2" S. CR ; : t3 " This is t3" S. CR ; : t4 " This is t4" S. CR ; : t5 " This is t5" S. CR ; ' rd SPAWN - Run rd in the background: Place the word rd's XT on the stack and run it as a background task To test the program, you need two instances of TP-Forth running on two different machines. On one machine with example address 192.168.7.101, you run remote_exec.fs. On the other, with example address 192.168.7.100, you run a program like this: myq " 192.168.7.101/5000" 128 NQCREATE ! \ Note the IP address! : wr myq @ SWAP NQ> ; \ Create a word that will write a string to myq. " t1" wr \ will execute the word t1 on the other machine ---------------- There is a video that shows how to run it: https://youtu.be/h8_L-AM4Csc A video about queue communication: https://youtu.be/tZkXTb1oX0U A video about creating tasks: https://youtu.be/GFkKPTmdbuM Last but not least, a presentation with some humour about the project: https://www.youtube.com/watch?v=M58AmFgi9nE
About
TP-Forth is a small smart-token interpreter for Forth code
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published