Encapsulate EmbeddedScript variables
This commit is contained in:
@@ -20,9 +20,13 @@ class EmbeddedScript {
|
|||||||
var instructionPointer = 0;
|
var instructionPointer = 0;
|
||||||
var running = false;
|
var running = false;
|
||||||
|
|
||||||
// TODO encapsulate these?
|
private var instructions:Array<Command> = null;
|
||||||
public var breakPoints:Map<Int, () -> Bool> = [];
|
private var breakPoints:Map<Int, () -> Bool> = [];
|
||||||
public var onBreak:() -> Void = null;
|
private var onBreak:() -> Void = null;
|
||||||
|
|
||||||
|
public function setBreakHandler(handler:() -> Void) {
|
||||||
|
onBreak = handler;
|
||||||
|
}
|
||||||
|
|
||||||
public function addBreakPoint(instruction:Int, ?condition:() -> Bool) {
|
public function addBreakPoint(instruction:Int, ?condition:() -> Bool) {
|
||||||
if (condition == null) {
|
if (condition == null) {
|
||||||
@@ -31,6 +35,10 @@ class EmbeddedScript {
|
|||||||
breakPoints[instruction] = condition;
|
breakPoints[instruction] = condition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function removeBreakPoint(instruction:Int) {
|
||||||
|
breakPoints.remove(instruction);
|
||||||
|
}
|
||||||
|
|
||||||
public function new() {}
|
public function new() {}
|
||||||
|
|
||||||
#if macro
|
#if macro
|
||||||
|
@@ -80,9 +80,9 @@
|
|||||||
|
|
||||||
// Day 8
|
// Day 8
|
||||||
(let [example (new BootCodeExample)]
|
(let [example (new BootCodeExample)]
|
||||||
(set example.onBreak (lambda [] (assert (= 5 example.accumulator))))
|
(example.setBreakHandler (lambda [] (assert (= 5 example.accumulator))))
|
||||||
(example.run))
|
(example.run))
|
||||||
(let [bootCode (new BootCodeReal)]
|
(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)))
|
(bootCode.run)))
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user