Enhanced EmbeddedScript error messages
This commit is contained in:
@@ -8,3 +8,6 @@ class BootCodeExample extends EmbeddedScript {}
|
||||
|
||||
@:build(kiss.EmbeddedScript.build("src/year2020/BootCodeDSL.kiss", "src/year2020/inputs/day8.txt"))
|
||||
class BootCodeReal extends EmbeddedScript {}
|
||||
|
||||
@:build(kiss.EmbeddedScript.build("src/year2020/BootCodeFixDSL.kiss", "src/year2020/inputs/day8.txt"))
|
||||
class BootCodeFix extends EmbeddedScript {}
|
||||
|
@@ -4,4 +4,7 @@
|
||||
|
||||
(defmethod nop [v] (setBreakPoint))
|
||||
(defmethod acc [v] (setBreakPoint) (set accumulator (+ accumulator v)))
|
||||
(defmethod jmp [v] (setBreakPoint) (set instructionPointer (+ instructionPointer (- v 1))))
|
||||
(defmethod jmp [v]
|
||||
(setBreakPoint)
|
||||
//(print (+ "jumping " (Std.string v) " from " (Std.string instructionPointer)))
|
||||
(set instructionPointer (+ instructionPointer (- v 1))))
|
26
projects/aoc/src/year2020/BootCodeFixDSL.kiss
Normal file
26
projects/aoc/src/year2020/BootCodeFixDSL.kiss
Normal file
@@ -0,0 +1,26 @@
|
||||
(load "BootCodeCommon.kiss")
|
||||
|
||||
(defvar &mut forked false)
|
||||
|
||||
(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)
|
||||
`(if forked
|
||||
(,instSymbol (,op 0 ,arg))
|
||||
(begin
|
||||
|
||||
(fork [
|
||||
(lambda [] (when ,(ReaderExp.Symbol (Std.string (= inst "nop"))) (set forked true)) (jmp (,op 0 ,arg)))
|
||||
(lambda [] (when ,(ReaderExp.Symbol (Std.string (= inst "jmp"))) (set forked true)) (nop (,op 0 ,arg)))
|
||||
])))))
|
||||
|
||||
// Define the default reader LAST because default readers tend to break everything
|
||||
(load "BootCodeDSL.kiss")
|
@@ -80,9 +80,14 @@
|
||||
|
||||
// Day 8
|
||||
(let [example (new BootCodeExample)]
|
||||
(example.setBreakHandler (lambda [] (assert (= 5 example.accumulator))))
|
||||
(example.setBreakHandler (lambda [example] (assert (= 5 .accumulator example))))
|
||||
(example.run))
|
||||
(let [bootCode (new BootCodeReal)]
|
||||
(bootCode.setBreakHandler (lambda [] (assert (= 2058 bootCode.accumulator) (assert true))))
|
||||
(bootCode.run)))
|
||||
(bootCode.setBreakHandler (lambda [bootCode] (assert (= 2058 bootCode.accumulator) (assert true))))
|
||||
(bootCode.run))
|
||||
(let [bootCode (new BootCodeFix)]
|
||||
(bootCode.setBreakHandler (lambda [:BootCodeFix bootCodeFork] (when (= bootCodeFork.instructionPointer (bootCodeFork.instructionCount)) (print .accumulator (the BootCodeFix bootCodeFork)))))
|
||||
(bootCode.addBreakPoint (bootCode.instructionCount))
|
||||
(bootCode.run))
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user