Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Entry point for Forth into Firefox Spidermonkey

236 views
Skip to first unread message

Liang Ng

unread,
Nov 4, 2018, 1:46:09 AM11/4/18
to
Entry point for Forth into Firefox Spidermonkey

I hope this could be where the historical mistakes in computing made by the "Unix paradigm" can be corrected, by putting a Forth interpreter into Firefox Spidermonkey (JavaScript engine).

The required function JS_DefineFunctions, to interface C++ function to SpiderMonkey (Firefox JavaScript engine), is poorly documented, to say the least.

On MDN (Mozilla Developers Network), the tutorials are quickly outdated as new versions of Firefox are released.

I will share what I know if you have specific queries.

AddIntlExtras() (Add Internal Extras, I think) seems to be the right place to add Forth to Spidemonkey.

I hope this will save you a few weeks of looking around.

Next to try: add Forth code to funcs array.

https://github.com/mozilla/gecko-dev/blob/master/js/src/shell/js.cpp

#ifdef ENABLE_INTL_API
static bool
AddIntlExtras(JSContext* cx, unsigned argc, Value* vp)
{

CallArgs args = CallArgsFromVp(argc, vp);

if (!args.get(0).isObject()) { JS_ReportErrorASCII(cx, "addIntlExtras must be passed an object"); return false; }

JS::RootedObject intl(cx, &args[0].toObject() );

static const JSFunctionSpec funcs[] = {
JS_SELF_HOSTED_FN("getCalendarInfo", "Intl_getCalendarInfo", 1, 0),
JS_SELF_HOSTED_FN("getLocaleInfo", "Intl_getLocaleInfo", 1, 0),
JS_SELF_HOSTED_FN("getDisplayNames", "Intl_getDisplayNames", 2, 0),
JS_FS_END };

if (!JS_DefineFunctions(cx, intl, funcs)) { return false; }

....

Liang Ng

unread,
Nov 4, 2018, 4:36:08 AM11/4/18
to
On Sunday, 4 November 2018 13:46:09 UTC+8, Liang Ng wrote:
> Entry point for Forth into Firefox Spidermonkey
>
> I hope this could be where the historical mistakes in computing made by the "Unix paradigm" can be corrected, by putting a Forth interpreter into Firefox Spidermonkey (JavaScript engine).

Here's the js.cpp file I modified in order to add a Forth interpreter.

https://github.com/udexon/fire4x/blob/master/js.cpp

The original file is:

https://github.com/mozilla/gecko-dev/blob/master/js/src/shell/js.cpp

Please read this to build dist/bin/js (jsshell):

https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Build_Documentation

The documentation could be a little confusing for first timer. You are welcome to ask me questions.

Please look for "f_load" and "f_Load" in my js.app for the changes I made as preliminary tests for adding Forth interpreter.

As you can see from line 1668, I intend to load Forth interpreter as .so DLL. I will start with Jonesforth, as it seems to be the easiest to me.

I would also make Forth .so dll for other Forth interpreters, provided you supply me with sufficient instructions. Alternatively, I will also share with you what I know for you to do the same.

Please visit Project Fire4X Facebook group for more information:

https://www.facebook.com/groups/483887212122959/

You may contact me directly via gmail if you refuse to use Facebook.

One of the long term project of Fire4X is EUCLIDE (Extensible Unified Command Line Integrated Development Environment) -- a distributed environment to recreate systems like Facebook based on Forth and other stack machine based components.

I share your disagreement with MAFGA (Microsoft Amazon Facebook Google Apple) and EUCLIDE is the antithesis of MAFGA.

So far I have been contacted by the author of CIFORTH / LINA. I hope I will also get the support from other Forth authors.

Thank you very much.

Liang Ng

unread,
Nov 4, 2018, 11:03:14 PM11/4/18
to
On Sunday, 4 November 2018 17:36:08 UTC+8, Liang Ng wrote:
> On Sunday, 4 November 2018 13:46:09 UTC+8, Liang Ng wrote:

> > Entry point for Forth into Firefox Spidermonkey
> https://github.com/udexon/fire4x/blob/master/js.cpp

1) I have added example code from which returns a random number to jsshell by running "f_load()". (Line 1716)

