-
Notifications
You must be signed in to change notification settings - Fork 246
/
Copy pathinstruction.js
53 lines (48 loc) · 1.25 KB
/
instruction.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
43
44
45
46
47
48
49
50
51
52
53
export var INUMBER = 'INUMBER';
export var IOP1 = 'IOP1';
export var IOP2 = 'IOP2';
export var IOP3 = 'IOP3';
export var IVAR = 'IVAR';
export var IVARNAME = 'IVARNAME';
export var IFUNCALL = 'IFUNCALL';
export var IFUNDEF = 'IFUNDEF';
export var IEXPR = 'IEXPR';
export var IEXPREVAL = 'IEXPREVAL';
export var IMEMBER = 'IMEMBER';
export var IENDSTATEMENT = 'IENDSTATEMENT';
export var IARRAY = 'IARRAY';
export function Instruction(type, value) {
this.type = type;
this.value = (value !== undefined && value !== null) ? value : 0;
}
Instruction.prototype.toString = function () {
switch (this.type) {
case INUMBER:
case IOP1:
case IOP2:
case IOP3:
case IVAR:
case IVARNAME:
case IENDSTATEMENT:
return this.value;
case IFUNCALL:
return 'CALL ' + this.value;
case IFUNDEF:
return 'DEF ' + this.value;
case IARRAY:
return 'ARRAY ' + this.value;
case IMEMBER:
return '.' + this.value;
default:
return 'Invalid Instruction';
}
};
export function unaryInstruction(value) {
return new Instruction(IOP1, value);
}
export function binaryInstruction(value) {
return new Instruction(IOP2, value);
}
export function ternaryInstruction(value) {
return new Instruction(IOP3, value);
}