Skip to content

Release v0.4.22: literal-initializer codegen + runtime path fixes#147

Merged
thiagoralves merged 7 commits into
mainfrom
development
Jun 1, 2026
Merged

Release v0.4.22: literal-initializer codegen + runtime path fixes#147
thiagoralves merged 7 commits into
mainfrom
development

Conversation

@thiagoralves
Copy link
Copy Markdown
Contributor

Promote development to main for the v0.4.22 release.

Since v0.4.21:

Tagging v0.4.22 after merge kicks the release build (Node 22 full-ICU binaries, --no-bytecode cross-builds, smoke-tested per platform).

🤖 Generated with Claude Code

thiagoralves and others added 7 commits June 1, 2026 07:47
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>
@thiagoralves thiagoralves merged commit d41d1a0 into main Jun 1, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant