Release v0.4.22: literal-initializer codegen + runtime path fixes#147
Merged
Conversation
Hex/based literals in a VAR initial value were copied verbatim into the
C++ constructor initializer list (`X(16#FF)`), producing invalid C++
("stray '#' in program"). The expression-statement path lowers the same
literals correctly; the declaration-initializer path did not.
Root cause: PROGRAM/GLOBAL VAR initialisers reach codegen as raw IEC
strings (project-model.expressionToString → rawValue), and
getDefaultValue never lowered numeric strings. expressionToString also
dropped unary expressions entirely, so a signed literal like `-5`
silently became the type default (0).
Checked every literal form in the initializer position and fixed them
together:
- based integers/bitstrings: 16#FF→0xFF, 8#17→017, 2#1010→0b1010
- IEC underscore separators stripped: 16#FF_FF→0xFFFF, 1_000→1000
- typed-literal prefixes stripped: INT#5→5, INT#16#10→0x10,
BYTE#16#AB→0xAB, REAL#1.5→1.5
- signed literals preserved: -5, +3 (previously lost to 0)
- decimals/reals/bool/string unchanged; non-numeric initialisers
(enum names, named constants) pass through untouched
New getDefaultValue helper lowerNumericInitializer reuses the existing
iecBaseToCppLiteral so declaration initialisers and statement bodies
lower identically. FB initialisers already routed through the
expression path and were unaffected; struct fields emit valid decimal.
Adds tests/backend/codegen-var-initializers.test.ts covering all forms,
including the VAR_GLOBAL path.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Verified that based literals, IEC underscore separators, typed-literal prefixes, signs (incl. -16#FF), and reals already lower correctly on the statement-body path (assignment RHS, conditions, arithmetic, array indices) — no code change needed there; the #133 bug was confined to the declaration-initializer path. These tests lock that in so the two paths can't drift. (BOOL#TRUE/BOOL#FALSE is non-lexable and non-standard; typed bool uses BOOL#1/BOOL#0.) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…iteral-lowering fix(codegen): lower IEC numeric literals in VAR initializers (#133)
`--build`/`--test` aborted with "Could not locate runtime include directory" on a global/npm install, even though the headers ship in the package. The package places the runtime at <pkg>/src/runtime/include but the CLI runs from <pkg>/dist/node, so reaching it needs two levels up (../../src/runtime/include). findRuntimeIncludeDir only climbed one (../src/runtime/include → <pkg>/dist/src, absent), so auto-discovery landed one directory short. It only worked when run from the project root, where the cwd-relative candidate happened to hit — which is never the case on a global install (cwd is the user's project). Add the two-level package-relative candidate to both the import.meta and __dirname blocks, mirroring the libs locator just below (which already uses ../../libs). Verified end-to-end: `--build` from a foreign cwd now locates the headers and produces a working binary. Strengthen the previously-lenient build-utils test (it mocked cwd to /tmp but only asserted "doesn't throw") into a real #134 regression that requires the package-relative lookup to resolve src/runtime/include, plus a -I cxx-flags fallback case. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
fix(cli): locate runtime include dir on npm install (#134)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
chore(release): v0.4.22
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Promote development to main for the v0.4.22 release.
Since v0.4.21:
fix(codegen): lower IEC numeric literals in VAR initializers (based16#FF/8#17/2#1010, underscores, typed prefixesINT#5/BYTE#16#AB, signed-5); previously emitted verbatim → invalid C++. Plus statement-body literal regression tests.fix(cli): auto-locate the runtime include dir on npm/global installs so--build/--testwork without manual--cxx-flags.Tagging
v0.4.22after merge kicks the release build (Node 22 full-ICU binaries,--no-bytecodecross-builds, smoke-tested per platform).🤖 Generated with Claude Code