Language: accept untyped global constant definitions - #547
Conversation
chqrlie
commented
Jul 25, 2026
- type is inferred from init value
- cannot take the address of an untyped global constant
- add tests
- need bootstrap to use in the compiler or libraries
94620a4 to
39b7c01
Compare
|
I'm playing around with this. I think we can tighten some checks: Maybe we can also enforce local const to be Capital cased (perhaps only for untypes at first? to make it easier) Code-wise there seems to be some duplication between analyseGlobalVarDecl and analyseDecl, maybe we can refactor that into a common function? The error messages contain 'untyped global constant'. I think this tshould be 'untyped constant' since it should also apply to local constants. |
39b7c01 to
bec19b1
Compare
Forbidding pointer arithmetics would be consistent with the rejection of the
I would not do that, local variables are not global constants, defining them as There is a fundamental semantical difference between global constants that name concepts that are given for the whole program or system interface and
Yes, I shall look into that, but for a separate PR
Indeed, it should not mention |
2af17be to
7931fd7
Compare
* type is inferred from init value
* accept `const` blocks: `const { ONE = 1, TWO = 2 }`
* cannot take the address of an untyped global constant
* add tests
* need bootstrap to use in the compiler or libraries
7931fd7 to
7e7dc34
Compare
|
merged! |
|
I had to revert this on Main, since it broke on attributes.. const u32 Max @(unused) = 10; //ok I tried fixing it in c2_parser.c2 Parser.parseSingleTypeSpecifier() by changing also checking if next token is an At, but that broke a lot of stuff.. When I debugging I was looking at the const blocks again and I dont really like the added syntax complexity. It is different than the rest. Multiple simple lines are just clearer I think. |
I think both of the above are wrong. Restricting the attributes to occur only before Another direction is the new With this new syntax, we could have equivalently: or I do not particularly like this new stuff inherited from C++, like most of the C++ syntax indeed. My preference would be: or and or and in combination or |