From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 318E57F84F for ; Tue, 25 Feb 2014 00:31:28 +0100 (CET) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of anil@recoil.org) identity=pra; client-ip=89.16.177.154; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="avsm@dark.recoil.org"; x-sender="anil@recoil.org"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of avsm@dark.recoil.org) identity=mailfrom; client-ip=89.16.177.154; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="avsm@dark.recoil.org"; x-sender="avsm@dark.recoil.org"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@dark.recoil.org) identity=helo; client-ip=89.16.177.154; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="avsm@dark.recoil.org"; x-sender="postmaster@dark.recoil.org"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgsFAMzVC1NZELGadGdsb2JhbABZg0GqCpcugX8OAQwVCDyCJQEBBAEnEz8FCwsYCSUPBUmIEAwJxggTBJIPgRQEmDMBilGLAzw X-IPAS-Result: AgsFAMzVC1NZELGadGdsb2JhbABZg0GqCpcugX8OAQwVCDyCJQEBBAEnEz8FCwsYCSUPBUmIEAwJxggTBJIPgRQEmDMBilGLAzw X-IronPort-AV: E=Sophos;i="4.97,537,1389740400"; d="scan'208";a="50362854" Received: from recoil.dh.bytemark.co.uk (HELO dark.recoil.org) ([89.16.177.154]) by mail3-smtp-sop.national.inria.fr with SMTP; 25 Feb 2014 00:31:27 +0100 Received: (qmail 2777 invoked by uid 10000); 24 Feb 2014 23:31:25 -0000 Date: Mon, 24 Feb 2014 23:31:25 +0000 From: Anil Madhavapeddy To: Andy Ray Cc: Ocaml Mailing List , Leo White Message-ID: <20140224233125.GE12291@dark.recoil.org> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [Caml-list] camlp4 for js_of_ocaml toplevels 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