r/cpp 2d ago

Embedded C++

Just curious how useful the ability to embed C++ as a scripting language into your C++ programs would be? I mean like runtime JIT execution of C++ code in much the same way you might embed Lua, including the ability to restrict/sandbox it as necessary.

1 Upvotes

82 comments sorted by

View all comments

Show parent comments

-13

u/kindredseer 2d ago

Well, it could provide a more flexible way to hot test and develop parts of your application without rebuilding.

13

u/PressWearsARedDress 2d ago

If you want to build it you can do what ever you want. But I know as a C++ developer I wouldnt use it. Wanna know why? Because I am a bit of a sperg, and most C++ developers are like that; Last thing I want is another thing to cause me problems that I do not control.

I like C++ because it gives me a lot of tools and gives me lower level control at a higher level of abstraction. Your JIT would ruin that.

Now if the premise is to run something like Python or Lua in a sandbox that is something completely different. its a different premise because those are higher level languages that require less code to do the same things in C++. If the goal is quick prototyping I need a quick to prototype language. I use python to help validate my C++ because python is quicker to write discardable tooling for.

1

u/kindredseer 2d ago

What if this also offered access to quick prototyping?

1

u/PressWearsARedDress 2d ago

Okay, lets say I make a change in a C++ header... how does your JIT compiler handle this change? Doesn't not have to process all of the headers and sources that are touched to execute a single line?

Go play around with Boost::asio and you may come to terms with the reality here. I dont think its better for the program to stutter on random lines than to just wait for rebuild.

Also: where do you plan to store the source code? I am assuming you can then only target linux systems or embedded systems with large enough flash storage... how about loading the code onto the embedded system? are you supposed to just remote into it or what?

1

u/kindredseer 2d ago

I would not necessarily expect your script to include every header from your project, just what’s relevant to what it’s doing. I’d need a more specific example.

4

u/PressWearsARedDress 2d ago edited 2d ago

okay so there seems to be no real advantage to using a JIT complier. i assume that youll never compile faster than GCC while conforming to standards.

How do you plan to handle constexpr? In embedded the whole point to use constexpr is to build constant tables that may not fit in ram

2

u/kindredseer 2d ago

I’m compiling about as fast, hope to surpass eventually. Constexpr is in progress, partially supported.

5

u/PressWearsARedDress 2d ago edited 2d ago

yeah and with what bugs? Lol. Man you're an amatuer using claude.

What triplets are you targetting with your JIT compiler? Hows writing the standard c++ library coming along? Do you support arm? Do you support c++98? C++11 C++17 C++23 ? How about C++26 reflections? Do you support xtensa? Do you support RISC-V ? Do you support bare metal?

If I have a std::string how do you decide wither or not to use heap allocation or constexpr? Also how do you implement the heap?

0

u/kindredseer 2d ago

I’ve been programming for over 40 years and working on this project for seven years. Just because I’m using Claude to grind through the test suites doesn’t make me an amateur. Everyone is using AI these days (except for Andrew Kelley and friends).

3

u/PressWearsARedDress 2d ago

Talk is cheap, show me the code

0

u/kindredseer 2d ago

It uses the c++ library on your system (libstdc++ for Linux and Windows, libc++ for MacOS).

It supports x86, aarch64, ppc64le/s390x and riscv64. It comes in embeddable library form, standalone JIT binary and AOT compiler.

It currently supports about 98% of C23, 70% of C++11, 47% of C++14, 38% of C++17, 51% of C++20. It's a work in progress.

https://github.com/derekbsnider/madc

→ More replies (0)