caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* camlp4 question
@ 2005-09-08  8:02 Christophe Raffalli
  2005-09-08  8:16 ` Christophe Raffalli
  2005-09-08 17:41 ` [Caml-list] " Martin Jambon
  0 siblings, 2 replies; 8+ messages in thread
From: Christophe Raffalli @ 2005-09-08  8:02 UTC (permalink / raw)
  To: caml-list


I am writing a tool to facilitate the use of callback of camlfunction 
from C. I have a first prototype running for lablGlut, but I want to 
make it nicer using camlp4 (this extension should produce automatically 
the C wrapper for each callback, the user will only have to compile the 
produced C file).

The pb is that I need to retrieve information given in one module from 
another. The minimum I need to do is to search for the path given to 
ocamlc (the -I options) from camlp4 code, but I would prefer a better 
way, and I do not know how to retrive this PATH anyway.

Here is an example to illustrate what I need (the type 'a callback is a 
type to a C wrapper for a function of type 'a) :

-- file glut.ml, part of the lablGlut library --

...

let visibility_state_of_int = function
     0 ->  NOT_VISIBLE
   | 1 -> VISIBLE
   | _ -> raise (BadEnum "visibility_state")

REGISTER_CONVERSION visibility_state_of_int

external visibilityFunc :
   cb:(state:visibility_state_t->unit) callback->unit
    = "ml_glutVisibilityFunc"

...

-- file test.ml an example using lablGlut --

open Glut

...

let state_changed ~state =
   match value with
     NOT_VISIBLE -> printf "window not visible."; print_newline()
   | VISIBLE -> printf "window not visible."; print_newline()

MAKE_WRAPPER state_changed state_changed_cb
(* here I need to search for the convertion for the type 
visibility_state_of_int which was defined in glut.ml to make the
C wrapper state_changed_cb : (visibility_state_of_int -> unit) callback *)

let _ = Glut.visibilityFunc state_changed_cb

...

Can someone help ?


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

* Re: camlp4 question
  2005-09-08  8:02 camlp4 question Christophe Raffalli
@ 2005-09-08  8:16 ` Christophe Raffalli
  2005-09-08 17:36   ` [Caml-list] " Martin Jambon
  2005-09-08 17:41 ` [Caml-list] " Martin Jambon
  1 sibling, 1 reply; 8+ messages in thread
From: Christophe Raffalli @ 2005-09-08  8:16 UTC (permalink / raw)
  To: Christophe Raffalli; +Cc: caml-list


Yet another question ....

I was assuming you oculd ask the type of an expression in camlp4 to do 
an induction over it (the type) ....

I do not see that in the manual !

(you can only construct trees with camlp4, but you cannot match them ?)



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

* Re: [Caml-list] Re: camlp4 question
  2005-09-08  8:16 ` Christophe Raffalli
@ 2005-09-08 17:36   ` Martin Jambon
  2005-09-08 17:44     ` Christophe Raffalli
  0 siblings, 1 reply; 8+ messages in thread
From: Martin Jambon @ 2005-09-08 17:36 UTC (permalink / raw)
  To: Christophe Raffalli; +Cc: caml-list

On Thu, 8 Sep 2005, Christophe Raffalli wrote:

> Yet another question ....
>
> I was assuming you oculd ask the type of an expression in camlp4 to do an 
> induction over it (the type) ....

You can't, Camlp4 is only about parsing and transforming the syntax 
tree.

I imagine you could use a (complicated) 3-step approach:
1) preprocess the file with camlp4 and ignore the syntax extensions
2) compile the result with -dtypes
3) fetch the type information from the .annot file and reparse the 
original file with camlp4. This time you can get the type of 
each identifier and expand your special syntax constructs

> I do not see that in the manual !
>
> (you can only construct trees with camlp4, but you cannot match them ?)

You can use quotations in patterns to read the syntax tree. Is it what you 
mean?


Martin

--
Martin Jambon, PhD
http://martin.jambon.free.fr


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

* Re: [Caml-list] camlp4 question
  2005-09-08  8:02 camlp4 question Christophe Raffalli
  2005-09-08  8:16 ` Christophe Raffalli
@ 2005-09-08 17:41 ` Martin Jambon
  1 sibling, 0 replies; 8+ messages in thread
From: Martin Jambon @ 2005-09-08 17:41 UTC (permalink / raw)
  To: Christophe Raffalli; +Cc: caml-list

On Thu, 8 Sep 2005, Christophe Raffalli wrote:

> I am writing a tool to facilitate the use of callback of camlfunction from C. 
> I have a first prototype running for lablGlut, but I want to make it nicer 
> using camlp4 (this extension should produce automatically the C wrapper for 
> each callback, the user will only have to compile the produced C file).
>
> The pb is that I need to retrieve information given in one module from 
> another. The minimum I need to do is to search for the path given to ocamlc 
> (the -I options) from camlp4 code, but I would prefer a better way, and I do 
> not know how to retrive this PATH anyway.

Maybe write a script which would transmit the -I options to camlp4o and to 
ocamlopt/ocamlc (each camlp4 loadable module can define additional options 
to pass to camlp4/camlp4o)

Martin

