Here's how it could look:
Me no like. How do you do range checking on
x? And the syntax looks too much like function calls to me. The colon at the end is so easy to confuse with a semicolon. Obfuscated C material, methinks...
Anyway, I have used the labels-as-values for state machines. However, I do prefer a function pointer variant, with each state or transition (depending on how you define your state machine and events) being a separate function call, instead of a single huge switch() or goto/label mess.
For things like command interfaces –– basically name-to-function mappings ––, I like to use ELF section support. (All architectures I use support ELF object files.) Basically, a preprocessor macro is used to generate a
static const structure in a dedicated
section. The linker will collect these at link time from all object files, and concatenate them into a single array, and the start and end addresses are exported by symbols visible to the C code.
Note: This is not a C feature, but a feature provided by C compilers and linkers when they use ELF format object files.
This means that if I write a G-code interpreter, I can use a dedicated section for supported G-codes, and another for M-codes. In the source code, anywhere a new one is defined, it gets declared using something like
DECLARE_G(code, function, "description") or
DECLARE_M(code, function, "description"), and the interpreter will look up each one using the linker-provided section symbols.
This works amazingly well. I can put each feature into a separate source file, and let the builder select the desired set at compile time. The only thing that annoys me is that the linker does not yet know how to sort those entries at link time. I often have a key, here
code (a positive integer), and if the array entries were sorted according to the key, I could use a binary search to find the entry in
O(log N) time. If I want to do that now, I need to do a separate post-link object file modification step. And if I have to do that, I can spend a little more time doing that, and make the array into a hash table with the hash function provided by the post-link step, to find a near-perfect hash function for the data, for
O(L) time lookups, where
L is the maximum collision chain length.
You are focusing way too much on "nice looking" syntax. This is not the most important part. If your code is full of those computed gotos, then you are likely doing something wrong anyway.
And I'm lost again what is being discussed. You throw some random examples of code that you don't want to work.
Yes, it is possible to make a language exactly as you like, but that happens by opening a text editor and typing the code, not forum posts.
You could be contributing to the conversation (instead of trolling) as several other people are
I do not always agree with ataradov, but here, he has a particularly apt point.
The way the code looks is not important. Readability is important, but "target(0):" is less readable than "target_0" because it is so easy to confuse with "target(0);", so you
are demonstrably focusing on the wrong thing, at least in this example.
What is important, is how easy or hard it is to describe an expression or concept in the given language with exactly the desired side effects and no others.
This means that the most important things to achieve with a new low-level language with the intent of replacing C, is to be able to express everything that can be expressed in C already,
and more, or at least
better, to some definition of "better". "Visually more appealing" is not "better", though.