c3lang / c3c

Compiler for the C3 language
GNU Lesser General Public License v3.0
2.6k stars 149 forks source link

Output raw cpp/h files? #1260

Open YanDevDe opened 1 month ago

YanDevDe commented 1 month ago

Hello,

this is an very interesting new language and so I was wondering if you're able to compile to raw cpp/h as well? In order for me to use it for ESP32/STM32/Arduino with PlatformIO?

I'm kinda getting sick to have 2 different files, cpp and header but I value speed / performance of cpp for IoT devices haha

lerno commented 1 month ago

You mean whether there is an option to output C code? If so, no there isn't. It's something that hopefully will happen some time in the future, but it's not a priority.

lerno commented 1 month ago

And one more addition: while there is still changes to the semantics and the language (i.e. 0.6-0.9) it's going to be less fun to support an additional backend. So this is better done once the language is 1.0.

After 1.0, the versioning of the compiler, language and the standard library will diverge:

  1. The language will then have editions, starting with the year when 1.0 is complete.
  2. The compiler will continue normal semantic versioning from 1.0
  3. The standard library will use semantic versioning from 1.0 independent of the compiler.
YanDevDe commented 1 month ago

Exactly, to output C or even C++ - just like TypeScript outputting to JavaScript :)

Got it - thank you so much!

lerno commented 1 month ago

That said STM32 is an ARM processor, so it would be possible to just be able to cross compile code for it if I enable the ARM target. – But it requires someone to test and help out with library linking etc.

YanDevDe commented 1 month ago

I'm more rather interested for the ESP32! Which they uses RISC-V processor. Questions however remains if native C++ library would be compatible with C3C?

lerno commented 1 month ago

The support I have already for RISC-V is probably better than 32-bit ARM. C3 would be able to use a C++ library through a C API, but not directly with C++. For C++ I'd say these possibilities exist:

  1. Write all the code in C3, access the C++ library through a C wrapper

    C3 <---> C API wrapper <---> C++ Library
  2. Write some C++ code, which calls C3 (as if it was C) and also calls the C++ library.

C++ main code <---> C3
   ^
   |
   v
C++ Library
YanDevDe commented 1 month ago

Interesting! I'm going to try out in couple of days! Thank you so much lerno!

I'm also wondering how the performance is between vs. native C++? There also exists MicroPython for ESP32 but the reason why I don't use it is because it's too horrible slow and ESP32 is not really the fastest chip out there.

lerno commented 1 month ago

It should be the same as using C++.

lerno commented 1 month ago

You can try using elf-riscv32 / 64 targets now.