From 4779cdea417fbae3df0ef7dda774c67cd0173697 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Tue, 3 Nov 2026 12:22:03 +0100 Subject: [PATCH] urust: fixed Step Over --- CHANGELOG.md | 2 ++ src/common/projectcore.ts | 26 ++++++++++++++++++++++++++ src/ide/ui.ts | 13 ++----------- test/unit/teststeplines.ts | 12 ++++++++++++ 4 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 test/unit/teststeplines.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 80c671ec..9e0946f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ See [extension/CHANGELOG.md](extension/CHANGELOG.md). ### Builds and tools +- The IDE's Step Over button on urust programs ran one instruction at a time. urust's debug info has one entry per expression, so every instruction counted as a line start; step over now stops only where the source line changes. + - Git hooks in `.githooks/` run the type check before a commit (`npm run tslint`) and the test suite before a push (`npm test`). They print one line while working and only show output on failure, which aborts the commit/push. `make prepare`/`npm run hooks` installs them by pointing `core.hooksPath` at `.githooks`; bypass with `--no-verify`, `SKIP_PRECOMMIT=1`, or `SKIP_PREPUSH=1`. Tag-only and branch-deletion pushes don't run the tests. - **CVBasic** builds BASIC programs for the Colecovision, MSX, SG-1000/SMS and NES. The WASI compiler turns `.bas` into gasm80 assembler, which the newly vendored gasm80 (also WASI) assembles into a cartridge ROM. Compiler and assembler diagnostics point at BASIC lines, and the gasm80 listing gives the debugger source line/address information. Colecovision, MSX, NES and SG-1000/SMS now send `.bas` to it, with presets, skeletons and a `cvbasic-fs.zip` package of its prologue/epilogue files. diff --git a/src/common/projectcore.ts b/src/common/projectcore.ts index d2ee187f..d37810f5 100644 --- a/src/common/projectcore.ts +++ b/src/common/projectcore.ts @@ -242,3 +242,29 @@ export function mergeSegments(nativeSegs: Segment[], linkerSegs: Segment[]): Seg segs.sort((a, b) => a.start - b.start); return segs; } + +/** + * The set of PCs that begin a source line, for source-level step over. + * Compilers like urust emit one entry per expression, so one source line can + * have many entries at consecutive addresses. Only the first entry of each run + * (in address order) on the same file+line counts, or step over would stop + * after nearly every instruction. + */ +export function sourceLineStartPCs(listings: CodeListingMap): Set { + var entries: SourceLine[] = []; + for (var lstfn in listings || {}) { + var sourcefile = listings[lstfn].sourcefile; + if (!sourcefile) continue; + for (var line of sourcefile.lines) { + if (line.offset >= 0) entries.push(line); + } + } + entries.sort((a, b) => a.offset - b.offset); + var pcs = new Set(); + var prev: SourceLine = null; + for (var e of entries) { + if (!prev || prev.line != e.line || prev.path != e.path) pcs.add(e.offset); + prev = e; + } + return pcs; +} diff --git a/src/ide/ui.ts b/src/ide/ui.ts index c0881449..42c44d09 100644 --- a/src/ide/ui.ts +++ b/src/ide/ui.ts @@ -18,6 +18,7 @@ import { getAppVersionLabel } from "../common/version"; import { PLATFORM_PARAMS } from "../worker/platforms"; import { hasErrors } from "../worker/listingutils"; import { CodeListingMap, FileData, WorkerError, WorkerResult, isErrorResult } from "../common/workertypes"; +import { sourceLineStartPCs } from "../common/projectcore"; import { reportErrorToServer, reportInternalError } from "./errorreport"; import { importPlatform } from "../platform/_index"; import { alertError, alertInfo, fatalError, setWaitDialog } from "./dialogs"; @@ -1544,17 +1545,7 @@ var sourcePcsCache: { listings: CodeListingMap, pcs: Set } = null; function getSourceLineStartPCs(): Set { var listings = current_project.getListings(); if (!sourcePcsCache || sourcePcsCache.listings !== listings) { - var pcs = new Set(); - if (listings) { - for (var lstfn in listings) { - var sourcefile = listings[lstfn].sourcefile; - if (!sourcefile) continue; - for (var line of sourcefile.lines) { - if (line.offset >= 0) pcs.add(line.offset); - } - } - } - sourcePcsCache = { listings: listings, pcs: pcs }; + sourcePcsCache = { listings: listings, pcs: sourceLineStartPCs(listings) }; } return sourcePcsCache.pcs; } diff --git a/test/unit/teststeplines.ts b/test/unit/teststeplines.ts new file mode 100644 index 00000000..a468e731 --- /dev/null +++ b/test/unit/teststeplines.ts @@ -0,0 +1,12 @@ +import assert from "assert"; +import { describe, it } from "mocha"; +import { processListings, sourceLineStartPCs } from "../../src/common/projectcore"; + +describe('sourceLineStartPCs', function () { + it('keeps one start PC per run of entries on the same line (urust emits one per expression)', function () { + const mk = (line: number, offset: number) => ({ line, offset, path: 'a.rs', iscode: true }); + const listings: any = { 'a.rs': { lines: [mk(1, 0x800), mk(1, 0x803), mk(1, 0x806), mk(2, 0x809), mk(2, 0x80b), mk(1, 0x80d)] } }; + processListings(listings); + assert.deepStrictEqual([...sourceLineStartPCs(listings)].sort(), [0x800, 0x809, 0x80d]); + }); +});