Tali Forth 2 for the 6502
github.com
github.com
If you have stack code that looks like this: "foo bar qux baz" and want to convert it to assembly, all you have to do is insert JSR instructions between the words:
JSR foo JSR bar JSR qux JSR baz
To define subroutines, insert a label and an RTS function around code blocks. For example, to define a subroutine called qux using the code ": qux foo bar", the output would be:
qux: JSR foo JSR bar RTS
The last thing needed is the ability to push literals onto the stack. In my language I defined literals as things between parenthesis. I compiled them by outputting a PUSH_LITERAL assembly macro. Code like "foo (5) (6) bar" would be compiled as:
JSR foo PUSH_LITERAL 5 PUSH_LITERAL 6 JSR bar
That's it! You could implement an entire compiler in 50 lines of code. (of course, writing a proper FORTH requires more than this toy example)
I love writing assembly code in RPN with Forth macros!
You can write FORTH code with loops and conditionals and any kind of logic and parameters, that dynamically assembles machine code! Much better than your typical macro assembler.
Here's some 6502 assembler for an Apple ][ SUPDUP terminal emulator that does ram card bank switching:
http://www.donhopkins.com/home/archive/forth/supdup.f
Here's some Forth 68k assembler that draws lines on a weird Sun-2 CGONE graphics board.
http://www.donhopkins.com/home/archive/forth/cg/bline.f
Mitch Bradley's 68k forth lets you use interactive conditionals and loops in the top level outer interpreter!
I think he wrote a paper about that feature, which I might be able to dig up ... Here's something related he wrote about refactoring the outer interpreter, but not what I'm thinking of:
https://groups.google.com/forum/#!topic/comp.lang.forth/lKQj...
https://github.com/scotws/TaliForth2/blob/master/docs/manual...
> Currently, there is no assembler included. The plan is to include a simple assembler based on Simpler Assembler Notation (SAN).
It does include a disassembler: https://github.com/scotws/TaliForth2/blob/master/docs/ch_dis...
The author has written a 6502 assembler in gforth: https://github.com/scotws/tasm65c02
Here is a document describing the notation: https://docs.google.com/document/d/16Sv3Y-3rHPXyxT1J3zLBVq4r...
Yes I wrote a paper but I probably can't find it. The easiest place to look would be in the Open Firmware source.
https://github.com/MitchBradley/openfirmware/blob/master/for...
The magic is all in +level and -level. Search for those in kernel.fth to see other places they are used to achieve a similar effect, e.g. in abort"
For an alternative but effectively equivalent formulation, see:
https://github.com/MitchBradley/cforth/blob/master/src/cfort...
and
https://github.com/MitchBradley/cforth/blob/master/src/cfort...
Then you could write opaque, transparent or invisible code and comments!
Blinking text and scrolling marquees would at least bring it into the late 1990's.
https://blogs.msdn.microsoft.com/ashleyf/2013/11/02/the-beau...
In ColorForth, color is part of the syntax - it matters whether or not some text is white or green or yellow, in the same way that "//" matters in C or indentation matters in Python. What would the use of millions of indistinguishably-fine syntax cases be? What are benevolent uses of transparent source code?
OTOH, ColorForth is really cool, and admirable for its minimalism and effectiveness. A featureful port to a modern platform would be really fun to play with.
The blink attribute could be a control structure! Blinking text would only execute when you could see it, so you could write a blinking word "BEEP," and you'd hear it beeping on and off as it blinked!
Or you could change a "DO" loop into a "DON'T" loop by making it transparent.
And you could extend IF ELSE THEN to support a partially transparent MAYBE clause, whose probability of executing was proportional to its alpha channel.
When looking at the FORTH code in Github that Mitch linked to, I realized that Github supports colored syntax highlighting for FORTH! (Or at least it tries.)
https://github.com/MitchBradley/cforth/blob/master/src/cfort...
But it colored the "Primitive control flow words" like if/do/while/etc red by mistake, because it didn't realize that particular code was actually defining those words instead of just using them.
It's pretty hard to write a code syntax colorizer for a language that does't actually have any syntax.