js-forth

0.2.0 • Public • Published

jsForth

An implementation of Forth in Javascript

Try it out here

ANS Forth

jsForth implements the full core ANS standard

The following word sets are implemented:

  • Core words - fully implemented
    • All tests pass except some integer multiplication/division edge cases where the ANS spec differs from the results given by the long package
  • Core plus words - fully implemented and all tests pass
  • Core extension words - fully implemented and all tests pass

The ANS Forth tests can be run using npm run test or in the intepreter with the following forth code

include test/verbose-tester.fth
include https://raw.githubusercontent.com/gerryjackson/forth2012-test-suite/master/src/core.fr

The complete test suite is available here

js interop

  • global variable access js /document
  • array access js .0.2
  • property access js .name
  • property setting js .name!
  • function calling js .sin{1}
  • method calling js /document.getElementById{1}
  • new with params js .new{1}

Threading model - trampolined threading

All of the standard threading models require call or jump to execute the next instruction. In js these both translate into functions calls in tail position. Without tail call optimisation this will lead to a stack overflow. Therefore jsForth uses a trampoline to execute instructions.

ECMAScript 6 specifies tail call optimisation but unfortunately most browsers don't support it yet

Dependencies (2)

Dev Dependencies (4)

Package Sidebar

Install

npm i js-forth

Weekly Downloads

1

Version

0.2.0

License

MIT

Last publish

Collaborators

  • brendanator