PDA

View Full Version : PropellerForth - announcement and multitasking tutorial (192 simultaneous tasks



Cliff L. Biffle
11-13-2006, 01:54 PM
There's been a discussion thread on PropellerForth for some time, but this is a bit of a milestone, so I'm starting a new one.

The PropellerForth website is up at www.cliff.biffle.org/software/propeller/forth/ (http://www.cliff.biffle.org/software/propeller/forth/), and the multitasking code is now a standard part of the distribution (which you can download there).

Documentation will be coming soon (along with some other niceties, like non-sucky serial I/O) -- but since y'all are my favorites, here's a quick overview of the multitasking system. This information is current as of the 20061112 release, and includes code snippets you can copy-and-paste to play along.

This is the same system that (in the benchmarks I posted to the other thread) supported 256 independent tasks on a single Cog -- but it's become more powerful, more flexible, and easier to use.

The Tasker

Most new code in this release is in support of the tasker, the Forth component that handles in-Cog multitasking. While there is no standard Forth multitasking API, I've reworked the tasker words to be closer to the API shared by several commercial Forths. Like most of the rest of PropellerForth, the tasker itself is written in Forth, and the user can modify it as she pleases.

Currently, the tasker is an optional component, and is off by default. It must be enabled before executing any of the tasker words, including pause:



init-tasking




At that point, you can check your current task:



this-task .




The value printed is the ID of your task -- or, more specifically, a pointer to your task's task control block. If you've just fired up PropellerForth and haven't skipped ahead in this tutorial, you're running in the default interactive task, named OPERATOR (that's you!). Try executing operator and printing the result; it should match what you saw from this-task.

There are two types of tasks, named and anonymous. Named tasks are accessible from Forth code in all Cogs by a distinguished name; OPERATOR is the most obvious example, but you might also have DISPLAY-DRIVER or FILESYSTEM-MANAGER. Anonymous tasks, on the other hand, are accessible only through pointers to their task control blocks. We'll play with anonymous tasks in a bit.

Named tasks are created by the word task. It takes as arguments the depths of the data and return stacks, as well as the size of its USER area (task-local variables). Let's create a task with small stacks and the default user area size:



8 8 #user task blinky




Blinky is a named task; you can get a pointer to its task control block by entering its name.

When tasks are created, they sit dormant and unscheduled. That's sad. Let's give Blinky some code to run.




: blinky-loop
begin
255 ledemit
pause
0 ledemit
pause
again ;




The word pause transfers control to the next task. (You can try pause right now if you want, but with only one scheduled task it's not very interesting.) So blinky-loop loops forever, alternately toggling the LEDs and yielding control like a good task. (This is an important point to note: the code run in a task must loop forever, until it gets shut down by another task. This may change in a future release.)

We can have Blinky run this code using activate:



' blinky-loop blinky activate




If you're on a Demo Board, your LEDs just came on. (If you're on some other board, whatever you've attached to pins 16-23 is now on. Good luck with that.) Try entering pause and pressing return. Each time you do this, it passes control back to Blinky, who toggles the LEDs and passes it back.

Congratulations, you now have the world's most labor-intensive turn signal.

When you're working with the interactive Forth interpreter, Blinky is paused. This is important to keep in mind. The next generation interpreter will pass control to background tasks while awaiting your commands, but I haven't finished this yet.


Now, let's spawn some more tasks. Here's a word, son-of-blinky, that will create an anonymous task to do the same work as Blinky:



: son-of-blinky
['] blinky-loop
8 8 #user anonymous-task
activate ;




You can run this word a few times from the interpreter; each time, it'll create a new anonymous task, which will be triggered (along with the others) when you pause.

If you'd like to automate the process, here's a handy word:



: blinky-hordes ( count -- )
0 do
son-of-blinky
loop ;




Now you can enter



192 blinky-hordes




At each pause, all 192 tasks (plus any others you created by hand) will be invoked one by one. Now imagine them doing actual work. http://forums.parallax.com/images/smilies/smile.gif

I'm using this infrastructure in PropellerForth's next-generation serial console driver, and I expect the two to evolve in tandem.

Edit: there was a typo in blinky-hordes. I was tempted to leave it, to see if anyone actually got that far, but I decided to be polite. http://forums.parallax.com/images/smilies/smile.gif

Post Edited (Cliff L. Biffle) : 11/13/2006 6:52:51 AM GMT

Bill Henning
11-13-2006, 02:49 PM
Congratulations!

Very, very cool.

I do believe you have the first self-hosted propeller development system!

stardust
11-14-2006, 09:12 AM
Hello,

I visited the site and I could not download fourth. I would like to download it as it sounds like a nice development system. How do I download from the site?

Harrison.
11-14-2006, 09:57 AM
I downloaded the zip file with the propeller binary fine. Goto the main link that Cliff posted, and goto the download page. Choose to download the Binary Release zip.

I did try to download the source, but it wasn't on the Google Code SVN Repository for the project. Maybe Cliff hasn't gotten time to import his code into the repository.

Harrison

Cliff L. Biffle
11-14-2006, 10:04 AM
hpham's right on all counts -- the download is on the Downloads section of the site, and I'm a lazy bastard and haven't finished uploading the code yet. http://forums.parallax.com/images/smilies/smile.gif

(Mostly this is because I'm using a custom build system to generate the image, and I hope to have it cleaned up before I admit to having written it.)

potatohead
11-15-2006, 06:58 AM
Cliff, this looks to be pretty damn cool. Was holding off until you reached this state.

Have a quickie Forth for dummies pointer somewhere? When you get this golden, I want to try it out. Will be fun to actually be writing code on the prop itself.

Cliff L. Biffle
11-15-2006, 11:40 AM
For the past 25 years, Starting Forth has been the preferred tutorial. It's what I learned on.

There's a free web edition -- which, while it acknowledges some inaccuracies, describes a much more current dialect of Forth than the 1981 original. You can find it here:

www.amresearch.com/starting_forth/ (http://www.amresearch.com/starting_forth/)

PropellerForth is not yet complete, so some of what they describe won't work -- but we'll get there soon.

Cliff L. Biffle
11-15-2006, 12:02 PM
Hey, for anyone watching this thread, here's a PS/2 demo.

This will read characters from a keyboard (which must be attached at the demo board pins, 26 and 27) and display info. It's entirely in Forth, and part of it will form PropellerForth's PS/2 driver in the next release.

Load the file into PropellerForth (notes below) and run



ps/2-disp




When you run it, you'll see:
- the scancode
- the equivalent ASCII character and its hex value

The code understands press and release events, and marks them separately.

I've assigned ASCII values to all the nonprintable characters, following the conventions of the Parallax SPIN Keyboard driver (with one exception -- ESC exists in ASCII at 0x1B, but Parallax assigned it 0xCB). I've also given Break a unique code (0x10000), and the PS/2 demo handles it separately -- try it and see. http://forums.parallax.com/images/smilies/smile.gif

The file has DOS line endings, since Unix machines tolerate them and Windows machines require them. HyperTerminal users, use Transfer>Send Text File to send it to PropellerForth. (Users of other terminal emulators, you know what you're doing.)

Edit: Whoops, to use this, you'll need the latest PropellerForth build (to get waitpeq in its current form). It's on the site.

Post Edited (Cliff L. Biffle) : 11/15/2006 4:15:32 AM GMT

cgracey
11-15-2006, 02:43 PM
Cliff,

I haven't run your Forth system yet, but I just looked at your keyboard code and it looks really to-the-point. That is quite nice!

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


Chip Gracey
Parallax, Inc.

Cliff L. Biffle
11-16-2006, 12:21 AM
Thanks Chip! I'm not a great Forth programmer -- but this code does show how Forth can be evolved into a specific language for your application. Being able to have statements like "ps/2-rising-edge" really help with clarity.

jhmorris3486
11-17-2006, 06:49 PM
is there going to be a way to use the FORTH to program multiple Propeller chips?

Jason

Cliff L. Biffle
11-17-2006, 11:50 PM
jhmorris3486 said...
is there going to be a way to use the FORTH to program multiple Propeller chips?


Someone could certainly port the PropellerLoader code, I suppose, but it's not a case I'm personally targetting.

How do you mean?

jhmorris3486
11-18-2006, 08:51 PM
If you had an array of Propeller chips, could Propeller FORTH be used in the array?



Thanks

Jason

Cliff L. Biffle
11-19-2006, 08:04 AM
I don't see why not. It's a binary like any other Propeller software.

Dave Lowry
11-20-2006, 01:03 AM
Where can I find info on how to hook up the serial i/o?

Thanks.

-Dave

Cliff L. Biffle
11-20-2006, 03:38 PM
Dave Lowry said...
Where can I find info on how to hook up the serial i/o?


Depends:
- If you're referring to the serial console, the demo board wiring (available in the schematics) should be fine. Any terminal emulator that handles 19200, 8N1 will suffice.
- If you're referring to doing serial I/O on other pins for other purposes, there's no code in PropellerForth to do this yet. You'd need to write your own driver, or what for me to finish mine. (I'm actually working on it right at this moment.)

Dave Lowry
11-21-2006, 01:20 AM
Looking at:

http://www.parallax.com/dl/docs/prod/prop/PropDemoDschem.pdf

I don't see any obvious serial connections, unless I solder leads onto the prop or the FTDI chip.

Please clarify.

Thanks.

-Dave
·

Cliff L. Biffle
11-21-2006, 04:37 AM
Dave,

If you want an actual RS-232 serial port, you'll have to add your own level shifter to the demo board (or whatever board you're using); the demo board gives you a USB connection that acts like a serial port to the host.

If you're not working with the demo board (which I'm beginning to suspect you're not http://forums.parallax.com/images/smilies/smile.gif ), the serial console is on pins 31 and 30, and this isn't a Forth-specific question; I don't know the answer, so you'll probably get better results by posting a new top-level question.

Gerry Keely
11-22-2006, 12:00 AM
Cliff

Is it possible to get a copy of the binary file for a 6MHz crystal(I have a DLP- Prop unit) or will you be posting the source code soon ?



Regards

Gerry

Cliff L. Biffle
11-22-2006, 12:20 AM
Gerry,

I hope to have the source up in the next few days. (My day job's been interfering.)

However, propasm (the assembler I'm using) doesn't currently support 6MHz crystals. There's a directive I need to add for the next release.

Assuming you want to run at 96MHz, you should be able to change the first four bytes of the binary from

00 B4 C4 04

to

00 D8 B8 05

All PropellerForth time-related definitions work in terms of this clock freq, so that should take care of it for you.

Gerry Keely
11-22-2006, 12:25 AM
Thanks Cliff

I'll give that a try

Regards

Gerry

Cliff L. Biffle
11-22-2006, 12:33 AM
Gerry,

I've opened up a bug against propasm for tracking your issue. If you're curious, you can watch it here:
code.google.com/p/propasm/issues/detail?id=6 (http://code.google.com/p/propasm/issues/detail?id=6)

I hope to have this licked in the next couple days.

Thanks for the input!

Dave Lowry
11-22-2006, 02:18 AM
Cliff, thank you for your patience.

I am using the demo board, and I do understand the concept of the level shifter, etc.

Still, I must be misssing something. Either I solder wires to the TQFP Prop chip and wire up the level shifter, etc.

Or, can Hyperterminal or whatever use a USB port as a regular serial port?

Or, more explicitly, how do you conect your demo board your PC?

Thanks.

-Dave

CJ
11-22-2006, 03:58 AM
the circuit on the demo board is a usb to serial adapter, just use the same cable you use to program it

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Who says you have to have knowledge to use it?

I've killed a fly with my bare mind.

Kevin Wood
11-22-2006, 05:44 AM
>>> Either I solder wires to the TQFP Prop chip

Probably not a good idea!

Gerry Keely
11-22-2006, 07:47 AM
Cliff



I tried your suggestion by changing the first 4 bytes but ran into checksum problems.

Fortunately the terminal program I have can handle custom baud rates, so I just multiplied your rate by 1.2 and it worked fine.

Next part is to learn forth it looks interesting.

Thanks again

Regards

Gerry

Cliff L. Biffle
11-22-2006, 08:43 AM
Dave Lowry said...
Or, more explicitly, how do you conect your demo board your PC?


With the USB cable. There's a USB-serial converter on the Demo Board, so if you plug the USB cable into the Demo Board and your computer, you'll grow a new "serial port."

It's COM3 on my XP install, but your number will vary. I think it announces it in the little I'm-an-excitable-Jack-Russel-terrier popups in the corner.

At that point, you can use HyperTerminal (or better yet, someone please tell me about a good, free terminal emulator for Windows -- HyperTerminal is horrible).

Cliff L. Biffle
11-22-2006, 08:44 AM
Gerry Keely said...
I tried your suggestion by changing the first 4 bytes but ran into checksum problems.

Fortunately the terminal program I have can handle custom baud rates, so I just multiplied your rate by 1.2 and it worked fine.


Oh, hey, yeah, forgot to mention -- the current serial console driver is a total hack, with hardcoded bit timings. Good catch.

I'm hacking on the new driver now, which is in Forth and does not suffer from such limitations. (Though it may do funny things if you change the clock frequency while a character is being sent, rather than between characters.)

jamma
11-22-2006, 09:08 AM
Cliff L. Biffle said...
or better yet, someone please tell me about a good, free terminal emulator for Windows -- HyperTerminal is horrible).

Most of the AVR folks use Bray's terminal (officially Br@y++ Terminal). I think it's official home is here:
http://bray.velenje.cx/index.php?page=elec, although I've always downloaded it from Smiley Micros:

http://www.smileymicros.com/download/term20040714.zip?&MMN_position=42:42

Bray's apparently inspired CuteCom, which is cross platform and thus might appeal to you more. I've never used it:

http://cutecom.sourceforge.net/

·

Peter Jakacki
11-22-2006, 09:24 AM
While *any* terminal is better than HorrorTerminal I have tried dozens including Bray's but I personally choose to use TeraTerm. It is a full-blown ANSI terminal that includes features such as debug mode etc. It runs at full-throughput and does not have all the gammy delays that HorrorTerminal has when sending text files (I'm used to sending Forth source at max speed without delays). It's free and binary&source are available at hp.vector.co.jp/authors/VA002416/teraterm.html (http://hp.vector.co.jp/authors/VA002416/teraterm.html)

*Peter*

Chris Double
11-22-2006, 09:45 AM
For those asking for quick intros to Forth, Thinking Forth is also a good free resource:

thinking-forth.sourceforge.net/ (http://thinking-forth.sourceforge.net/)

Chris.
--
http://www.bluishcoder.co.nz

Cliff L. Biffle
11-22-2006, 10:14 AM
jamma said...
Bray's apparently inspired CuteCom, which is cross platform and thus might appeal to you more.


I already have a favorite terminal emulator on Mac/Linux, but it's a pain to chown my serial port back and forth between my actual OS and the VM -- so I do most of my console work within Windows. Thanks for the links!


Chris Double said...
For those asking for quick intros to Forth, Thinking Forth is also a good free resource


Thinking Forth is pretty hardcore. I'd start with Starting Forth, which I think I've linked before, but I'll link again:
www.amresearch.com/starting_forth/ (http://www.amresearch.com/starting_forth/)

SSteve
11-23-2006, 12:37 PM
I'm having trouble figuring out how to address the Propeller Demo Board under OS X. I've used Kermit to communicate with a serial Board of Education. When I plug in the Parallax USB-Serial adaptor a new device shows up in /dev and I can select it. But when I plug in the Demo Board there is no new device. Am I missing a driver?

I'm looking forward to playing with Forth on the Propeller. Back in the 80s I used Forth to write a commercial MIDI voice librarian under DOS.


Cliff L. Biffle said...
I already have a favorite terminal emulator on Mac/Linux


Which one is that?

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows

links:
My band's website (http://www.theuniversalsteve.com)
Our album on the iTunes Music Store (http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewAlbum?i=84780626&id=84781354)

Cliff L. Biffle
11-23-2006, 04:36 PM
SSteve said...
I'm having trouble figuring out how to address the Propeller Demo Board under OS X. I've used Kermit to communicate with a serial Board of Education. When I plug in the Parallax USB-Serial adaptor a new device shows up in /dev and I can select it. But when I plug in the Demo Board there is no new device. Am I missing a driver?


This is not even remotely the right thread for such a question! http://forums.parallax.com/images/smilies/smile.gif But I'll give it a shot:

Double-check that you've got the latest FTDI USB-Serial driver. The Parallax USB-Serial Adapter should use the same driver, but it's worth checking. (There's a link to it off Parallax's product page.)

The driver itself is finicky; you might try rebooting (yeah, I know, it sucks) and then plugging in the Prop board first and seeing if it gets a node in /dev. (Oh, and make sure you have the power on. I keep forgetting that myself.)

Finally, it would definitely be worth checking to see if the Demo Board appears on any other machines, Macs or otherwise. There's always the possibility that your cable, board, or power supply is wonky.


As for terminal emulators, I'm a console kinda guy; I like minicom a lot. http://forums.parallax.com/images/smilies/smile.gif I'm sure there's a very nice Mac-native one out there, but in my day job I tend to be on Linux, and it's nice to retain the muscle memory on both systems.

SSteve
11-24-2006, 03:03 AM
Cliff L. Biffle said...
This is not even remotely the right thread for such a question! http://forums.parallax.com/images/smilies/smile.gif

Yeah, after re-reading my post it does look unrelated to the thread, doesn't it? But what I'm trying to do is use a terminal emulator with the Prop Demo Board in order to use PropellerForth, so it's at least tangentially related. http://forums.parallax.com/images/smilies/smile.gif

I'll try your suggestions and see if I can get something to show up in /dev. Thanks!

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
OS-X: because making Unix user-friendly was easier than debugging Windows

links:
My band's website (http://www.theuniversalsteve.com)
Our album on the iTunes Music Store (http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewAlbum?i=84780626&id=84781354)

JonnyBritish
11-20-2009, 12:00 AM
Is this project still ongoing? ie forth on propellor?

As a british guy who remembers a home computer running forth - the jupiter ace the idea of running a full forth system on a propellor sounds cool but is this still in development?

Mike Huselton
11-20-2009, 03:42 AM
Give 'em an inch and they'll take a mile http://forums.parallax.com/images/smilies/smilewinkgrin.gif

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
JMH

Mike Green
11-20-2009, 04:06 AM
I'm not aware of further work done by Cliff on his Forth. The most recent Forth work that I've seen is JDForth which is a Forth compiler that compiles into Spin.

www.jacobsdesign.com.au/software/jdforth/jdforth.php (http://www.jacobsdesign.com.au/software/jdforth/jdforth.php)

Ron Sutcliffe
11-20-2009, 07:01 AM
There is Prop Forth , by Sal sanci. This is an interactive Forth Project. Multi-threaded and with a large Dictionary. Originally is was called SpinForth. Search Google for Spin Forth and you will be re-directed to the PropForth site. Developement continues. Prop Forth is not an ANSI forth but it is well documented

Prop forth comes with VT100 and EEprom support and Web supoort

JBForth, allows you·to run ·spin alongside Forth.·Passing data between spin and JBforth is a snack.·The professional version is a complete package·and is fast. The downside is that it is not Intereactive.

CB Forth is close to a tiny ANSI forth but the I/O is very flakey.·See the Cliff Hacks·web site for the latest version.

Not sure if Peter Jackie has done any thing·for the Prop, he's the only other forther that I know of.
·
There is little interest in Forth, which is unfortunate. . I have been working on my own tiny ANSI Forth Project based around the HX512 Xmem card and it is coming along, albeit rather slowly.



Ron

Post Edited (Ron Sutcliffe) : 11/24/2009 11:46:13 AM GMT

JonnyBritish
11-20-2009, 10:31 AM
Check this out, the only home computer to use Forth as its built in language - http://en.wikipedia.org/wiki/Jupiter_Ace

Ever since reading about the propellor I have been trying to work out a reason to buy one as I am not an electronics guy and this forth project looks like its reason enough! Maybe I will progress and open up a forest mims book and play with 555's etc.

Either way cool stuff to have a complete system on the Propellor

Fred Hawkins
11-20-2009, 11:03 AM
Biffle does have a google code wiki: http://code.google.com/p/propellerforth/w/list

I think this is his latest public work on propellerforth.

Post Edited (Fred Hawkins) : 11/20/2009 3:22:02 AM GMT

Fred Hawkins
11-20-2009, 11:17 AM
spinforth forum thread: http://forums.parallax.com/showthread.php?p=694135

his code.google downloads (last entry Jan 2008): http://code.google.com/p/spinforth/downloads/list

Of all of the propeller implementations of forth, I like this one best. Salsanci's source is well commented and useful.

Ron Sutcliffe
11-20-2009, 06:25 PM
@fred

PropForth is Salsanci's latest version of SpinForth. Its is now case sensative.
TCP/IP stack for Propforth was the latest work in progress. ( a couple of months ago)

http://code.google.com/p/propforth/wiki/GettingStarted

PropForth V2.5· 9/10/2009 is the latest version

Ron

Post Edited (Ron Sutcliffe) : 11/20/2009 10:32:41 AM GMT

Fred Hawkins
11-22-2009, 12:46 PM
Thanks. I hadn't seen that.

pharseid
11-23-2009, 03:18 AM
Are any of you guys following the thread about Leon's Prop/XMOS hybrid? I'm wondering if there is any interest in implementing something like Jeff Fox' F* on that. A parallel processing language based on Forth and distributed shared memory. In his case he just added one word to the Forth wordset, although what I'm thinking of would ugly that up quite a bit. I don't have any application for it myself, but it seems like such a perfect fit. Also there are other multiProp implementations that might benefit from this.

-phar

Ron Sutcliffe
11-23-2009, 08:42 PM
Have you had a really had a good look at PropForth by Salsanci ?

There is extensive documentation.

If you don't like it you can always modify and recompile it. You would be stuck with then same core words if you are going to rebuild it using spinmaker and were to recompile it on the Prop.

PropForth provides for inline asm (PASM), an EEprom file system and it is multi threading using a time slicer. The P and R stacks reside in each active forth cog, this could limit the number of actve threads in a single cogbut there are seven cogs available to forth, one is used for I/O. I have considered moving the dictionary out of hub to my HX512 ram card, but considered it would be too slow.

I don't see Leon's pet chip being any more suited to Forth than the Prop. Chuck Moore's S40 chip is based on 18 bit core (3 cores or one cog). J fox and many other have Forth on a Chip. Dare I say that I had considered getting an X just to see how compact the compiled code was with XC against ICCP.

Cheers

Leon
11-23-2009, 10:55 PM
XMOS isn't my pet chip, I use whatever gets the job in hand done as cheaply and easily as possible.

I don't see why the XMOS chips are unsuited to Forth, it would run just as well as any other 32-bit Forth implementation on conventional processors. Exploiting the parallelism will require some work.

I've got some S40 chips (over £60 GBP each) but haven't done anything with them, partly because of the bust-up between Chuck Moore and Intellasys. How about a Propeller-S40 hybrid? http://forums.parallax.com/images/smilies/smile.gif

Leon

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM

Post Edited (Leon) : 11/23/2009 3:52:16 PM GMT

pharseid
11-24-2009, 02:37 AM
My thought was initially, you wouldn't be running Forth on the XMOS (I don't know if there are any implementations), but that it would be handling shared memory functions (address translation and locks on critical data). When tasks got moved to the XMOS chip, I'm thinking that they would probably get coded in XC. If someone wrote a Forth implementation for the XMOS chip, it would really be helpful if it was source compatible with that on the Prop. But that's a lot more work than I'm considering now.

And I agree with Leon about the suitability of the XMOS chip to run Forth. I worked a little on register optimization in Forth 20 years ago (the last time I did any serious programming in Forth) and it's possible to get pretty much any cpu to run Forth efficiently.

-phar

Leon
11-24-2009, 02:42 AM
I remember someone porting Forth to one of my transputer modules around 1985. It wasn't very efficient when I tried it; I don't think it was implemented properly.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM

pharseid
11-24-2009, 04:25 AM
Around that time I would think most Forth implementations were indirect threaded interpreters, which aren't very efficient. But native code compilers were popping up and I got involved in optimizing register allocation. I like to think of myself as the co-inventor of the virtual stack technique, but the other co-inventor was quite a bit ahead of me (when I read his paper I stopped my own work on this). I drifted away from the Forth world and assumed that the VST would become the standard method of optimizing Forth, but years later I dropped into the Forth Newsgroup and found that while optimization was a hot topic, the technique had been all but forgotten (one commercial vendor said they used something "very much like it").

My memory of the transputer was that it had a 4 element hardware stack you HAD to use (all alu ops used it) and didn't have good stack manipulation ops, so it wouldn't have been my dream target cpu. Once you filled the stack, you had to shuffle stuff around to push anything else on it and it was pretty inefficient. The best solution which occured to me was to do a scan of each basic block to determine how deep the stack would get at maximum and adjust code generation so you would just fill the hardware stack at that depth, but I never tried to code it, I was just looking at different cpu's to see how generally applicable the technique would be.

-phar

Leon
11-24-2009, 04:53 AM
Simulating a conventional stack in RAM (two of them are needed, of course) would be one way round the problem.

Leon

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM

pharseid
11-24-2009, 06:13 AM
Well yes, I haven't really fleshed this out. You would have a software parameter stack (and of course return stack too), but for most efficient execution, you want to use the hardware stack. If you just use the hardware stack naively, at some point you're threatened with overflow, and because on the transputer you don't have direct access to the lowest item on the hardware stack, you have to unload everything on the stack to get to it. If you look at a basic block and determine the maximum stack depth, you can use a mix of software stack and hardware stack operations to optimize performance.

Of course, I'm going into this detail because it's something I personally worked on. My guess is that if your implementor had used a naive native code compiler instead of an indirect interpreter, you would have seen a big increase in performance. Maybe an order of magnitude. But if he then employed the virtual stack technique, there's still a lot of improvement to be had.

-phar

Ron Sutcliffe
11-24-2009, 07:30 AM
I did not suggest than Xmos was less suitable than Prop. Quite frankly I don't know. I do know that Forth is ideally suited to microcontollers generally and can be implemeted on most in some form or another.

For me Forth is the ultimate low level language, but its comes down to what we get comfortable with.

Ron

Leon
11-24-2009, 07:55 AM
I have come across someone who ported Lisp to every new chip he used, and used that for development.

Leon

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM

pharseid
11-24-2009, 08:01 AM
The thing about distributed shared memory is that you just add a couple words (Jeff Fox just added one word) and you have extended memory and synchronization of multiple chips and extended I/O all at once. This seems in harmony with the philosophy of Forth. You have this new address space and bulk memory and I/O locations and mailboxes to other chips appear in this space. For my part, I'm just curious to see what it would all look like, never having seen an actual implementation. It seems like a good idea and Leon's board seems like good hardware to try it on. If I didn't already have 2 projects in the hopper, I might already be working on it. But then, I don't actually have an application for it, mundane MCU's are sufficient for my needs.

-phar

pharseid
11-24-2009, 08:08 AM
Leon, your post about Lisp is interesting. There is a public domain Smalltalk, Squeak, supported by Disney, that implements a windows GUI and debuggers and stuff, you just have to compile a virtual machine in C. But it's so darn big, it will probably be a while before it gets any interest from microcontroller people. I've never used Smalltalk seriously, but it is pretty fun as languages go.

Leon
11-24-2009, 03:32 PM
The nice thing about Lisp is that it basically consists of a very small number of primitive operations, and the whole language can be based on those, although it won't be very efficient. Also, programming in Lisp is programming in machine language - that of a Lisp machine.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Amateur radio callsign: G1HSM