caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Generating a module implementation from a module signature using camlp4
@ 2012-10-12 17:36 Mike McClurg
  2012-10-12 17:55 ` Wojciech Meyer
  2012-10-13 13:06 ` [Caml-list] ocaml 3.12.1 and delimcc Christophe Raffalli
  0 siblings, 2 replies; 6+ messages in thread
From: Mike McClurg @ 2012-10-12 17:36 UTC (permalink / raw)
  To: caml-list

Hi list,

I am trying to write a bit of camlp4 that will take as input a module
signature, preferably in mli form, and generate a module
implementation as an ml file. My goal is to implement a mocking
framework for OCaml modules.

It seems that I would want to use a camlp4 filter to do this, but as
far as I can tell it's not possible to create a filter from sig_items
to str_items. Is a filter the right approach? Am I going to have to
define my module signatures as module type definitions from within ml
files? Can anyone give me some some advice on how to do this properly?

Mike

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] Generating a module implementation from a module signature using camlp4
  2012-10-12 17:36 [Caml-list] Generating a module implementation from a module signature using camlp4 Mike McClurg
@ 2012-10-12 17:55 ` Wojciech Meyer
  2012-10-12 18:03   ` Mike McClurg
  2012-10-13 13:06 ` [Caml-list] ocaml 3.12.1 and delimcc Christophe Raffalli
  1 sibling, 1 reply; 6+ messages in thread
From: Wojciech Meyer @ 2012-10-12 17:55 UTC (permalink / raw)
  To: Mike McClurg; +Cc: caml-list

Hi Mike,

Mike McClurg <mike.mcclurg@gmail.com> writes:

> It seems that I would want to use a camlp4 filter to do this, but as
> far as I can tell it's not possible to create a filter from sig_items
> to str_items. Is a filter the right approach? Am I going to have to
> define my module signatures as module type definitions from within ml
> files? Can anyone give me some some advice on how to do this properly?

You can explicitly pretty print the camlp4 quotations:

open Camlp4
open Camlp4.PreCast
let _loc = Loc.ghost

let foo nm =
  <:str_item<module $uid:nm$ = struct let $lid:String.lowercase nm$ = () end>>


module OCamlPrinter = Camlp4.PreCast.Printers.OCaml;;

OCamlPrinter.print_implem (foo "OK")
==

Then you need some ocamlbuild plugin to create a rule that pipes to a
file.

--
Wojciech Meyer
http://danmey.org

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] Generating a module implementation from a module signature using camlp4
  2012-10-12 17:55 ` Wojciech Meyer
@ 2012-10-12 18:03   ` Mike McClurg
       [not found]     ` <507871F9.5040605@gmail.com>
  0 siblings, 1 reply; 6+ messages in thread
From: Mike McClurg @ 2012-10-12 18:03 UTC (permalink / raw)
  To: Wojciech Meyer; +Cc: caml-list

On Fri, Oct 12, 2012 at 6:55 PM, Wojciech Meyer
<wojciech.meyer@googlemail.com> wrote:
> Hi Mike,
>
> Mike McClurg <mike.mcclurg@gmail.com> writes:
>
>> It seems that I would want to use a camlp4 filter to do this, but as
>> far as I can tell it's not possible to create a filter from sig_items
>> to str_items. Is a filter the right approach? Am I going to have to
>> define my module signatures as module type definitions from within ml
>> files? Can anyone give me some some advice on how to do this properly?
>
> You can explicitly pretty print the camlp4 quotations:
>
> open Camlp4
> open Camlp4.PreCast
> let _loc = Loc.ghost
>
> let foo nm =
>   <:str_item<module $uid:nm$ = struct let $lid:String.lowercase nm$ = () end>>
>
>
> module OCamlPrinter = Camlp4.PreCast.Printers.OCaml;;
>
> OCamlPrinter.print_implem (foo "OK")

Hi Wojciech,

Thanks for that advice. I attempted something like this earlier, but
even with your printer module I get the following:

Error: This expression has type AstFilters.Ast.str_item
       but an expression was expected of type Camlp4.PreCast.Ast.str_item

Is there any way to unify the modules AstFilters.Ast and
Camlp4.PreCast.Ast? In my earlier attempt I tried some module Foo =
Blah with module ... trickery, but I couldn't seem to unify the types
properly.

Mike

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Caml-list] Re: Generating a module implementation from a module signature using camlp4
       [not found]     ` <507871F9.5040605@gmail.com>
@ 2012-10-12 21:01       ` Mike McClurg
  0 siblings, 0 replies; 6+ messages in thread
From: Mike McClurg @ 2012-10-12 21:01 UTC (permalink / raw)
  To: Hongbo Zhang, caml-list

On Fri, Oct 12, 2012 at 8:39 PM, Hongbo Zhang <bobzhang1988@gmail.com> wrote:
> On 10/12/12 2:03 PM, Mike McClurg wrote:
>> On Fri, Oct 12, 2012 at 6:55 PM, Wojciech Meyer
>> <wojciech.meyer@googlemail.com> wrote:
>>>
>>> Hi Mike,
>>>
>>> You can explicitly pretty print the camlp4 quotations:
>>>
>>> let foo nm =
>>>    <:str_item<module $uid:nm$ = struct let $lid:String.lowercase nm$ = ()
>>> end>>
>>>
>>> module OCamlPrinter = Camlp4.PreCast.Printers.OCaml;;
>>> OCamlPrinter.print_implem (foo "OK")
>>
>> Hi Wojciech,
>>
>> Thanks for that advice. I attempted something like this earlier, but
>> even with your printer module I get the following:
>>
>> Error: This expression has type AstFilters.Ast.str_item
>>         but an expression was expected of type Camlp4.PreCast.Ast.str_item
>>
>> Is there any way to unify the modules AstFilters.Ast and
>> Camlp4.PreCast.Ast? In my earlier attempt I tried some module Foo =
>> Blah with module ... trickery, but I couldn't seem to unify the types
>> properly.
>
> They are actually the same, unfortunately the interface does not expose the
> equality, the ugly solution is to use
> Obj.magic

