Conversation
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
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.
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:
INSTRarray 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.SECTION,TYPE,DEFTYPE, andKIND, separating concerns and improving readability.Project management updates:
todo.mdto 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.