-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjs.js
More file actions
177 lines (141 loc) · 5.7 KB
/
js.js
File metadata and controls
177 lines (141 loc) · 5.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
var delayValue;
let runBtn = document.getElementById("button");
runBtn.addEventListener("click", async function (e) {
runBtn.style.visibility = "hidden";//hide the run button
let inp = document.getElementById("inp");
delayValue = document.getElementById("delayInput").value * 1000;
inp.style.visibility = "hidden";
//Add the main function to the call stack
let stack = document.querySelectorAll("#stack td");
stack[0].innerHTML = `<div>
<span class="function">main</span>
<span class="brackets">(</span>
<span class="brackets">)</span>
</div>`;
await glow(stack[0]);
//Display the arrow and heighlight the first line
let prevLine = moveArrow(11, "non");
let arrow = document.getElementById("arrow");
arrow.classList.add("display");
await glow(arrow);
//Add x to memory
let ramCells = document.querySelectorAll("#ram tr");
let addressValue = ramCells[1].querySelectorAll("td");
addressValue[1].textContent = "10";
await glow(ramCells[1]);
//Add x to symbols table
let symbolCells = document.querySelectorAll("#symbolTable tr");
let value = symbolCells[1].querySelectorAll("td");
value[0].textContent = "x";
value[1].textContent = "0x00";
await glow(symbolCells[1]);
prevLine = moveArrow(12, prevLine);
await new Promise(r => setTimeout(r, delayValue));
//Add the byvalue function to the call stack
stack[1].innerHTML = `<div>
<span class="function">by_value</span>
<span class="brackets">(</span>
<span class="variable">x</span>
<span class="brackets">)</span>
</div>`;
await glow(stack[1]);
prevLine = moveArrow(1, prevLine);
await new Promise(r => setTimeout(r, delayValue));
//Add byvalue a to memory
addressValue = ramCells[2].querySelectorAll("td");
addressValue[1].textContent = "10";
await glow(ramCells[2]);
//Add byvalue a to symbols table
value = symbolCells[2].querySelectorAll("td");
value[0].textContent = "a";
value[1].textContent = "0x01";
await glow(symbolCells[2]);
prevLine = moveArrow(3, prevLine);
await new Promise(r => setTimeout(r, delayValue));
//Modify byvalue a memory value
addressValue = ramCells[2].querySelectorAll("td");
addressValue[1].textContent = "15";
await glow(ramCells[2]);
prevLine = moveArrow(12, prevLine);
await new Promise(r => setTimeout(r, delayValue));
//remove the byvalue function from the call stack
stack[1].innerHTML = ``;
await glow(stack[1]);
//Remove byvalue a from memory
addressValue = ramCells[2].querySelectorAll("td");
addressValue[1].textContent = "GARBAGE";
await glow(ramCells[2]);
//remove byvalue a from symbols table
value = symbolCells[2].querySelectorAll("td");
value[0].textContent = "";
value[1].textContent = "";
await glow(symbolCells[2]);
prevLine = moveArrow(13, prevLine);
await new Promise(r => setTimeout(r, delayValue));
//print out cout
let div = document.createElement("div");
let text = document.createTextNode("Value of X: 10");
div.appendChild(text);
let print = document.getElementById("print");
let output = document.getElementById("output");
output.insertBefore(div, print);
await glow(output);
await new Promise(r => setTimeout(r, delayValue));
prevLine = moveArrow(14, prevLine);
await new Promise(r => setTimeout(r, delayValue));
//Add the byReference function to the call stack
stack[1].innerHTML = `<div>
<span class="function">by_reference</span>
<span class="brackets">(</span>
<span class="variable">x</span>
<span class="brackets">)</span>
</div>`;
await glow(stack[1]);
prevLine = moveArrow(5, prevLine);
await new Promise(r => setTimeout(r, delayValue));
//Add byreference a to symbols table
value = symbolCells[2].querySelectorAll("td");
value[0].textContent = "a";
value[1].textContent = "0x00";
await glow(symbolCells[2]);
prevLine = moveArrow(7, prevLine);
await new Promise(r => setTimeout(r, delayValue));
//Modify byreference a memory value
addressValue = ramCells[1].querySelectorAll("td");
addressValue[1].textContent = "20";
await glow(ramCells[1]);
prevLine = moveArrow(14, prevLine);
await new Promise(r => setTimeout(r, delayValue));
//Remove the byreference function from the call stack
stack[1].innerHTML = ``;
await glow(stack[1]);
//Remove byreference a from symbols table
value = symbolCells[2].querySelectorAll("td");
value[0].textContent = "";
value[1].textContent = "";
await glow(symbolCells[2]);
prevLine = moveArrow(15, prevLine);
await new Promise(r => setTimeout(r, delayValue));
//print out cout
div = document.createElement("div");
text = document.createTextNode("Value of X: 20");
div.appendChild(text);
output.insertBefore(div, print)
await glow(output);
});
function moveArrow(lineNum, prevLine) {
let line = document.querySelector(`.line:nth-child(${lineNum})`);
if (prevLine != "non")
prevLine.classList.remove("heighlight");
line.classList.add("heighlight");
let arrow = document.getElementById("arrow");
let arect = arrow.getBoundingClientRect();
let rect = line.getBoundingClientRect();
arrow.style.top = `${(rect.top + (rect.height / 2)) - (arect.height / 2)}px`;
return line;
}
async function glow(element) {
element.classList.add("glow");
await new Promise(r => setTimeout(r, delayValue));
element.classList.remove("glow");
}