Thread overview
[Issue 24291] ImportC: cannot compile janet.c
Dec 24, 2023
Walter Bright
Dec 25, 2023
anonymous4
Dec 25, 2023
anonymous4
Dec 27, 2023
Walter Bright
Dec 27, 2023
Daniel
Dec 29, 2023
anonymous4
Dec 30, 2023
Walter Bright
[Issue 24291] ImportC: support computed goto
Dec 30, 2023
Walter Bright
Dec 30, 2023
Walter Bright
December 24, 2023
https://issues.dlang.org/show_bug.cgi?id=24291

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com

--- Comment #1 from Walter Bright <bugzilla@digitalmars.com> ---
Can you please try reducing this to the offending few lines of code? I don't have src/core/vm.c, and probably not exactly the same .h files you're using, either.

--
December 25, 2023
https://issues.dlang.org/show_bug.cgi?id=24291

anonymous4 <dfj1esp02@sneakemail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                URL|                            |https://forum.dlang.org/pos
                   |                            |t/woaixickqgqvfsazutex@foru
                   |                            |m.dlang.org

--- Comment #2 from anonymous4 <dfj1esp02@sneakemail.com> ---
>From forum discussion:
---
One Problem with Janet is that it uses computed gotos which is a
gcc extension
The code it complains about looks like:
```C
     /* opcode -> label lookup if using clang/GCC */
#ifdef JANET_USE_COMPUTED_GOTOS
     static void *op_lookup[255] = {
         &&label_JOP_NOOP,
         &&label_JOP_ERROR,
```

As you can see &&label is not valid C11.
Which is what the import C parser complains about.
---

Maybe something can be done there with that JANET_USE_COMPUTED_GOTOS define.

--
December 25, 2023
https://issues.dlang.org/show_bug.cgi?id=24291

--- Comment #3 from anonymous4 <dfj1esp02@sneakemail.com> ---
clang provides __has_extension function for such checks, but doesn't document computed gotos.

--
December 27, 2023
https://issues.dlang.org/show_bug.cgi?id=24291

--- Comment #4 from Walter Bright <bugzilla@digitalmars.com> ---
If you can post the definition of JANET_USE_COMPUTED_GOTOS we can see about making it evaluate to false.

--
December 27, 2023
https://issues.dlang.org/show_bug.cgi?id=24291

Daniel <wyrlon@gmx.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |wyrlon@gmx.net

--- Comment #5 from Daniel <wyrlon@gmx.net> ---
#if defined(__GNUC__) && !defined(__EMSCRIPTEN__)
#define JANET_USE_COMPUTED_GOTOS
#endif

--
December 29, 2023
https://issues.dlang.org/show_bug.cgi?id=24291

--- Comment #6 from anonymous4 <dfj1esp02@sneakemail.com> ---
Oh, __GNUC__ means gnu C dialect?

--- cjanet.c ---
#undef __GNUC__
#include "janet.c"
---
dmd -P-I. -c cjanet.c

Does this work?

--
December 30, 2023
https://issues.dlang.org/show_bug.cgi?id=24291

--- Comment #7 from Walter Bright <bugzilla@digitalmars.com> ---
(In reply to Daniel from comment #5)
> #if defined(__GNUC__) && !defined(__EMSCRIPTEN__)
> #define JANET_USE_COMPUTED_GOTOS
> #endif

Unfortunately, if dmd #define'd __EMSCRIPTEN__ it would likely turn on some other nutburger extensions ImportC doesn't support. importc.h cannot #undef JANET_USE_COMPUTED_GOTOS because importc.h is #include'd first.

Turning off __GNUC__ will cause all kinds of other problems.

--
December 30, 2023
https://issues.dlang.org/show_bug.cgi?id=24291

Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Hardware|x86_64                      |All
            Summary|ImportC: cannot compile     |ImportC: support computed
                   |janet.c                     |goto
                 OS|Linux                       |All

--- Comment #8 from Walter Bright <bugzilla@digitalmars.com> ---
I'm going to leave this as an enhancement request for computed goto. If there are other ImportC problems with janet, please post a bugzilla issue about it!

https://gcc.gnu.org/onlinedocs/gcc/Labels-as-Values.html

--
December 30, 2023
https://issues.dlang.org/show_bug.cgi?id=24291

--- Comment #9 from Walter Bright <bugzilla@digitalmars.com> ---
At least I can get you a better error message:

https://github.com/dlang/dmd/pull/15967

--