PropForth - imaginary bug

I was running a blinking LED program in the PropForth V5.0 html (Example 2) and found that using the infinite loop Begin..... Again results in the Serial console being ignored.
Once entered, the only way to exit is via a hard reset of the Propeller.
I would like the following:
1. Being able to use a CNTL code from the terminal to drop out of the loop and return to stack.
2. Being able to code one cog to enter an infinite loop and then being able to shift to another cog for other tasks.
I am not sure if this is a bug or I just don't know enough.
I guess I can use Saveforth to retain the word before calling it, but if you just immediately try to run the word, there is no means to save your work. And in the case of using Minicom, you have to disconnect the wire before quiting OR the exit from your terminal will reset the Propeller somehow.
Once entered, the only way to exit is via a hard reset of the Propeller.
I would like the following:
1. Being able to use a CNTL code from the terminal to drop out of the loop and return to stack.
2. Being able to code one cog to enter an infinite loop and then being able to shift to another cog for other tasks.
I am not sure if this is a bug or I just don't know enough.
I guess I can use Saveforth to retain the word before calling it, but if you just immediately try to run the word, there is no means to save your work. And in the case of using Minicom, you have to disconnect the wire before quiting OR the exit from your terminal will reset the Propeller somehow.
Comments
(my example keywords may be off the mark a bit - my memory is old and fading and I haven't PropForth'd in a while but the ideas are relatively sound)
For #1, I don't think you want an infinite loop (or any loop for that matter) incurring keystroke detection overhead unless you explicitly code it. Through the use of the key? word (I think there is one that waits for a key to be pressed and another that just checks if a key was presed, but I forget), you can check for console input and then abort or continue as needed. This way, your looping word can incur overhead if you want it and my looping keyword doesn't.
For #2, write your looping word and then from the console (COG talking to serial I/O), use the cogx word to start your looping word on another COG. All the COGs share the same dictionary, so it doesn't matter which COG runs which word. You can move the console around and you still see the same dictionary.
Try "loopy n cogx" where loopy is the word you wrote and want to run on another COG and n is the number of one of your free COGs. Should you want to kill the looping COG, then you can use "n cogstop" to kill it. If I remember, there are both cogstop and cogreset words in PropForth.
when developing, saveforth is your friend. When you reset to a saved image, you can always forget back to your "good" point in the dictionary and add in the stuff you are testing again after fixing something.
Yes, it would appear to be a bug, but its not.
Unlike most languages which attempt to "Hold Your Hand" with the result of larger, slower code.
Forth does virtually no error checking. It leaves this up to you if you want it.
If you need a "Bail Out" in your WORD you have to put it in their yourself.
The philosophy of forth is to keep core words as simple and speedy as possible.
Duane J
How do I run 4 infinite loops on 4 separate cogs?. Currently, I only can run one on one cog.
BTW, philosophy is the luxury of a full belly, I'd prefer functionality leaning towards simplicity.
Yes, I considered adding key and key?, but it appears the rs232 is shut out completely, maybe key? would revive the connection.
ANS Forth does have 'bail out' from the terminal for any word that is running. I'll have to look around a bit for it, but there is one. I fear this is more fundamental and about the Propeller lacking interrupts.
I will try starting it on another cog as advised in #2. I guess I am that idiotic stage where I know just enough to start screaming 'bugs!'
There are lots and lots of words in PropForth that ate non standard and are only found in the HTML doc (before that, you got to dig through the code).
You have probably already figured this out. When you start PropForth, COG7 is running the serial interface to the PC and all the others are running a PF interpreter. The console I/O is connected to COG6. If you want to change console I/O, there is a word >con which will make any COG the one you at talking to through the terminal. 0 >con makes COG0 the active console COG, for example.
Assuming you reset and haven't changed anything, the following will start your infinite-loop word on COGs 0-3:
Infinite-loop 0 cogx
Infinite-loop 1 cogx
Infinite-loop 2 cogx
Infinite-loop 3 cogx
At this point, COG0-3 are looping in your word, COG4 and COG5 are idle in the PF interpreter and 6 is talking to you through the console and 7 is doing serial I/O with the PC.
There are cogs top and/or cog reset words (I forget which and have no handy reference) to stop the cogs you started.
Now, you have complete mastery of a Propeller environment!!
If you want to build H/W interrupts, you have plenty of pins to play with. Set one in one cog and check it in another!!
EDIT: I was going to fix the iPad typos but I'm too lazy today. If anything doesn't make sense or can't be deciphered, just ask! :0)
Discussion is good! You can't always find everything you need and we all learn together this way!!
Thankfully PropForth provided a 'rather complete' (not completely complete) list of words that I go over every day or two. At this point I do a bit of tutorial word, I read a bit of Forth history, and I go over the ANS Forth and PropForth word lists to see what I know and what I want to explore.
Maybe in a month or two it will sink into being something that works well. But for now, I am just bumping into one thing after another.
The extension you want:
key? - checks if a key is pressed, so this will look and return true is key press.
key - gets the current key press
abort? - exits to interpreter quit loop if true.
the overhead is consistent every pass until the key press, escape bails out of whatever your doing and returns to the command prompt.
If you are on cog6, you can use bail to allow breaking out of any running loop.
If you've launched any word in any other loop besides the one running console, you can just send it another command (such as quit) to stop it.
I tend to add junk like this (non application overhead) when experimenting, but "pros" expect the development words removed from any final application.
the word "words" lists out all the definitions in tha propforth dictionary from most recent to oldest.
the ones in the beginning of the dictionary (at the bottom of the print out) with the odd looking underscores and prefixes are only used internally, and not generally executed from the command line unless you are redesigning the dictionary (too advanced for me).
I am studying GForth at the same time and it doesn't shut out the console interface. I think one can simply enter Abort to kill the loop in such a situation. It is so true - If you have seen one Forth, you have seen one Forth.
It seems that a lot of the non-standard words for the Propeller are simply either constants or variables tied to a particular register in the Cogs or an assembler word translated to a Forth word -- not too hard for someone that has used the Propeller a bit. AND, it is very helpful to actually see immediate results to confirm what the Propeller is really doing.
Yes, yes .... I do know about Words.
But I am finally using copy and paste to get that complete listing into a spreadsheet or a text file where I can compare it to documentation in the HTML and the Reference List. Words is indeed the bottom-line and using See is helpful if nothing else is available.
For instances, Waitcnt can be observed in a good configuration or one that ends up with excessive state due to a rollover. Some Propeller students would appreciate being shown directly via an interpreted language, rather than muddle through compile and load.
No 'see' provided. This word allows one to peek at the actual code for the construction of the word that you 'see xxx'. I got very enthused about using this in GForth as I can view exactly what a work I have created contains before I go about modifying it for a better result.
I suspect youall will just say 'the Forth philosophy is....'
But is also a very useful word for learners to reverse engineer the whole of Forth. And why learn Forth, if you cannot use it learn more of it?
I know I am whinning. I have had two cogs doing complicate blinks independently for hours via using Cogx. And I cut and pasted the Words output in order to continue to review PropForth's rather unique dictionary. I am just a bit stumped about looking under the hood.
I guess I can refer to the address of a word and do a Dump to get it all in machine code.
Aww, and here I've been trying to help out.... :0(
I'd love to have a see word, I always have the .f files open in an editor so,I can look the words up as I have questions. I don't think it's philosophy here, just nobody has written the word and/or shared it. I think it was Peter (sorry if I'm wrong) who wrote a disassembled a while back. It may be buried in the last PropForth thread. I didn't grab a copy then because I was otherwise occupied (distracted/overwhelmed/frustrated/etc). If I sit down at a real PC, I'll have a go at finding it.
Did you find the word index on the Wiki? It at least gives you a start by telling you which .f files a word is defined in. I created that to support by brute force way of learning. It makes the initial search easier. Many words are defined in multiple .f files to reduce dependencies on loading things in the proper order or loading stuf you don't need just to get a few words from a module. They are wrapped in if directives to avoid being redefined.
I still think you are asking good questions. You are a much more thorough and focused learner than I am and that helps me learn and think about things. It's a different language and there's a lot to wrap your head around in the various 'dialects' you are covering.
I have an 11 years old, you, sir, are NOT whining!!!
http://forums.parallax.com/showthread.php?138399-Propforth-5.0-is-available-for-download&p=1107790&viewfull=1#post1107790
PropForth 5 decompiler
EDIT: There's a newer version on the PropForth Wiki, here. (I know, read the documentation!! I should know better!!)
You realize you've forced me to hook up a Propeller and play.....sadly, something I haven't done in months.
I cut and pasted his .fth file into a fresh install of PropForth 5.02 (or .03 or whatever the last pre-release was)
Once loaded, I did a decomp cogx, since we've been talking about that word. and got this:
When I look in the PropForth .f files, I find this code for cogx:
in PropForthStartKernel.f
It looks like a winner as far as the decompiler goes! Yay, Peter!!
If you want, you can always rename the word see, so it's more standard to the Forths you are working with.
Thank you for making me find this, it will be a much nicer tool than digging through the source code to find words. I'll have to include it in my debug file.
It's also nice to get to play with PF again, I may need to spend some time getting reacquainted with my old friend, today! Football and Forth Sunday!!
... it was provided in the beginning, but nobody used it, and nobody seemed to want it, and Sal found that he didn't need it. And we must remove unwanted code.
BUT since you asked for it, we can see about putting it back, maybe in the developer extensions (so that are only loaded in dev, and are not automatically included in the kernel?).
Please open an issue requesting this function.
Yes, I am using GForth that is likely a 'big bloated Forth' to help me along. I don't have any insight into what other's used to learn Forth, but if you learned way back in '79, it may not be useful to a newcomer. In some cases, GForth merely provides machine code when 'see' is used, but I can at least review my own definitions to see what I've done.
So to get up to speed, I am studying Forth on the Propeller as PropForth and working with the GForth tutorials for ANS Forth at the same time. Back 1980, I was married to a bar stool in Eugene, Oregon, in a fog of Blitz beer, and I really missed all this.
Having a .f file with 'see' is extremely useful to me at this point. I just tried to preview all the words listed by Words and there are even more than I expected. I realize space is an issue, but so is providing useful tools for new learners to develop their own ability to discover Forth.
Thank's again to everyone for being helpful.
In many ways Forth reminds me of my early days with studying Chinese characters. One just has to keep cramming in characters until the brain catches up with associating meaning to them. Since even a basic reader has to have 2000 characters in order to read childrens books and easy stuff, one tends to fumble around a lot in the beginning.
BTW, philosophy is too deep for me.
Let's say "optimized for smaller footprint implementations", ok?
I tried to learn Russian a few years back (my hardest language attempt). It's always humbling when the children you see in a country are able to tackle their native tongues. Maybe we should train programmers at a very young age!
I've become a big fan of "decomp" today. It's a wonderful tool to have available and sure beats reading the .f files.
Finally, congratulations on your "divorce"!!
Or take your time, instead of rushin'.
My impression of Forth is that it is very much a computer language equivalent to Esperanto.
Esperanto is a language that everyone has an equal input in creating as no one source can claim to be its origin. But by taking such and approach, nobody really knows what Esperanto is and only a few zealous souls choose to learn it.
Tyranny has a bit of stabilizing effect on language use.
Russian, Chinese, or whatever - kids are much more able to assimilated a new language fully and quickly than adults. Actual changes in the brain at puberty seem to slow down the whole process there after. And changing to a Cryllic alphabet or Chinese characters really force the learner to use parts of the brain that they haven't used for language before.
Divorced the bar stool in '83.
I hope these words will bring more new users to you. Writing documentation is endless tedious and rarely up-to-date. One has to think, think, thing; then write and rewrite.
I changed the thread heading to 'imaginary bug' and we have cleared up my misperceptions about the endless loop in PropForth. I can get other cogs to commit to an endless loop while having the terminal interface remain up for uncommitted cogs. But it seems the only way to break the loop is to kill the committed Cog. Maybe I am wrong about this.
The 'begin... ....until' endless loop is a great way to explore Cog control without having to read (or write) documentation about what is happening. I may yet learn to break into the loop and have the stack move onto other items - such as providing a message that the loop has been broken. Now, I am trying to learn when and how Abort and Abort? work.
our model is that the docs are driven by user questions. (me simply writing on random topic did not appear to yeild benefit). so you questions to date have been a primary driver, please do not slow down. in fact, if you were to create a page on the wiki for each "discovery" it would benefit many. your point of view is much closer to a new user than mine.
abort end any yask, and return to a bare command line running the interpreter. abort? consumes one item from the stack, if true (non zero) it aborts, otherwise does not
These Forth threads have been getting rather long. It concerns me that their winding nature is rather counter-productive to newcomers. I know from my own experience that when threads get too long, it shuts out a lot of readership.
To avoid that, I started doing some Parallax Blog entries of a more detailed nature about beginning Forth on the Propeller. The first two entries have been rather general.
The First - Mostly about my own approach of learning GForth and PropForth in parallael and the importance of reading the most up-to-date version of "Starting Forth" if you have never done so.
The Second - A survey of the rather diverse world of terminal emulation programs that are avaiable for free. I suspect that many new users feel terminal emulation programs are too complicated or they feel they must buy the best or the don't know how to get one that is well-supported with tutorials and a large user base.
The above blog entries were rather general in nature. I have a lot I am trying to grasp. For the most part - the role of the Dictionary is central, so how do I come to terms with what it is. What do I need to know about the Pad? What is going on after a word is created? Understanding that Forth uses colon/semi-colon words, constants (which can be doubled), variables (which also can be doubled), and create (as a means to set aside larger spaces for arrays, etc.).
Somehow, that all may get into a Third Blog. But Wiki's for PropForth may be very rewarding - more objective and modular to edit.
And there are also the simple problems of learning one's ways around the existing resources -- such as the .f files and the actual .spin files for PropForth. TachyonForth seems to want to release binaries instead, but I am seeing some convienence in having the .f files to read if their is not other documentation for whatever I am pondering.
I still am reading a bit of history of the evolution of Forth and some overview material on Forth -- such as the Wikipedia entry for Forth. These things I do so that I don't just get lost in one version. I thinking the history is very important in this language as changes pull away words and provide new ones in a rather mysterious way if you don't know something of the history.
See, decompile, and words of related functionality are extremely helpful to me right now and I hope that they will continue to provide a big assistance.
But at some point, more overview of what PropForth is and how it compares to the 'big bloated Forths' is going to be helpful. Already, I have become rather dependent on features in GForth that make typing very easy. These small lean, mean Forths for micro-controllers cannot afford to have some rather nice options to automatically retype and to fill in the rest of a word when you don't remember it all.
I don't expect the small Forths to try to provide these features, but knowing about the contrast keeps everything in perspective. PropForth really is more about managing 32 i/o pins, while GForth is all about doing bigger projects on a complete OS. Nonetheless, Forth will always have the heartbeat of a number cruncher. I can do some rather dramatic 32bit calculations.
Lots to study, lots to learn. But as far as Prof_Braino and Sal, I don't really want them working hard just to appeal me. Other people need to present themselves and dare to ask the dumb questions. I will learn even more from other people posting.
My guess is that translates into "The word 'abort' ends any task and returns to a bare command line running the interpreter. While the word 'abort?' consumes one item from the stack and if true (a non-zero), it aborts, otherwise it does not.
Sorry to be so pedantic, the combination of typos and loose grammar in the beginning of that entry make it rather hard to decypher. You can copy and paste that snippet. Put it in your wiki and smoke it... so to speak.
Still, if you call a loop with Begin, you have to include your own 'abort?' within the loop or you will never get this feature to work. The Begin... loop does pull a value off the stack to decide to keep going. If just se to 0, the infinite loop shuts out all until you resent the Cog - plain and simple. I have no idea about other loops and the 'abort' or 'abort?'. I will have to explore.
On other fronts, I saw a request in the Propeller Forum of how to get the output of a simple button down condition to a serial port in SPIN today. OMG, the amount of code to do that is rather huge and complex; while Forth seems likely to be so easy and short for such a task. It is hard not to jump in and say 'Use PropForth' and it is just that and that and there you go.
goterm provides the OS command line support. so you can scroll and edit the command line history like in linux. i meant to add this to the dev extensions for jupiterace; it always takes too much memory until we require SD and that breaks the "runs on any prop chip" rule so was not added to the standard kernels.
please try to create/edit pages on the wiki, you have many useful insights we want to capture
In this modern world, gadgets have to travel with you.
I have to find out what GOTERM is. I found this ==> http://code.google.com/p/propforth/wiki/GoSetup20120511
But I am not up to speed (once again).
i forgot the posted GO is the windows prototype. it all works the same on linux.
we should have the final v5.3 shortly, i know i've been saying this for months