Skip to content

feat(translate): implement +LOOP word for strided DO loops#28

Merged
tetsuo-cpp merged 3 commits intocanonfrom
feat/plus-loop
Feb 19, 2026
Merged

feat(translate): implement +LOOP word for strided DO loops#28
tetsuo-cpp merged 3 commits intocanonfrom
feat/plus-loop

Conversation

@tetsuo-cpp
Copy link
Owner

Summary

  • Extract common loop-end logic into emitLoopEnd helper
  • Refactor LOOP to use the new helper
  • Add +LOOP which pops an arbitrary step from the data stack

Test plan

  • Translation test: plus-loop.forth
  • Error test: plus-loop-without-do-error.forth
  • Pipeline test: plus-loop.forth
  • All 57 tests pass

Closes #25

Copy link
Owner Author

@tetsuo-cpp tetsuo-cpp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

Clean, well-structured PR. The emitLoopEnd extraction is a natural refactoring that eliminates duplication without over-abstracting. The +LOOP implementation is minimal and easy to follow.

Tests

Thorough coverage — translation IR check, error case, and full pipeline test.

Two items to consider

  1. Negative step values: Standard Forth +LOOP uses a direction-sensitive termination check — positive step terminates when index >= limit, negative step terminates when index < limit. The current implementation always uses slt, so negative step values will produce an infinite loop. Worth documenting the limitation or addressing it.

  2. CLAUDE.md: The supported words list says DO LOOP I J K but doesn't mention +LOOP.

@tetsuo-cpp tetsuo-cpp merged commit 68af901 into canon Feb 19, 2026
1 check passed
@tetsuo-cpp tetsuo-cpp deleted the feat/plus-loop branch February 19, 2026 09:07
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.

feat: implement +LOOP word

1 participant

Comments