caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Anil Madhavapeddy <anil@recoil.org>
To: Andy Ray <andy.ray@ujamjar.com>
Cc: Ocaml Mailing List <caml-list@inria.fr>, Leo White <lpw25@cam.ac.uk>
Subject: Re: [Caml-list] camlp4 for js_of_ocaml toplevels
Date: Mon, 24 Feb 2014 23:31:25 +0000	[thread overview]
Message-ID: <20140224233125.GE12291@dark.recoil.org> (raw)
In-Reply-To: <CAHYOizGtocS17dt8FcEo9QmOCZvA=Kzoknekk7a4QvbhVgftFA@mail.gmail.com>

On Mon, Feb 24, 2014 at 05:55:03PM +0000, Andy Ray wrote:
> >> Is anyone working on making camlp4 extensions available in a
> >> js_of_ocaml toplevel?
> >>
> >> I have seen the work the OCamlPro guys have done to get pa_js going by
> >> hacking the compiler itself - serious kudos for that!
> >>
> >> Is there a reason why that's easier than js_of_ocaml compiling a
> >> (static) version of camlp4?
> >
> > Leo White put together a custom compiler frontend for just this use
> > case a while back:
> >
> > https://github.com/lpw25/ocaml-with-pp
> >
> > The idea is that you build this with a static set of camlp4 extensions,
> > and it runs the input through camlp4 and then passes the AST directly
> > through to the compiler (via compiler-libs).
> >
> > It should be reasonably easy to adapt this to a toplevel model
> > as well -- let us know if you need a hand.
> 
> 
> A good amount of hacking and I have some camlp4 code running via js_of_ocaml.

Fantastic!

> I basically took the compilation process of camlp4orf, added pa_js.cmo
> and slightly modified the driver program so it took a static command
> line of the form `-str "let a = b##c"`.  Also needed a bit of hacking
> around temp file generation.
> 
> My next step is to try and figure out a way to get camlp4 to transform
> "string -> string" rather than "hacked js_of_ocaml psuedo file ->
> hacked console log in browser".  Can't say I ever really wanted to
> know much about the insides of camlp4, but there you go....
> 
> One thing I noticed was when I (accidentally) had unix_isatty
> returning false, and presumably camlp4 attempting to marshal a
> compiler ast the js_of_ocaml runtime would die with a JSON error.  I
> presume this is an issue with js_of_ocaml's marshalling code?

Sounds like it -- camlp4 in non-tty mode would just be using Marshal to
send the data.  It looks like js_of_ocaml has a hand-written Marshall
module that mimics the standard OCaml wire format:
https://github.com/ocsigen/js_of_ocaml/blob/master/runtime/marshall.js

I'm not really sure why a bug here would result in a JSON error without
looking into it more deeply though...

-anil

  reply	other threads:[~2014-02-24 23:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-22  3:07 Andy Ray
2014-02-23 20:18 ` Anil Madhavapeddy
2014-02-24 17:55   ` Andy Ray
2014-02-24 23:31     ` Anil Madhavapeddy [this message]
2014-02-27  8:34     ` Olivier Levillain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140224233125.GE12291@dark.recoil.org \
    --to=anil@recoil.org \
    --cc=andy.ray@ujamjar.com \
    --cc=caml-list@inria.fr \
    --cc=lpw25@cam.ac.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).