39 lines
1.6 KiB
Plaintext
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")
|