From b8492c1e8ee3821ecdadda4c8921dc06b851af31 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Wed, 9 Dec 2020 13:03:50 -0700 Subject: [PATCH] Encapsulate EmbeddedScript variables --- kiss/src/kiss/EmbeddedScript.hx | 14 +++++++++++--- projects/aoc/src/year2020/Solutions.kiss | 4 ++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/kiss/src/kiss/EmbeddedScript.hx b/kiss/src/kiss/EmbeddedScript.hx index 86595802..b62154c9 100644 --- a/kiss/src/kiss/EmbeddedScript.hx +++ b/kiss/src/kiss/EmbeddedScript.hx @@ -20,9 +20,13 @@ class EmbeddedScript { var instructionPointer = 0; var running = false; - // TODO encapsulate these? - public var breakPoints:Map Bool> = []; - public var onBreak:() -> Void = null; + private var instructions:Array = null; + private var breakPoints:Map Bool> = []; + private var onBreak:() -> Void = null; + + public function setBreakHandler(handler:() -> Void) { + onBreak = handler; + } public function addBreakPoint(instruction:Int, ?condition:() -> Bool) { if (condition == null) { @@ -31,6 +35,10 @@ class EmbeddedScript { breakPoints[instruction] = condition; } + public function removeBreakPoint(instruction:Int) { + breakPoints.remove(instruction); + } + public function new() {} #if macro diff --git a/projects/aoc/src/year2020/Solutions.kiss b/projects/aoc/src/year2020/Solutions.kiss index 13857f37..cc0555e1 100644 --- a/projects/aoc/src/year2020/Solutions.kiss +++ b/projects/aoc/src/year2020/Solutions.kiss @@ -80,9 +80,9 @@ // Day 8 (let [example (new BootCodeExample)] - (set example.onBreak (lambda [] (assert (= 5 example.accumulator)))) + (example.setBreakHandler (lambda [] (assert (= 5 example.accumulator)))) (example.run)) (let [bootCode (new BootCodeReal)] - (set bootCode.onBreak (lambda [] (assert (= 2058 bootCode.accumulator) (assert true)))) + (bootCode.setBreakHandler (lambda [] (assert (= 2058 bootCode.accumulator) (assert true)))) (bootCode.run)))