atilaneves / dpp

Directly include C headers in D source code
Boost Software License 1.0
230 stars 31 forks source link

can't include #include <caml/memory.h> #251

Open FraMecca opened 4 years ago

FraMecca commented 4 years ago
#include <stdio.h>
#include <assert.h>

// #include <caml/alloc.h>                                                                                                                                                    
// #include <caml/mlvalues.h>                                                                                                                                                 
#include <caml/memory.h>
// #include <caml/callback.h>                                                                                                                                                 

import std.stdio: writeln;

void ocaml_test_return_string() {
    CAMLlocal1(res);
}

void main(string[] argv)
{
    writeln(argv);
}
$ d++ main.dpp
Error: Could not execute `dmd main.d -ofmain`:
main.d(7282): Error: found `int` when expecting `;` following statement
Laeeth commented 4 years ago

I don't know about this one as a while since I looked at. But i figured out what problematic macros were doing and then just rewrote the code inline or as a template - don't quite remember but a working trivial example of caml calling D is up on code.dlang.org I think. I didn't take it any further.

Laeeth commented 4 years ago

AST to AST translation for C to D would be nice. It's not that bad although quite a lot of work. See c2rust

atilaneves commented 4 years ago

Macros are... hard. In this case there's two issues: one is the non-standard __attribute__((unused)) that causes the original error, but even removing it manually causes another issue which is that the CALxparam1 macro uses the result of a comma expression, which is now illegal in D. I don't think this is fixable.