2) I have tested dlopen() and dlsym(). There was no conflict with Firefox code. (Line 1684)

3) I am having problem making .so files from jonesforth and pforth.

It may take a few hours or a few days to sort this out.

Help is needed on this one.

Authors of other Forthes, your help is very much appreciated.

We can basically create custom hooks to different Forthes, or even any C++ programs (e.g. cryptocurrency browser mining) using this method.

Thank you very much.

lsng....@gmail.com

unread,
Nov 5, 2018, 12:02:41 AM11/5/18
to
On Monday, November 5, 2018 at 12:03:14 PM UTC+8, Liang Ng wrote:
> 3) I am having problem making .so files from jonesforth and pforth.

1) To be more specific, I downloaded jonesforth from:

https://github.com/nornagon/jonesforth

2) Compile jonesforth:

gcc -m32 -nostdlib -static -o jonesforth jonesforth.S

3) Compile libjonesforth.so

gcc -m32 -nostdlib -static -shared -o libjonesforth.so jonesforth.S


4) To run jonesforth:

cat jonesforth.f - | ./jonesforth
JONESFORTH VERSION 47
14499 CELLS REMAINING
OK

5) I exported the symbols of both jonesforth and libjonesforth:

https://github.com/udexon/fire4x
o_nm_jonesforth
o_nm_libjonesforth

I am trying to figure out which symbol represents the entry point to joinesforth (like main() in C)?

Then I can pipe the input into the entry point in libjoneforth.

Any idea?

Liang Ng

unread,
Nov 5, 2018, 4:11:10 AM11/5/18
to
On Monday, 5 November 2018 13:02:41 UTC+8, lsng....@gmail.com wrote:
> On Monday, November 5, 2018 at 12:03:14 PM UTC+8, Liang Ng wrote:
> > 3) I am having problem making .so files from jonesforth and pforth.
>
> 1) To be more specific, I downloaded jonesforth from:
>
> https://github.com/nornagon/jonesforth> 5) I exported the symbols of both jonesforth and libjonesforth:
>
> https://github.com/udexon/fire4x
> o_nm_jonesforth
> o_nm_libjonesforth
>
> I am trying to figure out which symbol represents the entry point to joinesforth (like main() in C)?
>
> Then I can pipe the input into the entry point in libjoneforth.

I realize that Forth needs a "C interface" i.e. code to support C function return value convention to return values to Firefox.

So far, pforth seems to have this.

For other Forthes, please let me know if you have a C API. If not, perhaps we need to work out one.

Anyway, users will choose which Forth is the best at the end of the day -- fastest, most stable, most portable etc.

lsng....@gmail.com

unread,
Nov 6, 2018, 8:01:52 PM11/6/18
to
On Monday, November 5, 2018 at 12:03:14 PM UTC+8, Liang Ng wrote:
> On Sunday, 4 November 2018 17:36:08 UTC+8, Liang Ng wrote:
> > On Sunday, 4 November 2018 13:46:09 UTC+8, Liang Ng wrote:
>
> > > Entry point for Forth into Firefox Spidermonkey
> > https://github.com/udexon/fire4x/blob/master/js.cpp

I have added the myjs_system() example from hello-spidermonkey github repo to my js.cpp.

https://github.com/udexon/fire4x/blob/master/js.cpp line 1746

However, due to a recent code changes to JS_EncodeString*() functions which affected many other calling functions, and yet MDN has not updated its documentation, I have to dig deep directly in hg.mozilla.org for solutions. Fortunately, plenty of examples were provided, as shown below.

https://bugzilla.mozilla.org/show_bug.cgi?id=1485066

https://hg.mozilla.org/.../mozilla-inbound/rev/9f5767f1b04c
0 new messages