A PIC Forth Compiler/IDE

In light of all the PIC18F Assembler I’ve been writing (for RainDance and other stuff), I’ve been thinking about a simple FORTH compiler to make things a little bit easier.

Here’s what I’m envisioning: A PC environment, basically a forth shell, that allows the definition of new words (using the ‘:’ word), but instead of adding it to the current dictionary, it compiles the new word to PIC code, outputs the ASM and machine code (like you would see in a .LST file) and adds it to an “output” dictionary. An extra command, “compile”, puts all the words in the dictionary together, fills in addresses etc., and outputs a PIC object file that can be linked against other files using standard tools to make a complete PIC binary.

Of course, the current output dictionary could be stored also, for later editing/resumption of work.

The whole thing could be implemented on top of a standard FORTH (gforth or similar) by redefining words so that when you type

: add5 5 add ;

it actually checks if ‘add’ is a word defined in the “output” dictionary, checks if it’s a macro or a callable function (things like add would be implemented directly as one or two assembly instructions, so it would be easier to treat it as a macro), expands/calls the macro/function, and puts the resulting headers/code into the output dictionary.

I’m sure there’s a ton of stuff I haven’t thought about here, but it could work, and it could be neat. It’s questionable whether this is a better approach than just using, say, C, but I think FORTH is a very nice language to make some of the ugliness of assembly go away without sacrificing much in the way of transparency.

Comments are closed.