-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathStack.js
42 lines (33 loc) · 893 Bytes
/
Stack.js
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
const Variable = require('./Variable');
class Stack {
constructor() {
this.data = [];
}
push(el) {
this.data.push(el);
}
pop() {
return this.data.pop();
}
get(idx) {
let new_var = new Variable(this.data[idx].type, this.data[idx].value, this.data[idx].taint);
return new_var;
}
set(idx, val) {
let new_var = new Variable(val.type, val.value, val.taint);
this.data[idx] = new_var;
}
len() {
return this.data.length;
}
ptr() {
return this.data.length -1 ;
}
print() {
console.log("STACK: ");
for(let i = 0; i < this.data.length; i++) {
console.log(" " + i + " - type: " + this.data[i].type + "; value: " + this.data[i].value + "; taint: " + JSON.stringify(this.data[i].taint));
}
}
}
module.exports = Stack;