Skip to content

core: Preserve endian qualifiers on template arguments - #259

Open
AkiSakurai wants to merge 2 commits into
WerWolv:masterfrom
AkiSakurai:endian_template_arguments
Open

AkiSakurai wants to merge 2 commits into
WerWolv:masterfrom
AkiSakurai:endian_template_arguments

Conversation

@AkiSakurai

Copy link
Copy Markdown
Contributor

Copy m_endian, m_reference, and m_templateParameterIndex when evaluating or cloning ASTNodeTypeApplication so be/le on template arguments survives nested binding.

Example (test_data starts with PNG signature 89 50 4E 47):

struct Box<T> { T v; };
Box<be u32> b @ 0;

Before: b.v read as 0x474E5089 (le) — 'be' dropped during evaluate()
After: b.v read as 0x89504E47 (be) — template argument endian preserved

Adds TemplateEndian test.

AkiSakurai and others added 2 commits September 24, 2026 23:22
Copy m_endian, m_reference, and m_templateParameterIndex when evaluating or cloning ASTNodeTypeApplication so be/le on template arguments survives nested binding.

Example (test_data starts with PNG signature 89 50 4E 47):

    struct Box<T> { T v; };
    Box<be u32> b @ 0;

Before: b.v read as 0x474E5089 (le) — 'be' dropped during evaluate()
After:  b.v read as 0x89504E47 (be) — template argument endian preserved

Adds TemplateEndian test.

Co-authored-by: opencode <opencode@opencode.ai>
setEndian() refuses to pin patterns in the heap, pattern-local, and
instantiation sections, but getEndian() still fell back to the ambient
default for them. An unset endian therefore answered whatever the
evaluator's current default happened to be, so a value written under
one default could be read back under another: a template parameter
initialized inside a 'be' instantiation but used after the scope
restored the little-endian default, or a heap variable read while a
'be' instantiation was being created.

Example (test_data starts with PNG signature 89 50 4E 47):

    struct Test<auto t> { u32 a = t; };
    be Test<5> test;

Before: test.t printed 6646139978924579364519035301401722880 (5 << 120)
After:  test.t prints 5 — unpinned non-file patterns now round-trip
        with native endian regardless of ambient default changes

    auto g = 16909060;
    struct Q<auto t> { u32 a = g; };
    be Q<5> q;

Before: q.a printed 0 (g's little-endian bytes decoded as big endian)
After:  q.a prints 16909060

Extends the TemplateEndian test with non-type template parameters under
be/le (placed and local) and a heap variable read under 'be'.

fix: WerWolv#119

Co-authored-by: opencode <opencode@opencode.ai>
@AkiSakurai

Copy link
Copy Markdown
Contributor Author

I found a regression that causes issue #119, so I added a commit to fix it.

This branch has not been deployed

No deployments
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