Skip to content

Commit ecbb7b2

Browse files
hyperpolymathclaude
andcommitted
refactor: complete Js.* API migration across vm, lib, and companions (47 files)
The previous migration (commits bce352c..ac744e2) scoped to src/ only, missing vm/lib/ocaml/ (actual VM source), lib/bs/, lib/ocaml/, and src/app/companions/Moletaire.res. This completes the migration: - Js.Dict → Dict (empty→make, keys→keysToArray, entries→toArray, t→dict) - Js.Console.log/warn/error → Console equivalents - Js.log/log2/log3 → Console.log/log2/log3 - Js.String2 → String (toLowerCase, toUpperCase, includes, split, etc.) - Js.Json → JSON (parseExn, stringify, classify→Classify.classify) - Js.Json encode → JSON.Encode (string, float, bool, array, object) - JSON classify patterns: JSONNumber→Number, JSONString→String, etc. - Js.Float → Float, Js.Int → Int - Rewrite State.res deserializeState for JSON.Classify.classify API shape Verified: 0 Js.* calls remain across all 542 tracked .res files. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6a35033 commit ecbb7b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+635
-630
lines changed

lib/bs/src/app/companions/Moletaire.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ let catchByDog = (mole: t): unit => {
517517
// tiny eyes, optional equipment indicators.
518518

519519
// Console log mole pos for debug
520-
// let _ = Js.log3("Mole pos:", mole.x, mole.depth)
520+
// let _ = Console.log3("Mole pos:", mole.x, mole.depth)
521521
let renderMole = (mole: t): unit => {
522522
let _ = Graphics.clear(mole.bodyGraphic)
523523
let _ = Graphics.clear(mole.indicatorGraphic)

lib/ocaml/Moletaire.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ let catchByDog = (mole: t): unit => {
517517
// tiny eyes, optional equipment indicators.
518518

519519
// Console log mole pos for debug
520-
// let _ = Js.log3("Mole pos:", mole.x, mole.depth)
520+
// let _ = Console.log3("Mole pos:", mole.x, mole.depth)
521521
let renderMole = (mole: t): unit => {
522522
let _ = Graphics.clear(mole.bodyGraphic)
523523
let _ = Graphics.clear(mole.indicatorGraphic)

src/app/companions/Moletaire.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ let catchByDog = (mole: t): unit => {
517517
// tiny eyes, optional equipment indicators.
518518

519519
// Console log mole pos for debug
520-
// let _ = Js.log3("Mole pos:", mole.x, mole.depth)
520+
// let _ = Console.log3("Mole pos:", mole.x, mole.depth)
521521
let renderMole = (mole: t): unit => {
522522
let _ = Graphics.clear(mole.bodyGraphic)
523523
let _ = Graphics.clear(mole.indicatorGraphic)

vm/lib/ocaml/Add.res

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ let make = (a: string, b: string): Instruction.t => {
55
instructionType: "ADD",
66
args: [a, b],
77
execute: state => {
8-
let valA = Js.Dict.get(state, a)->Belt.Option.getWithDefault(0)
9-
let valB = Js.Dict.get(state, b)->Belt.Option.getWithDefault(0)
10-
Js.Dict.set(state, a, valA + valB)
8+
let valA = Dict.get(state, a)->Belt.Option.getWithDefault(0)
9+
let valB = Dict.get(state, b)->Belt.Option.getWithDefault(0)
10+
Dict.set(state, a, valA + valB)
1111
},
1212
invert: state => {
13-
let valA = Js.Dict.get(state, a)->Belt.Option.getWithDefault(0)
14-
let valB = Js.Dict.get(state, b)->Belt.Option.getWithDefault(0)
15-
Js.Dict.set(state, a, valA - valB)
13+
let valA = Dict.get(state, a)->Belt.Option.getWithDefault(0)
14+
let valB = Dict.get(state, b)->Belt.Option.getWithDefault(0)
15+
Dict.set(state, a, valA - valB)
1616
},
1717
}

vm/lib/ocaml/And.res

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ let make = (varA: string, varB: string, varC: string): Instruction.t => {
88
instructionType: "AND",
99
args: [varA, varB, varC],
1010
execute: state => {
11-
let valA = Js.Dict.get(state, varA)->Belt.Option.getWithDefault(0)
12-
let valB = Js.Dict.get(state, varB)->Belt.Option.getWithDefault(0)
11+
let valA = Dict.get(state, varA)->Belt.Option.getWithDefault(0)
12+
let valB = Dict.get(state, varB)->Belt.Option.getWithDefault(0)
1313
// Bitwise AND: c = a & b
1414
let result = land(valA, valB)
15-
Js.Dict.set(state, varC, result)
15+
Dict.set(state, varC, result)
1616
},
1717
invert: state => {
1818
// Inverse: clear the ancilla (set c to 0)
1919
// This assumes c was 0 before execute
20-
Js.Dict.set(state, varC, 0)
20+
Dict.set(state, varC, 0)
2121
},
2222
}

vm/lib/ocaml/Div.res

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,36 @@ let make = (varA: string, varB: string, varQ: string, varR: string): Instruction
1111
instructionType: "DIV",
1212
args: [varA, varB, varQ, varR],
1313
execute: state => {
14-
let valA = Js.Dict.get(state, varA)->Belt.Option.getWithDefault(0)
15-
let valB = Js.Dict.get(state, varB)->Belt.Option.getWithDefault(1) // Avoid division by zero
14+
let valA = Dict.get(state, varA)->Belt.Option.getWithDefault(0)
15+
let valB = Dict.get(state, varB)->Belt.Option.getWithDefault(1) // Avoid division by zero
1616

1717
if valB == 0 {
1818
// Division by zero - store error state
19-
Js.Dict.set(state, varQ, 0)
20-
Js.Dict.set(state, varR, valA) // Store original value in remainder
19+
Dict.set(state, varQ, 0)
20+
Dict.set(state, varR, valA) // Store original value in remainder
2121
} else {
2222
// Normal division: q = a / b, r = a mod b
2323
let quotient = valA / valB
2424
let remainder = mod(valA, valB)
2525

26-
Js.Dict.set(state, varQ, quotient)
27-
Js.Dict.set(state, varR, remainder)
26+
Dict.set(state, varQ, quotient)
27+
Dict.set(state, varR, remainder)
2828
}
2929
},
3030
invert: state => {
3131
// Inverse: reconstruct a from quotient and remainder
3232
// a = (q * b) + r
33-
let valB = Js.Dict.get(state, varB)->Belt.Option.getWithDefault(1)
34-
let valQ = Js.Dict.get(state, varQ)->Belt.Option.getWithDefault(0)
35-
let valR = Js.Dict.get(state, varR)->Belt.Option.getWithDefault(0)
33+
let valB = Dict.get(state, varB)->Belt.Option.getWithDefault(1)
34+
let valQ = Dict.get(state, varQ)->Belt.Option.getWithDefault(0)
35+
let valR = Dict.get(state, varR)->Belt.Option.getWithDefault(0)
3636

3737
let _reconstructed = (valQ * valB) + valR
3838
// In a full implementation, we might restore varA here:
39-
// Js.Dict.set(state, varA, reconstructed)
39+
// Dict.set(state, varA, reconstructed)
4040

4141
// Clear quotient and remainder (ancilla cleanup)
42-
Js.Dict.set(state, varQ, 0)
43-
Js.Dict.set(state, varR, 0)
42+
Dict.set(state, varQ, 0)
43+
Dict.set(state, varR, 0)
4444

4545
// Note: We don't restore varA here because DIV is typically used
4646
// to compute quotient/remainder, not to transform the dividend
@@ -52,16 +52,16 @@ let makeSimple = (varA: string, varB: string, varQ: string): Instruction.t => {
5252
instructionType: "DIV_SIMPLE",
5353
args: [varA, varB, varQ],
5454
execute: state => {
55-
let valA = Js.Dict.get(state, varA)->Belt.Option.getWithDefault(0)
56-
let valB = Js.Dict.get(state, varB)->Belt.Option.getWithDefault(1)
55+
let valA = Dict.get(state, varA)->Belt.Option.getWithDefault(0)
56+
let valB = Dict.get(state, varB)->Belt.Option.getWithDefault(1)
5757

5858
if valB != 0 {
5959
let quotient = valA / valB
60-
Js.Dict.set(state, varQ, quotient)
60+
Dict.set(state, varQ, quotient)
6161
}
6262
},
6363
invert: state => {
6464
// Clear the quotient
65-
Js.Dict.set(state, varQ, 0)
65+
Dict.set(state, varQ, 0)
6666
},
6767
}

vm/lib/ocaml/Flip.res

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ let make = (varA: string): Instruction.t => {
77
instructionType: "FLIP",
88
args: [varA],
99
execute: state => {
10-
let valA = Js.Dict.get(state, varA)->Belt.Option.getWithDefault(0)
10+
let valA = Dict.get(state, varA)->Belt.Option.getWithDefault(0)
1111
// Bitwise NOT: ~a
1212
// For integers, we'll use a simple inversion for demonstration
1313
// In a real binary system, this would flip all bits
1414
let result = lnot(valA)
15-
Js.Dict.set(state, varA, result)
15+
Dict.set(state, varA, result)
1616
},
1717
invert: state => {
1818
// FLIP is self-inverse: NOT(NOT(a)) = a
19-
let valA = Js.Dict.get(state, varA)->Belt.Option.getWithDefault(0)
19+
let valA = Dict.get(state, varA)->Belt.Option.getWithDefault(0)
2020
let result = lnot(valA)
21-
Js.Dict.set(state, varA, result)
21+
Dict.set(state, varA, result)
2222
},
2323
}

vm/lib/ocaml/IfPos.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ let make = (
1919
instructionType: "IF_POS",
2020
args: [testReg, exitReg],
2121
execute: state => {
22-
let testVal = Js.Dict.get(state, testReg)->Belt.Option.getWithDefault(0)
22+
let testVal = Dict.get(state, testReg)->Belt.Option.getWithDefault(0)
2323
if testVal > 0 {
2424
Belt.Array.forEach(thenBranch, instr => instr.execute(state))
2525
} else {
2626
Belt.Array.forEach(elseBranch, instr => instr.execute(state))
2727
}
2828
},
2929
invert: state => {
30-
let exitVal = Js.Dict.get(state, exitReg)->Belt.Option.getWithDefault(0)
30+
let exitVal = Dict.get(state, exitReg)->Belt.Option.getWithDefault(0)
3131
if exitVal > 0 {
3232
let reversed = Belt.Array.copy(thenBranch)
3333
Belt.Array.reverseInPlace(reversed)

vm/lib/ocaml/IfZero.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let make = (
2020
instructionType: "IF_ZERO",
2121
args: [testReg, exitReg],
2222
execute: state => {
23-
let testVal = Js.Dict.get(state, testReg)->Belt.Option.getWithDefault(0)
23+
let testVal = Dict.get(state, testReg)->Belt.Option.getWithDefault(0)
2424
if testVal == 0 {
2525
// Execute then-branch
2626
Belt.Array.forEach(thenBranch, instr => instr.execute(state))
@@ -31,7 +31,7 @@ let make = (
3131
},
3232
invert: state => {
3333
// Reverse uses the exit assertion to determine which branch was taken
34-
let exitVal = Js.Dict.get(state, exitReg)->Belt.Option.getWithDefault(0)
34+
let exitVal = Dict.get(state, exitReg)->Belt.Option.getWithDefault(0)
3535
if exitVal == 0 {
3636
// Was then-branch reverse it (instructions in reverse order)
3737
let reversed = Belt.Array.copy(thenBranch)

vm/lib/ocaml/Instruction.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
type t = {
44
instructionType: string,
55
args: array<string>,
6-
execute: Js.Dict.t<int> => unit,
7-
invert: Js.Dict.t<int> => unit,
6+
execute: dict<int> => unit,
7+
invert: dict<int> => unit,
88
}
99

1010
// Helper to create instruction records

0 commit comments

Comments
 (0)