-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueue.vm
106 lines (106 loc) · 1.45 KB
/
Queue.vm
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
function Queue.new 0
push constant 2
call Memory.alloc 1
pop pointer 0
push constant 0
pop this 0
push constant 0
pop this 1
push pointer 0
return
function Queue.isEmpty 0
push argument 0
pop pointer 0
push this 0
push constant 0
eq
push this 1
push constant 0
eq
and
return
function Queue.enqueue 1
push argument 0
pop pointer 0
push argument 1
call Node.new 1
pop local 0
push local 0
push this 0
call Node.setNext 2
pop temp 0
push this 0
if-goto IF_TRUE0
goto IF_FALSE0
label IF_TRUE0
push this 0
push local 0
call Node.setPrev 2
pop temp 0
goto IF_END0
label IF_FALSE0
push local 0
pop this 1
label IF_END0
push local 0
pop this 0
push constant 0
return
function Queue.dequeue 2
push argument 0
pop pointer 0
push this 1
pop local 0
push this 1
if-goto IF_TRUE0
goto IF_FALSE0
label IF_TRUE0
push this 1
call Node.getValue 1
pop local 1
push this 1
call Node.dispose 1
pop temp 0
push local 0
call Node.getPrev 1
pop this 1
push this 1
push this 0
eq
if-goto IF_TRUE1
goto IF_FALSE1
label IF_TRUE1
push constant 0
pop this 0
label IF_FALSE1
push local 1
return
goto IF_END0
label IF_FALSE0
push constant 0
return
label IF_END0
function Queue.dispose 2
push argument 0
pop pointer 0
push this 0
pop local 0
label WHILE_EXP0
push local 0
not
if-goto WHILE_END0
push local 0
pop local 1
push local 1
call Node.getNext 1
pop local 0
push local 1
call Node.dispose 1
pop temp 0
goto WHILE_EXP0
label WHILE_END0
push pointer 0
call Memory.deAlloc 1
pop temp 0
push constant 0
return