Skip to content

Commit 603208a

Browse files
committed
fix: address feedback
1 parent 5e0b519 commit 603208a

2 files changed

Lines changed: 38 additions & 8 deletions

File tree

src/utils/memory-parser.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,6 +1288,34 @@ describe("Util: memory-parser", () => {
12881288
hits: "",
12891289
},
12901290
],
1291+
[
1292+
"-100=5",
1293+
{
1294+
flag: "",
1295+
lType: "v",
1296+
lSize: "",
1297+
lMemory: "0x00-100",
1298+
cmp: "=",
1299+
rType: "v",
1300+
rSize: "",
1301+
rMemVal: "0x000005",
1302+
hits: "0",
1303+
},
1304+
],
1305+
[
1306+
"0xH1234=-100",
1307+
{
1308+
flag: "",
1309+
lType: "m",
1310+
lSize: "0xh",
1311+
lMemory: "0x001234",
1312+
cmp: "=",
1313+
rType: "v",
1314+
rSize: "",
1315+
rMemVal: "-100",
1316+
hits: "0",
1317+
},
1318+
],
12911319
[
12921320
"K:{recall}+-100",
12931321
{

src/utils/memory-parser.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ function formatAddress(
9797
value: string,
9898
specials: readonly string[],
9999
hadSizePrefix: boolean,
100-
skipNegative: boolean,
100+
// Main path: preserve the original negative decimal instead of converting to hex.
101+
keepNegativeDecimal: boolean,
102+
// Main path right operand only: leave a leading "-" alone instead of padding it.
103+
skipNegativePad: boolean,
101104
): string {
102105
if (!value) return value;
103106

@@ -108,8 +111,7 @@ function formatAddress(
108111
!value.startsWith("0x")
109112
) {
110113
const num = parseInt(value, 10);
111-
// Main path refuses to reformat negatives; recall/variable convert and pad through the sign.
112-
if (!Number.isNaN(num) && (num >= 0 || !skipNegative)) {
114+
if (!Number.isNaN(num) && (num >= 0 || !keepNegativeDecimal)) {
113115
value = num.toString(16);
114116
}
115117
}
@@ -121,7 +123,7 @@ function formatAddress(
121123
if (specials.includes(value) || value.includes(".")) {
122124
return value;
123125
}
124-
if (skipNegative && value.startsWith("-")) {
126+
if (skipNegativePad && value.startsWith("-")) {
125127
return value;
126128
}
127129

@@ -201,7 +203,7 @@ function parseRecallOperand(operand: string): {
201203
type = size !== "" ? "m" : "v";
202204
}
203205

204-
value = formatAddress(value, RECALL_SPECIAL_CONSTANTS, size !== "", false);
206+
value = formatAddress(value, RECALL_SPECIAL_CONSTANTS, size !== "", false, false);
205207

206208
return { type: type as MemType, size, value };
207209
}
@@ -298,7 +300,7 @@ function parseVariableRightOperand(operand: string): {
298300
}
299301

300302
if (!value.includes(".")) {
301-
value = formatAddress(value, RECALL_SPECIAL_CONSTANTS, size !== "", false);
303+
value = formatAddress(value, RECALL_SPECIAL_CONSTANTS, size !== "", false, false);
302304
}
303305

304306
return { type: type as MemType, size: size as MemSize, value };
@@ -446,8 +448,8 @@ function parseRequirement(req: string): ParsedRequirement | null {
446448
lMemory = lMemory.substring(1);
447449
}
448450

449-
lMemory = formatAddress(lMemory, MAIN_SPECIAL_CONSTANTS, lSize !== "", false);
450-
rMemVal = formatAddress(rMemVal, MAIN_SPECIAL_CONSTANTS, rSize !== "", true);
451+
lMemory = formatAddress(lMemory, MAIN_SPECIAL_CONSTANTS, lSize !== "", true, false);
452+
rMemVal = formatAddress(rMemVal, MAIN_SPECIAL_CONSTANTS, rSize !== "", true, true);
451453

452454
const isKnownLType = ["d", "p", "b", "v", "~", "f", "recall"].includes(lType);
453455
if (!isKnownLType) {

0 commit comments

Comments
 (0)