R a i n b o w Forth
becomes a WebApp
Brad Nelson
November 15, 2008
|
Overview
* colorForth
* RainbowForth
* WebApps
* Javascript
* AppEngine
* Security/Sharing
* Process Model
* Demo
* Future Directions
|
colorForth
* Use color to simplify the Forth interpreter
* Back to basics (not ANS-Forth)
: square ( n--n ) dup * ; [ 4 square ]
becomes
square n--n dup * ; 4 square
|
Meaning of the colors
red - define a word
yellow - execute a word
green - compile a word into the definition of the current word
cyan - compile a word, even if it is a macro
blue - get the address of a word (not present in colorForth)
magenta - create a variable
white - comments
|
Meaning of the colors
word : word
word [ word ]
word word
word ' word compile,
word ' word
word variable word
word ( word )
|
RainbowForth 0.1
* My first Forth implementation
* x86 machine code
* Bootstrapped from C
* Cheated on the editor
* Platform specific syscalls
* Windows / Linux
* 23 blocks for core system
* 8 blocks to put up colored boxes
* Subroutine threaded
|
RainbowForth 0.2
* Make it work on a webpage
* Javascript / AJAX
* Store state on the server
* Allow online collaboration
* Web Application
* AppEngine
* Do the editor in Forth (~10 blocks)
* ~300 lines of Python
* ~900 lines of Javascript
* Subroutine threaded
|
Web Applications
* Browser as thin client
* Use from anywhere
* Keep your data in the cloud
* No need to install
* No need to upgrade
* Inherently cross platform
* Tied to the network :-(
|
Javascript
* Interpreted
* Weakly typed
* Avaiable on most browser
* Lisp like closures
* Driven by browser events
|
Forth in Javascript
* Arrays for dstack, rstack, heap
* Dictionary for the dictionary
* Closures for built-in words
* Poor man threads
* Text console in the DOM
* HTTP POST to read/write blocks
|
Google AppEngine
* Host WebApps on Google servers
* Designed to scale
* Python (Django-like)
* Free hosting up to relatively high limits
|
Security/Sharing
* Single number space
* Each block owned by one user
* Cache blocks on read/write
* Blocks readable by all
* Core blocks setup by me
|
Process Model
* Per thread data:
- data stack
- return stack
- instruction pointer
- console location
* Global data:
- heap
- dictionary
|
Threading Model
* Execute thread until it yields
* Yield to system when all threads block
* Yield to system if too much time passes
* Run threads if key events come in
* Run threads on periodic timer tick
|
DEMO
DEMO DEMO DEMO
DEMO DEMO DEMO
DEMO DEMO DEMO
DEMO DEMO DEMO
DEMO DEMO DEMO
DEMO DEMO DEMO
DEMO DEMO DEMO
|
Future Directions
* Cross compile native code?
* Move to SCM like sharing model?
* Use Gears to run offline?
* Actually use it for something?
|