>
> Here is an example to illustrate what I need (the type 'a callback is a type 
> to a C wrapper for a function of type 'a) :
>
> -- file glut.ml, part of the lablGlut library --
>
> ...
>
> let visibility_state_of_int = function
>    0 ->  NOT_VISIBLE
>  | 1 -> VISIBLE
>  | _ -> raise (BadEnum "visibility_state")
>
> REGISTER_CONVERSION visibility_state_of_int
>
> external visibilityFunc :
>  cb:(state:visibility_state_t->unit) callback->unit
>   = "ml_glutVisibilityFunc"
>
> ...
>
> -- file test.ml an example using lablGlut --
>
> open Glut
>
> ...
>
> let state_changed ~state =
>  match value with
>    NOT_VISIBLE -> printf "window not visible."; print_newline()
>  | VISIBLE -> printf "window not visible."; print_newline()
>
> MAKE_WRAPPER state_changed state_changed_cb
> (* here I need to search for the convertion for the type 
> visibility_state_of_int which was defined in glut.ml to make the
> C wrapper state_changed_cb : (visibility_state_of_int -> unit) callback *)
>
> let _ = Glut.visibilityFunc state_changed_cb
>
> ...
>
> Can someone help ?
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>

--
Martin Jambon, PhD
http://martin.jambon.free.fr


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

* Re: [Caml-list] Re: camlp4 question
  2005-09-08 17:36   ` [Caml-list] " Martin Jambon
@ 2005-09-08 17:44     ` Christophe Raffalli
  0 siblings, 0 replies; 8+ messages in thread
From: Christophe Raffalli @ 2005-09-08 17:44 UTC (permalink / raw)
  To: Martin Jambon; +Cc: caml-list

Martin Jambon a écrit :
> On Thu, 8 Sep 2005, Christophe Raffalli wrote:
> 
>> Yet another question ....
>>
>> I was assuming you oculd ask the type of an expression in camlp4 to do 
>> an induction over it (the type) ....
> 
> 
> You can't, Camlp4 is only about parsing and transforming the syntax tree.
> 
> I imagine you could use a (complicated) 3-step approach:
> 1) preprocess the file with camlp4 and ignore the syntax extensions
> 2) compile the result with -dtypes
> 3) fetch the type information from the .annot file and reparse the 
> original file with camlp4. This time you can get the type of each 
> identifier and expand your special syntax constructs
> 
>> I do not see that in the manual !
>>
>> (you can only construct trees with camlp4, but you cannot match them ?)
> 
> 
> You can use quotations in patterns to read the syntax tree. Is it what 
> you mean?


Yes I saw that later (after acually using the type in MLast t odo the 
same ...)

All that lacks a lot of documentation, but in one day, I found my way ;-)

> 
> Martin
> 
> -- 
> Martin Jambon, PhD
> http://martin.jambon.free.fr


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

* Camlp4 question
@ 2009-06-14  0:25 Jacques Le Normand
  0 siblings, 0 replies; 8+ messages in thread
From: Jacques Le Normand @ 2009-06-14  0:25 UTC (permalink / raw)
  To: caml-list caml-list

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

Hello list,
how does one define type parameter syntax with camlp4?
right now I'm using:

  test:
    [[
       "mytype" ; options = OPT parameters  ; ident = a_LIDENT; "=" ; ctyp
-> (ident,atoms)
     ]];

  parameters:
    [
      ["(";params = comma_type_parameter;")" -> params]
    |
    [tp = type_parameter -> tp ]];

Is this the right way to do it or has parameters already been defined
elsewhere?

--Jacques L.

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

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

* camlp4 question
@ 2005-11-30  9:29 Christophe Raffalli
  0 siblings, 0 replies; 8+ messages in thread
From: Christophe Raffalli @ 2005-11-30  9:29 UTC (permalink / raw)
  To: caml-list

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


I would like to produce an abbreviated command for

camlp4 mylexer.cmo mypa_o.cmo pa_extend.cmo q_MLast.cmo pr_dump.cmo\
  pa_bindlib.cmo

I tried to mimic the compilation of camlp4o:

ocamlc -I +camlp4 odyl.cma camlp4.cma mylexer.cmo mypa_o.cmo\
 pa_bindlib.cmo pr_dump.cmo odyl.cmo -o camlp4bo

But when I try to use ocamlp4bo, it produces no output ...

What am I doing wrong ?


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 894 bytes --]

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

* Camlp4 question
@ 2005-10-28 19:44 Matt Gushee
  0 siblings, 0 replies; 8+ messages in thread
From: Matt Gushee @ 2005-10-28 19:44 UTC (permalink / raw)
  To: caml-list

I had occasion today to look through the pa_r.ml, and noticed the
following (line 329 in OCaml 3.08.4):

  | "object"; cspo = OPT class_self_patt; cf = class_structure; "end" ->
      (* <:expr< object $opt:cspo$ $list:cf$ end >> *)
      MLast.ExObj loc cspo cf ]

So a quotation expander was created for objects as ordinary expressions,
but evidently there was something wrong with it. Anyone know what the
problem was?

--
Matt Gushee
Englewood, CO, USA


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

end of thread, other threads:[~2009-06-14  0:25 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-08  8:02 camlp4 question Christophe Raffalli
2005-09-08  8:16 ` Christophe Raffalli
2005-09-08 17:36   ` [Caml-list] " Martin Jambon
2005-09-08 17:44     ` Christophe Raffalli
2005-09-08 17:41 ` [Caml-list] " Martin Jambon
2005-10-28 19:44 Camlp4 question Matt Gushee
2005-11-30  9:29 camlp4 question Christophe Raffalli
2009-06-14  0:25 Camlp4 question Jacques Le Normand

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