Hi Greg - Continuing our conversation -
On 5/28/15, 12:12 PM, "Greg Kreider" <[email protected]> wrote: >> >>You could use the extern block mechanism, if you have Chapel >>built with LLVM. For example (this example is in our test suite): >> >>extern { >> typedef enum { >> ENUM_A = 1, >> ENUM_B = 0, >> ENUM_C = -1 >> } MyEnum; >>} >> >>var x:MyEnum = ENUM_A; >> >>writeln(x); >> > >OK, we've been using GCC so far so this wasn't an option. >There's already quite a bit of parsing of the C header (we're >using the link between a Chapel class and the C >typedef struct _name { } name construct to access PNG images >that were read in C), and it seemed that a similar link but >for enums would be nice to have. The extern block support needs you to build the Chapel compiler with LLVM, but you can still use GCC to compile the generated C code (or the Chapel compiler for that matter). The extern block stuff uses clang to parse C code, but packages all the right stuff back into generated C so that e.g. GCC can compile it. If you want to give it a try: * make sure you have GCC 4.7 or newer since LLVM wants C++11 features * export CHPL_LLVM=llvm * make -j 4 # this will build LLVM and clang, so -j parallel build * then compile with chpl as usual. extern { } should work. * if you want to use Chapel's experimental LLVM back-end, you'd do chpl --llvm. You don't need to do that in order to use the extern blocks though. For the extern class/extern record case you're describing - if you want to use a record field, you still have to declare it in the Chapel extern class/record. (unless you're using an extern block). So the same problem - that adding a field to the struct now requires you to update it in two places - is still there, just as with the enums. That's why I like the extern block feature. In both scenarios, the Chapel code could use the type even if the rest (enum values or struct fields) were complete in the extern type declarations. But the Chapel compiler doesn't parse any C code unless you're using the extern block feature. (Everything else works by adding the appropriate stuff to the generated C...) That might be more nuts and bolts than you needed... Cheers, -michael ------------------------------------------------------------------------------ _______________________________________________ Chapel-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/chapel-users
