Skip to content

chochain/eForth.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

eForth.js - Forth in Javascript

eForth implemented in 100% Javascript. An interfactive Forth shell can be run from within a single web page on your desktop or even cellphone.

There is a good collection of prior art (at the bottom of this page). Here is my version of a new wheel, eforth.js, the only file you need! Well, maybe an extra index.html to wrap it up is nicer. So, simply copy both of them from the root directory shown above to your local directory. Click on index.html and you have a live Forth engine ready to play with. Without surprise, you should get something like the left hand side snip below. Try the live demo here which runs 100% in your brower once fetched.

The good old green screen days are long gone. Add some HTML stuffs and your work looks instantly better!Just point your <script> tag to eforth.js and you can create whatever presentation you fancy... Check src/eforth8.html, my work in progress but is quite usable as a template.

.....

Installation - Simple as 1-2-3.

  1. From root directory shown above, download or cut-n-paste eforth.js and index.html to any of your local directory,
  2. Find the index.html we've just saved in your FileExplorer (Windows), iFile (Mac OS), or Files (Linux),
  3. Open it with your favorite browser. It should bring on the eForth page like the left-hand snip shown above.

It's that easy. Have fun!

Fancier UI - with CodeMirror, tooltips, ...

As shown in the right-hand side picture above

  1. Clone this repository to your local directory,
  2. In your FileExplore, find src/eforth8.html below the root directory,
  3. Click it, and there you have it. A nicer UI, and optionally, you can open browser's Web Developer Tools on the side to monitor console output. The editor shows up once you click the 'pencil icon' in the function bar atop. You can try this live demo src/eforth8.html
icon description
home clear text
file+ create new file in your local directory
file open a file
file<- save your updated file to your local directory
boot forget all words defined and clear text
down arrow execute selected/high-lighted section of Forth code
run execute entire file shown

Note if you kick-off the eforth8.html page from a webserver (as described below), the embedded Forth in the page also can be executed.

Javascript Modules

Should you plan to incorporate eforth.js in a larger project, or maybe you care for modulization in fashion of the ES6's new feature i.e. ease of source code maintenance

  • check the /modules directory for individual functional areas.
  • eforth_w_module.html in the root is provided as an example to import modules
  • note that, without a bundler (i.g. Webpack, Browsify, ...) to tie modules together, one will need a web server to push all the modules to your web-browser
  • Python3 has a simple built-in http server that you can use. i.e.

From root directory starting your web server

python3 -m http.server

On you browser, enter

http://localhost:8000/eforth_w_module.html

Performance

Javascript brings us the simplicity. Just point the web page to your eforth.js and that's it. Open the DevTool in your browser, you can trace, benchmark, even single-step the code. But what about the performance compared to native C? Well, it's slow! Running at about 1/15 of the speed. For an interfactive Forth shell on the browser to play with or learn, I think it works OK. But if you want to see a WASM eForth that runs at about 1/2 of native CPU, check my weForth here

Documentation

History - The lineage

  • It started back in 2011 when Cheahshen Yap from Taiwan FIG sent the 100-line kernel, named jeForth, to Dr. Chen-Hanson Ting, the master of eForth family.
  • Sam Suan Chen, took over the codebase (called project-k) and produced a graphic demo in SVFIG. The project took on its own path here now.
  • Brad Nelson, introduced a web front-end to Dr. Ting sourcing from his ESP32Forth project.
  • It sat on the shelf for years until Dr. Ting restarted his interest in Jan. 2021, completed jeforth614, and presented in SVFIG in May *(see ref. below)
  • In Aug. 2021, after working with Dr. Ting on his objectization of ooeForth (aka EForth.java) for a month, without knowing jeforth614's existance, I took interest in the 10 year old jeforth_301 and wiped it up to jeforth400. Presented to Dr. Ting on 2021/8/8 (Taiwanese Father's Day) just for a kick and a potential project path forward.
  • Dr. Ting did not like the flashy front-end at all. He striped the sidebar, dropped dependency to CodeMirror, and renamed it jeforth615.js. He, however, did include it in the published document ceforth_403.doc* and was kind enough to put me along side with him as the authors. *(see ref. below)
  • After he merged html and js into one file jeforth616.html, Dr. Ting and I switched focus onto upgrading ceForth (C-based Forth) for Windows and ESP32 here, and finally targeting an FPGA with Don and Demitri of AI & Robotics project. He worked tirelessly even from his sickbed and did not ever stop. Not until he finally succumb to the illness 2022/5/30.
  • After a few months of head-down cranking on tensorForth, I felt that it's time to take a look at all the projects I've worked with Dr. Ting before my memory starting to fade. In Thanksgiving Day, after reviewing jeforth615, I've decided to call it eForth.js in memory of Dr. Ting.

Though I've never had the chance to meet him in person, the years of dedication and contribution he has to the Forth community is something I'll carry with me. As I told him once in the e-mail: "The name eForth will forever be associated with you, Dr. Ting".

Dr. Ting's Original jeForth live demo

Prior Art (on GitHub)

Many others have the same idea as well, each with a little different implemenation. Proof of the saying in the Forth community, instead of seen one seen them all, here you see many of the ones!

Other Refs From Lars Brinkhoff's 2017 list

About

eForth in Javascript - one file does it all

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published