←back to thread

Jank is C++

(jank-lang.org)
281 points Jeaye | 1 comments | | HN request time: 0.208s | source
Show context
johnnyjeans ◴[] No.44535498[source]
I'm not surprised to see that Jank's solution to this is to embed LLVM into their runtime. I really wish there was a better way to do this.

There are a lot of things I don't like about C++, and close to the top of the list is the lack of standardization for name-mangling, or even a way mangle or de-mangle names at compile-time. Sepples is a royal pain in the ass to target for a dynamic FFI because of that. It would be really nice to have some way to get symbol names and calling semantics as constexpr const char* and not have to deal with generating (or writing) a ton of boilerplate and extern "C" blocks.

It's absolutely possible, but it's not low-hanging fruit so the standards committee will never put it in. Just like they'll never add a standardized equivalent for alloca/VLAs. We're not allowed to have basic, useful things. Only more ways to abuse type deduction. Will C++26 finally give us constexpr dynamic allocations? Will compilers ever actually implement one of the three (3) compile-time reflection standards? Stay tuned to find out!

replies(9): >>44535506 #>>44535588 #>>44535621 #>>44535873 #>>44535967 #>>44536143 #>>44539903 #>>44540443 #>>44542272 #
benreesman ◴[] No.44535588[source]
Carmack did very much almost exactly the same with the Trinity / Quake3 Engine: IIRC it was LCC, maybe tcc, one of the C compilers you can actually understand totally as an individual.

He compiled C with some builtins for syscalls, and then translated that to his own stack machine. But, he also had a target for native DLLs, so same safe syscall interface, but they can segv so you have to trust them.

Crazy to think that in one computer program (that still reads better than high-concept FAANG C++ from elite lehends, truly unique) this wasn't even the most dramatic innovation. It was the third* most dramatic revolution in one program.

If you're into this stuff, call in sick and read the plan files all day. Gives me googebumps.

replies(3): >>44535907 #>>44536648 #>>44537532 #
MangoToupe ◴[] No.44537532[source]
Linking directly to C++ is truly hell just considering symbol mangling. The syntax <-> semantics relationship is ghastly. I haven't seen a single project tackle the C++ interface in its entirety (outside of clang). It nearly seems impossible.

There's a reason Carmack tackled the C abi and not whatever the C++ equivalent is.

replies(2): >>44537593 #>>44537798 #
PaulDavisThe1st ◴[] No.44537593[source]
There is no C ABI (windows compilers do things quite differently from linux ones, etc) and there is no certainly no C++ equivalent.
replies(4): >>44537647 #>>44537663 #>>44539049 #>>44539973 #
caim ◴[] No.44537663[source]
C ABI is the system V abi for Unix, since C was literally created for it. And that is the abi followed by pretty much any Unix successor: Linux, Apple's OS, FreeBSD.

Windows has its own ABI.

The different abi is pretty much legacy and the fact that x86_64 ABI was built by AMD + Linux etc, while Microsoft worked with Intel for the Itanium abi.

replies(1): >>44541880 #
Someone ◴[] No.44541880[source]
> And that is the abi followed by pretty much any Unix successor: Linux, Apple's OS, FreeBSD.

Even limiting that to “on x64”, I don’t see how that’s true. To make a syscall, the ABI on Linux says “make the call”, while MacOS (and all the BSDs, I think) says “call the provided library function”.

Also (https://developer.apple.com/documentation/xcode/writing-64-b...): “Apple platforms typically follow the data representation and procedure call rules in the standard System V psABI for AMD64, using the LP64 programming model. However, when those rules are in conflict with the longstanding behavior of the Apple LLVM compiler (Clang) on Apple platforms, then the ABI typically diverges from the standard Processor Specific Application Binary Interface (psABI) and instead follows longstanding behavior”

Some of the exceptions mentioned there are:

- Asynchronous Swift functions receive the address of their async frame in r14. r14 is no longer a callee-saved register for such calls.

- Integer arguments that are smaller than int are required to be promoted to int by the caller, and the callee may assume that this has been done. (This includes enumerations whose underlying type is smaller than int.) For example, if the caller passes a signed short argument in a register, the low 32 bits of the register at the moment of call must represent a value between -32,768 and 32,767 (inclusive). Similar, if the caller passes an unsigned char argument in a register, the low 32 bits of the register at the moment of call must represent a value between 0 and 255 (inclusive). This rule also applies to return values and arguments passed on the stack.

replies(1): >>44543194 #
1. caim ◴[] No.44543194[source]
Swift has its own ABI and calling convention, so that makes sense that Apple adapted to it.

The system v abi doesn't say anything about syscall.

Windows x86_64 abi is the same abi for x86, for this reason, you can only pass arguments in 4 registers ( while unix uses 6 ) because x86 only had 8 registers.

I think people have expectations that are misaligned with history and reality about this, to be honest. We can't expect all OS to do things in the same way.

C was created to rewrite the UNIX system, and POSIX compliance is followed by all successors, with minimal differences.

When it became clear that "Itanium" was a failure, Microsoft couldn't just pull an ABI out of the box and break all applications, so they just reused the same x86 ABI.