Giter Site home page Giter Site logo

ocaml.jl's Introduction

OCaml.jl

Dev Build Status

This package enables you to generate Julia bindings for OCaml libraries with no boilerplate.

How to build the example

To build and run the example, type the following at the root of this repo:

make testjl

How this works

In examples/libocaml/api.mli, we find the following function declaration:

val evaluate: expr -> int

From this signature, the following C wrapper is generated automatically:

value* evaluate(value *x0) {
  static const value *_f = NULL;
  if (_f == NULL) _f = caml_named_value("evaluate");
  value *_r = malloc(sizeof(value));
  *_r = caml_callback_exn(*_f, *x0);
  if (Is_exception_result(*_r)) {
    caml_last_exception = Extract_exception(*_r);
    caml_register_generational_global_root(&caml_last_exception);
    free(_r);
    return NULL;
  }
  else {
    caml_register_generational_global_root(_r);
    return _r;
  }
}

Also, the following Julia stub is generated:

@caml evaluate(::Caml{:expr}) :: Caml{:int}

where the @caml macro expands to:

function evaluate(e)
  e = convert(Caml{:expr}, e)
  GC.@preserve e begin
    ptr = ccall((:evaluate, OCAML_LIB), Ptr{Cvoid}, (Ptr{Cvoid},), e.ptr)
    return tojulia(Caml{:int}(ptr))
  end
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.