mitra42 / webForth

Forth for the web - implemented in JS and other web technologies
https://www.mitra.biz/forth/console.html
GNU Affero General Public License v3.0
27 stars 1 forks source link

Node API #23

Closed mitra42 closed 3 years ago

mitra42 commented 4 years ago
mitra42 commented 4 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
mitra42 commented 4 years ago

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
mitra42 commented 4 years ago
mitra42 commented 3 years ago

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'));
mitra42 commented 3 years ago

This is done - check the README