Closed mitra42 closed 3 years ago
Possible node design .... In parent package:
require 'webforth'; // defines a "forth" global
require 'foo' // where foo is defined in package.json to be a .js file
forth.load('https://bar.com/foo.f') // Load a forth file. Relative to current URL (e.g. could be a file or HTTP etc)
In forth package something like
forth = { m, c, x, load }
export forth
Alternative API
const Forth = require('webforth'); // The class or obj with functions
Forth.load('foo.f'); // Load it into the class
const forth = new Forth({ CELLL: 3, xxxMemSize: 1000000}) // Parameterized instance
forth.load('https://....'); // Load it into the instance
forth.interpret("1 2 DUP .S");
boo = forth.rot([1,2,3]); // Returns [2,3,1] - will depend what can do with JS API
forth.console(); // Go interactive
this
may need this.call or something like that
Actual API - for now - in sandbox/test_node_api.mjs
import Forth from '../index.js';
// Normally this would be: import Forth from 'webforth';
const CELLL=3
const MEM=8
const EM=0x2000 * CELLL; // default is 0x2000 * CELLL
const foo = new Forth({CELLL, EM, memClass: `${MEM}_${CELLL*8}`});
foo.compileForthInForth()
.then(() => console.log('===forthInForth compiled'))
//.then(() => foo.cleanupBootstrap()).then(() => console.log('===forthInForth cleaned up'))
//.then(() => foo.interpret("WARM"));
.then(() => foo.console()) // Interactive console
.then(() => console.log('console exited'));
This is done - check the README