FFFF Refactor AST→value conversion onto one converter with two sinks · Issue #133 · kexhq/kex · GitHub
[go: up one dir, main page]

Skip to content

Refactor AST→value conversion onto one converter with two sinks #133

Closed

Description

@akoskovacs

Part of #131. Blocked by #132.

src/interpreter/stdlib/parser.cxx (~950 lines) walks the C++ AST and builds interpreter ValuePtrs directly — Value::variant("Call", "Parser.Expression", {...}) and friends. To reach BEAM (#134) the same tree has to be produced as an Erlang term, and the fidelity work (#135) has to extend both.

Written as two independent walkers, they drift: an Expr variant added to one is silently missing from the other, and the failure shows up as a Kex program that behaves differently under -R than under the interpreter.

What lands

  • The convert* functions are restated against a builder interface — roughly variant(tag, parent, args), record(name, fields), list, string, integer, floating, atom, none, just — with the AST walk written once against it.
  • ValueBuilder produces ValuePtr, reproducing today's output exactly.
  • TermBuilder produces kex::beam::Term (src/beam/etf.hxx).
  • Term gains the arms it lacks: a Float arm (NEW_FLOAT_EXT, tag 70) and bignum encoding (tags 110/111) for integers outside int64_t. It currently has only Int, because a KexI chunk never needed more.

Why it is separate

It ends with zero user-visible change — tools/docgen/docgen.kex must produce byte-identical output before and after. That makes it cheap to review and cheap to revert, and it is the single change that makes every later stage cost one implementation instead of two.

Verification

  • make test-all.
  • Docgen output diffed before/after across the prelude — must be identical.
  • Unit tests for the new Term arms: a float round-trips through encodeEtf/decodeEtf, and an integer beyond int64_t range round-trips as a bignum.

Activity

  1. added a commit that references this issue on Aug 21, 2026
    e5338ad
  2. added this to the 0.4.0 milestone on Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0