Browse thread
Technical question about internal representation of functional values
- Benjamin Canou
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Benjamin Canou <benjamin.canou@g...> |
| Subject: | Technical question about internal representation of functional values |
Hi, I have a strange question, for which I have a working but incomplete, low level and implementation dependent answer. Maybe I'm missing a less tricky solution, so I want to ask people who understand the internal behaviour of OCaml better than I do. The context is not really important, but let's say, to simplify, that I want to marshal closures in a controlled way (at source level). Basically, I have a table of registered closures that I want to be able to export. These closures are explicitly declared as marshallable in the source by adding them to the table with a dedicated function. There is no way (as far as I know) to build such a polymorphic table, so I use some "not for the casual user" stuff for prototyping and will rely on externals later. Before calling the standard marshal function, I explore the value, and when I find a closure which is in the table, I replace it with a descriptor block (by using a high block tag unused in my prototype, let's say 240). When I find a closure which is not in the table, I reject the value. This is kind of tricky but works well. Now, I want some support for partial applications of these closures (and marshal the environment along with the descriptor block). Unfortunately, a partial application is not easily detectable. My current implementation only works with ocamlopt, is probably highly platform and version dependent and does not satisfy me at all : I unfold applications of "caml_curryN(_M)?". Another idea I have in mind is to write an assembly function which behaves like the vm's application by extending the closure and detect this function (or maybe this application function exists and is bound to an existing C symbol I can use to set Field(closure, 0) ?). So, is there a cleaner way to recognize partial applications of a specific closure by exploring a value ? Thanks for reading these strange questions and my dirty solutions. Benjamin.