monte icon indicating copy to clipboard operation
monte copied to clipboard

compile to JavaScript (SES) to run in browsers (and node.js?)

Open dckc opened this issue 10 years ago • 6 comments

While typhon is cool, web browser deployment is important, if not essential, for many of the ways I want to use monte.

design sketch: source-to-source translation using one of the JS AST APIs.

It seems straightforward except for:

  • [ ] immutability - use freeze() and let as appropriate. and perhaps traits (IOU link)
  • [ ] ejectors - in a small runtime library, implement them using try/catch much like the python implementation
  • [ ] references - javascript evaluation of variables matches the first 3 steps of evaluation in E. For the fourth step, all bindings should go to promises and all evaluation should use .value or something.

This depends on SES, of course.

Here's hoping for time to give it a go...

dckc avatar Jul 31 '15 19:07 dckc

darn; I don't think my references idea will work. noun phrases aren't the only place they show up. They're also in lists and such.

edit: I have since learned that references are actually just normal objects that proxy messages.

dckc avatar Aug 01 '15 05:08 dckc

more ideas:

  • [ ] ADT for AST using flow
  • [ ] prototype source-to-source translation with sweetjs macros?
  • [ ] use traits to build objects, from miranda etc.
  • [ ] get ConstList from immutable

dckc avatar Aug 08 '15 02:08 dckc

progress deserializing .ty to a flow-happy ADT: js-monte

Modern .js is really quite nice:

  • static typechecking with flow, with real-time feedback in emacs via flycheck

I got as far as deserializing typhon's AST for def [x, var y, [=>choc, =>van], bind z] := bzzt.

The ADT I built in rust matched the serialized form but not the actual kernel monte grammar. This js ADT matches kernel monte more closely. The deserialization code makes up the difference, sorta like the fromAST() methods in nodes.py

hmm... export var... not good. unfortunately, flow doesn't yet grok let

one happy byproduct: a JSON serialization of kernel monte

I doubt immutable.js will be worth the trouble for ConstList. Object.freeze() is probably most of the bang for much less buck.

for reference: 8f30ff72c9534ef77a82d182a32cabe40503b0f0 (hg: ebc2c69c69ff)

dckc avatar Aug 08 '15 21:08 dckc

some conversion to javascript via escodegen is working; e.g. { x:= 42; traceln(x) } becomes x = __monte_runtime.wrapInt(42), traceln.run(x). I haven't added var yet because that's at the statement level and I'm only converting expressions so far.

Hmm... I suppose there should be a runtime.makeSlot(...) in there somewhere too.

https://github.com/dckc/js-monte/commit/1700595e3f81b05e2eb1c1adad7392860c6dc281

dckc avatar Aug 09 '15 22:08 dckc

perhaps port Masque to purescript?

dckc avatar May 01 '16 20:05 dckc

The https://github.com/monte-language/spotter work looks like a possible path here. js_of_ocaml and reason and all that are pretty mature.

dckc avatar Oct 10 '19 22:10 dckc