compile to JavaScript (SES) to run in browsers (and node.js?)
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...
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.
more ideas:
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)
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
perhaps port Masque to purescript?
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.