K : [4]s64 : .[...] and the untyped A :: .[1, 2, 3] register as is_const globals: one storage, reads GEP it, dead-global elimination drops unused ones, source-aware reads come free via selectGlobalAuthor. - registerConstArrayGlobal (scanDecls pass 2): typed via the annotation (array-ness + dimension/count checked), untyped via element-type unification — all ints s64; ANY float promotes the element type to f64 with ints converting exactly; bool/string homogeneous; a non-numeric mix or non-inferable element asks for an annotation. - constExprValue converts int elements into float destinations exactly (the int+float promotion rule, element-wise). - emitGlobals marks is_const globals LLVMSetGlobalConstant — also flips the comptime-backed #run globals and __sx_default_context to 'constant' (37 pinned IR snapshots regenerated; runtime unchanged). - Element shapes: nested arrays, struct elements, strings, bools. Non-constant elements / dim mismatch / mixed types diagnose loudly. Examples: 0177 (feature matrix incl. @K reads through *[4]s64 — needs the 0117 fix), 1159/1160/1161 (diagnostics), 0837 repointed to values.
13 lines
302 B
Plaintext
13 lines
302 B
Plaintext
// An array constant's elements must be compile-time constants — a call
|
|
// (or any runtime expression) in an element slot is diagnosed. `#run`
|
|
// is the tool for computed constants.
|
|
|
|
#import "modules/std.sx";
|
|
|
|
f :: () -> s64 { 7 }
|
|
BAD : [2]s64 : .[1, f()];
|
|
|
|
main :: () {
|
|
print("{}\n", BAD[0]);
|
|
}
|