feat(vm): add the kernel natives Machine.loadAt and Machine.storeAt #221
Loading…
Reference in a new issue
No description provided.
Delete branch "loop/163-vm-address-arithmetic"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Part 1 of 2 of #163 (the VM loop's address arithmetic without overflow checks), the option the owner decision chose: kernel natives
Machine.loadAt/Machine.storeAtinstd/machine.What
std/machine:loadAt(base, index): Int64andstoreAt(base, index, value), the wordindexwords afterbase. Internal to the kernel ("not for programs"), likeload/store.runtime/include/torb.h: bothstatic inline, the addressbase + 8 * indexcomputed in wrapping unsigned arithmetic, so a call is one load or store with a scaled addressing mode and no overflow check.backend/c/natives.trb) rows, and the generatedtorb_natives.handmachine_natives.c(two new thunks; the thunks after them renumbered, astorb natives --headerwrites them).runtime/tests/machine_test.c: the arithmetic, a negative index included (the loop reads a frame's return record below its first word).docs/design/VM.mdsections 6 and 10: eight kernel natives, and the plan for the step.Why only the natives
A new native is the two commits of CLAUDE.md "Seed and breaking changes" / CONTRIBUTING "Two commits for a breaking change": the published seed has no manifest row for
Machine.loadAt, so a tree whose interpreter calls it cannot bootstrap in CI (the lowering reports the call as unsupported). This PR is the first commit: it adds the natives without using them. It changes nothing a program can observe, and nothing in the loop yet, so it has no performance effect of its own.CI
91c009ff: green, including bootstrap (linux-x64), tier A, tier B (linux-x64) and gates. Cross-compile and other-host bootstrap jobs are skipped for a PR, as usual.machine_test.c), all passing. An earlier run on the same change (before the rebase onto main) was red only intest_io_a_cancelled_wait_releases_its_registration, which is the intermittent #218 and unrelated to this change.fibonacci(30)before/after numbers (method of VM.md section 8) come with part 2.After the merge (Torben)
seedworkflow (Actions -> seed -> Run workflow) on the merged commit, or let the nightly publish the seed of main, so the published seed knowsMachine.loadAt/Machine.storeAt.compiler/src/vm/interpret.trbmovesMachine.load(frame + 8 * x)/Machine.store(frame + 8 * x, v)(registers, code, pool, header words ofexecuteLoop) ontoloadAt/storeAt, with thefibonacci(30)before/after numbers. #163 stays open until then.Refs #163
db7162c4e92e99baf34eCI red on
2e99baf:ci / tier B (linux-x64)failed after 10m23s (run 382, job 6), andci / gatesfailed with it (it needs tier B). Cause not seen: the job log is not readable with the reviewer token. All other checks of this head are green, including bootstrap, tier A and pdisc. Diff read so far shows no defect, so this is a red-CI wait, not a review round: please check the tier B log and re-run or fix; the review runs again once CI has finished.2e99baf34e91c009fff0Tier A/B red on
2e99bafwas not caused by this change: the failing assertion (probeCount == 43in the real-code lowering tests) belongs to the old base, and this PR touches no compiler test. I rebased onto current main (b4164160) and force-pushed91c009ff; the pull request touches only the natives, runtime, std/machine and VM.md. Runs 427/428 are queued on the new head. Review re-requested; it will run once CI has finished.Approved at
91c009f. Checklist:runtime/tests/machine_test.ccovers positive and negative index and store/load round trip, registered inharness.candbuild.sh. Combined CI status is success on this head (tier A/B, bootstrap, gates, pdisc).base + 8u * indexis computed inuint64_t, so it wraps without UB. The result goes through the existingtorb_machine_load/store. The manifest rows,torb_natives.hand the regenerated thunks inmachine_natives.care consistent, and CI checks the generated files against the manifest.std/machinestays internal and the pitfalls are documented.std/machinedoc comments are updated; the "eight natives" count is right.Non-blocking: none.