stedolan / malfunction

Malfunctional Programming
Other
336 stars 19 forks source link

Documentation on adding primitives #21

Closed ziman closed 4 years ago

ziman commented 4 years ago

Is there any documentation on how to add primitives to Malfunction so that we can use the OCaml standard library? Currently, I'm reading (and grepping) the sources of the OCaml compiler, the stdlib, and Malfunction, and slowly trying to figure out how everything works. Some primitives seem to be implemented as C functions; some seem to be builtins.

I tried copy-pasting bits and pieces around and editing them, which made the compiler stop complaining about some unimplemented primitives such as %string_length (and start complaining about the next one), but don't know if it will work once it eventually compiles.

Is there any recommended reference to look at?

stedolan commented 4 years ago

I'm afraid there's not a huge amount of docs on the guts of the compiler, so reading and grepping is the best option at the moment. (There are a few HACKING.adoc files in the OCaml sources that might be helpful).

ziman commented 4 years ago

So for the record, the answer is that we actually don't want to add more primitives because:

  1. they're unstable between OCaml releases
  2. they don't work in the evaluator

The correct way is to use just the provided Malfunction primitives (such as byte arrays, or arrays, even for strings) and if functions in the stdlib require adding OCaml primitives, they need to be reimplemented on the side.