Skip to content

Mnemonic#7

Merged
dy merged 21 commits into
mainfrom
mnemonic
Jan 8, 2026
Merged

Mnemonic#7
dy merged 21 commits into
mainfrom
mnemonic

Conversation

@dy

@dy dy commented Jan 8, 2026

Copy link
Copy Markdown
Owner

Mnemonic approach makes code more maintainable and clean, keeping perf benefits
This pull request refactors and significantly expands the WebAssembly instruction and type constants in src/const.js, providing much more detailed metadata for each instruction, and reorganizes the type and section codes for clarity and maintainability. Additionally, it updates the project TODOs to reflect recent progress.

Major improvements to WebAssembly constants:

  • Expanded the INSTR array to include detailed instruction formats, immediate types, and value types, with explicit grouping and comments for each opcode range. Nested arrays are now used for multi-byte opcodes (e.g., SIMD and GC instructions), and immediates are specified for each instruction.
  • Refactored and clarified type, section, and kind code exports: introduced new explicit exports for SECTION, TYPE, DEFTYPE, and KIND, separating concerns and improving readability.
  • Improved documentation in the code with detailed comments explaining the format and purpose of each constant, and clarified the mapping between type codes and their WebAssembly meanings.

Project management updates:

  • Updated todo.md to mark the splitting of strings into Unicode/binary parts and the mnemonic algorithm as completed, reflecting recent progress.

These changes make the codebase much clearer, more maintainable, and easier to extend for future WebAssembly features.

dy added 21 commits January 7, 2026 08:01
Replaced ~44 lines of if/else chains with 17-line dispatcher.
Immediate types now driven by INSTR.imm annotations.
Handles: localidx, globalidx, funcidx, typeidx, tableidx,
labelidx, dataidx, elemidx, laneidx, i32, i64, f32, f64
Remove unnecessary flattening in plain() - instr() already processes
nested arrays in correct stack order. Much simpler than full flattening.
- Move INSTR initialization to const.js for shared use
- Create transform(nodes, ctx, { form, resolve }) API
- Implement flatten() for nested → flat stack order
- nest() and resolveNames() are stubs for now
- Add isInstruction() helper to properly check instruction names
- Implement stack-based nesting with arity detection
- Support basic control flow (block, loop, if, else, end)
- Round-trip flatten↔nest works correctly
@dy dy merged commit cbbb18b into main Jan 8, 2026
1 check passed
@dy dy deleted the mnemonic branch January 8, 2026 00:38
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