Files
kiss-vscode/projects/aoc/src/year2020/BootCodeFixDSL.kiss
2021-07-24 14:40:55 -06:00

39 lines
1.6 KiB
Plaintext

(load "BootCodeCommon.kiss")
(var :Map<Int,Bool> instructionsTested (new Map<Int,Bool>))
(prop &mut forked false)
(prop &mut forkedAt -1)
(defReaderMacro ["jmp" "nop"] [stream]
(let [inst
(nextToken stream)
instSymbol
(ReaderExp.Symbol inst)
op
(begin (stream.dropWhitespace) (ReaderExp.Symbol
(begin (stream.dropWhitespace) (stream.expect "+/-" (lambda [] (stream.takeChars 1))))))
arg
(ReaderExp.Symbol (nextToken stream))]
(stream.dropWhitespace)
`(cond
((or self.forked (instructionsTested.exists self.instructionPointer))
(,instSymbol (,op 0 ,arg) self))
(true
(dictSet instructionsTested self.instructionPointer true)
(self.setBreakPoint)
(self.fork [
(lambda [:Dynamic self]
(when ,(ReaderExp.Symbol (Std.string (= inst "nop")))
(set self.forked true)
(set self.forkedAt self.instructionPointer))
(jmp (,op 0 ,arg) self))
(lambda [:Dynamic self]
(when ,(ReaderExp.Symbol (Std.string (= inst "jmp")))
(set self.forked true)
(set self.forkedAt self.instructionPointer))
(nop (,op 0 ,arg) self))
])))))
// Define the default reader LAST because default readers tend to break everything
(load "BootCodeDSL.kiss")