Implement JMZ, JMN, DJN, CMP and SLT in the MARS #2

Open
Claude wants to merge 2 commits from Claude/corewars-test:agent/issue-1 into master
First-time contributor

The simulator in lib/mars.ml only executed DAT, MOV, ADD, SUB, JMP and SPL. Any other opcode hit the "not yet implemented" failure. This adds the remaining ICWS-88 instructions:

  • JMZ / JMN: jump to the A address if the B-field of the B target is zero / non-zero.
  • DJN: decrement the B-field of the B target (mod core size), then jump if the result is non-zero.
  • CMP: skip the next instruction if the operands are equal. An immediate A is compared with the B-field of the B target. Otherwise the whole instructions are compared (opcode, modes and fields).
  • SLT: skip the next instruction if the A value is less than the B target's B-field. An immediate A uses its own value. Otherwise it uses the B-field of the A target.
  • The catch-all case now only covers the EQU and END pseudo-instructions.

Not tested: dune and ocaml aren't installed in this environment, so I couldn't build or run the test suite. I only checked the code by reading it.

I didn't change how DAT kills a warrior: it still ends all of that warrior's processes, not just the one that executed it.

Closes #1

The simulator in `lib/mars.ml` only executed DAT, MOV, ADD, SUB, JMP and SPL. Any other opcode hit the "not yet implemented" failure. This adds the remaining ICWS-88 instructions: - **JMZ / JMN**: jump to the A address if the B-field of the B target is zero / non-zero. - **DJN**: decrement the B-field of the B target (mod core size), then jump if the result is non-zero. - **CMP**: skip the next instruction if the operands are equal. An immediate A is compared with the B-field of the B target. Otherwise the whole instructions are compared (opcode, modes and fields). - **SLT**: skip the next instruction if the A value is less than the B target's B-field. An immediate A uses its own value. Otherwise it uses the B-field of the A target. - The catch-all case now only covers the EQU and END pseudo-instructions. **Not tested:** `dune` and `ocaml` aren't installed in this environment, so I couldn't build or run the test suite. I only checked the code by reading it. I didn't change how DAT kills a warrior: it still ends all of that warrior's processes, not just the one that executed it. Closes #1
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Owner

@Claude try installing ocaml and dune in your enviornment, if possible, then test

@Claude try installing ocaml and dune in your enviornment, if possible, then test
Author
First-time contributor

I installed OCaml 5.2.1 and dune 3.24.2 with opam. The full project doesn't build here, but the tests pass without the SDL window module.

  • Install: tar fails in this sandbox with "Function not implemented" when opam extracts the compiler source. I got past it by putting bsdtar first on PATH as tar. The install is in ~/.opam (switch default), so it stays for later jobs. To use it, run eval $(opam env) and put ~/shim on PATH for any opam install.
  • Full build fails: dune build and dune test stop with Library "sdl3" not found. There is no sdl3 package in the opam repo, so I couldn't install it.
  • Tests pass without the window: I made a scratch copy that leaves out lib/window.ml and the sdl3 dependency, and ran dune test there. All the test cases pass, including Imp, Add, Equ, the precedence tests, Mov, Sub, Jmp, Comments, the invalid-opcode error and the validation program.
  • Not covered: the SDL window and bin/main.ml were not built or run.
  • Repo unchanged: I made no commits.

If you want CI or agent testing to work, sdl3 would need to be pinned or installed some other way, or window split into a separate library from the core.

I installed OCaml 5.2.1 and dune 3.24.2 with opam. The full project doesn't build here, but the tests pass without the SDL window module. - **Install:** `tar` fails in this sandbox with "Function not implemented" when opam extracts the compiler source. I got past it by putting `bsdtar` first on `PATH` as `tar`. The install is in `~/.opam` (switch `default`), so it stays for later jobs. To use it, run `eval $(opam env)` and put `~/shim` on `PATH` for any opam install. - **Full build fails:** `dune build` and `dune test` stop with `Library "sdl3" not found`. There is no `sdl3` package in the opam repo, so I couldn't install it. - **Tests pass without the window:** I made a scratch copy that leaves out `lib/window.ml` and the `sdl3` dependency, and ran `dune test` there. All the test cases pass, including Imp, Add, Equ, the precedence tests, Mov, Sub, Jmp, Comments, the invalid-opcode error and the validation program. - **Not covered:** the SDL window and `bin/main.ml` were not built or run. - **Repo unchanged:** I made no commits. If you want CI or agent testing to work, `sdl3` would need to be pinned or installed some other way, or `window` split into a separate library from the core.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u agent/issue-1:Claude-agent/issue-1
git switch Claude-agent/issue-1

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch master
git merge --no-ff Claude-agent/issue-1
git switch Claude-agent/issue-1
git rebase master
git switch master
git merge --ff-only Claude-agent/issue-1
git switch Claude-agent/issue-1
git rebase master
git switch master
git merge --no-ff Claude-agent/issue-1
git switch master
git merge --squash Claude-agent/issue-1
git switch master
git merge --ff-only Claude-agent/issue-1
git switch master
git merge Claude-agent/issue-1
git push origin master
Sign in to join this conversation.
No reviewers
No labels
agent
claude
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Levitating/corewars-test!2
No description provided.