Hey, that works! I probably wouldn't have thought to use Obj.magic. I
think it's probably OCaml's goto statement. It's not that it should
never be used, but there are so few cases where it's appropriate that
we condition ourselves not to think about it. Well, at least I have.

> Another solution to your problem is to use map to traverse sig_item, but
> maintain a state in your object to collect them as str_items

Yes, that's basically what I want to do. I just needed a way to print
those str_items directly, because sig_item filters can only return
sig_items.

Thanks for the help Hongbo and Wojciech.

Mike

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Caml-list] ocaml 3.12.1 and delimcc
  2012-10-12 17:36 [Caml-list] Generating a module implementation from a module signature using camlp4 Mike McClurg
  2012-10-12 17:55 ` Wojciech Meyer
@ 2012-10-13 13:06 ` Christophe Raffalli
  2012-10-13 14:38   ` Anthony Tavener
  1 sibling, 1 reply; 6+ messages in thread
From: Christophe Raffalli @ 2012-10-13 13:06 UTC (permalink / raw)
  To: caml-list

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Hello,

I failed to have the delimited continuation library working
with ocaml 3.12.1 on an amd64. bytecode is fine but
native code segfaults one the provided regression test:

raffalli@delli7:~/Caml/caml-shift$ make testd0opt
/usr/bin/ocamlopt -o testd0opt -cclib -L. delimcc.cmxa  testd0.ml
./testd0opt
make: *** [testd0opt] Erreur de segmentation
make: *** Destruction du fichier « testd0opt »

I tried both the provided header file and those of the
original distribution.

Did anyone succeded with delimcc on 3.12.1 or 4.0.X ?

Cheers,
Christophe
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAlB5Z0wACgkQi9jr/RgYAS7apwCeJ4u+Wd9ScYU4aLWzZMZBuchU
beYAn3rjvAWfnVsEsLn9UR9HBxsVSrOd
=Mozm
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Caml-list] ocaml 3.12.1 and delimcc
  2012-10-13 13:06 ` [Caml-list] ocaml 3.12.1 and delimcc Christophe Raffalli
@ 2012-10-13 14:38   ` Anthony Tavener
  0 siblings, 0 replies; 6+ messages in thread
From: Anthony Tavener @ 2012-10-13 14:38 UTC (permalink / raw)
  To: Christophe Raffalli; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 2034 bytes --]

Interesting to see that it's not working on 3.12.1. I ran into the same
problem with 4.00.0, also on amd64. I've been successfully using delimcc
(native) on a 32-bit machine with ocaml 3.12.0.

Based on this message from Oleg...

http://caml.inria.fr/pub/ml-archives/caml-list/2010/08/f7e9bbdc114f17b5714146abe1793278.en.html
... delimcc's native implementation should have been more portable, and it
was working for 3.12.0 on amd64. So likely a change brought in with 3.12.1
needs to be accommodated. This is a lot simpler to investigate than the
jump to 4.0! I might look at it today, depending on visiting company.

This is encouraging. Up to now I've been using my older machine rather than
dig into this problem.

 Tony


On Sat, Oct 13, 2012 at 7:06 AM, Christophe Raffalli <
christophe.raffalli@univ-savoie.fr> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
>
> Hello,
>
> I failed to have the delimited continuation library working
> with ocaml 3.12.1 on an amd64. bytecode is fine but
> native code segfaults one the provided regression test:
>
> raffalli@delli7:~/Caml/caml-shift$ make testd0opt
> /usr/bin/ocamlopt -o testd0opt -cclib -L. delimcc.cmxa  testd0.ml
> ./testd0opt
> make: *** [testd0opt] Erreur de segmentation
> make: *** Destruction du fichier « testd0opt »
>
> I tried both the provided header file and those of the
> original distribution.
>
> Did anyone succeded with delimcc on 3.12.1 or 4.0.X ?
>
> Cheers,
> Christophe
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.12 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAlB5Z0wACgkQi9jr/RgYAS7apwCeJ4u+Wd9ScYU4aLWzZMZBuchU
> beYAn3rjvAWfnVsEsLn9UR9HBxsVSrOd
> =Mozm
> -----END PGP SIGNATURE-----
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>

[-- Attachment #2: Type: text/html, Size: 2981 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-10-13 14:38 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-12 17:36 [Caml-list] Generating a module implementation from a module signature using camlp4 Mike McClurg
2012-10-12 17:55 ` Wojciech Meyer
2012-10-12 18:03   ` Mike McClurg
     [not found]     ` <507871F9.5040605@gmail.com>
2012-10-12 21:01       ` [Caml-list] " Mike McClurg
2012-10-13 13:06 ` [Caml-list] ocaml 3.12.1 and delimcc Christophe Raffalli
2012-10-13 14:38   ` Anthony Tavener

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).