5var staticDebugger = null;
7Elm.debuggerInit = function(module) {
9 staticDebugger = debuggerInit(module, elm);
10 return staticDebugger.moduleRetValue;
14Elm.debuggerReset = function() {
15 staticDebugger.reset();
18Elm.debuggerRestart = function() {
19 staticDebugger.restart();
22Elm.debuggerStep = function() {
23 staticDebugger.step();
26function debuggerInit(module, elm) {
28 var programPaused = false;
31 var recordedEvents = [];
33 var initialProgramState = {
38 function wrapNotify(id, v) {
39 var timestep = Date.now();
42 // ignore notify because we are stepping
45 elm.notify(id, v, timestep);
46 recordEvent(id, v, timestep);
50 function wrapRunDelayed(func, delayMs) {
51 return safeSetTimeout(func, delayMs);
54 function safeSetTimeout(func, delayMs) {
55 var timerId = setTimeout(func, delayMs);
56 asyncTimers.push({ func:func, delayMs:delayMs, timerId:timerId });
60 function recordEvent(id, v, timestep) {
61 recordedEvents.push({ id:id, value:v, timestep:timestep });
64 function resetProgram() {
66 restoreNodeValues(allNodes, initialProgramState.nodeValues);
70 function restartProgram() {
73 initialProgramState.asyncTimers.forEach(function(timer) {
74 var func = timer.func;
79 function stepRecording() {
81 if (recordedEvents.length > 0) {
82 var nextEvent = recordedEvents.shift();
83 elm.notify(nextEvent.id, nextEvent.value, nextEvent.timestep);
87 // move into stepping mode
93 function clearAsyncEvents() {
94 asyncTimers.forEach(function(timer) {
95 clearTimeout(timer.timerId);
99 function doPlayback(eventList) {
100 var x = eventList.shift();
102 elm.notify(x[0], x[1], x[2]);
104 if (eventList.length > 0) {
105 var delta = eventList[0][2] - time;
106 setTimeout(function() { doPlayback(eventList); }, delta);
110 function redrawGraphics() {
111 var graphicsFoldp = moduleRetValue.main.kids[0];
112 graphicsFoldp.recv(Date.now(), true, moduleRetValue.main.id);
117 runDelayed: wrapRunDelayed,
119 display: elm.display,
121 addListener: elm.addListener,
125 var moduleRetValue = module(wrappedElm);
128 moduleRetValue: moduleRetValue,
130 // debugger functions
132 restart: restartProgram,
136 allNodes = flattenNodes(wrappedElm.inputs);
137 initialProgramState.nodeValues = saveNodeValues(allNodes);
138 initialProgramState.asyncTimers = asyncTimers.slice();
145function assert(bool, msg) {
147 throw "Assertion error: " + msg;
151function saveNodeValues(allNodes) {
154 allNodes.forEach(function(node) {
155 nodeValues.push({ value: node.value, id: node.id });
162function restoreNodeValues(allNodes, nodeStates) {
163 assert(allNodes.length == nodeStates.length, "saved program state has wrong length");
164 for (var i=0; i < allNodes.length; i++) {
165 var node = allNodes[i];
166 var state = nodeStates[i];
167 assert(node.id == state.id, "the nodes moved position");
169 node.value = state.value;
173function flattenNodes(nodes) {
174 var treeReduce = function(prev, cur, i, arr) {
175 var flatKids = cur.kids.reduce(treeReduce, []);
177 return prev.concat(flatKids);
180 return nodes.reduce(treeReduce, []);
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list