-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathtraverse_map.script
56 lines (49 loc) · 1.41 KB
/
traverse_map.script
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
.if ($sicmp("${$arg1}", "-n") == 0) {
.if (@@(@$t0->_Isnil) == 0) {
.if (@$t2 == 1) {
.printf /D "<exec cmd=\"db %p L10\">%p</exec>\n", @$t0, @$t0
.printf "key = "
?? @$t0->_Myval.first
.printf "value = "
?? @$t0->_Myval.second
} .else {
r? $t9 = @$t0->_Myval
command
}
}
$$ This statement is here for debugging purposes
$$ .printf "root = %p, node = %p, left = %p, right = %p\n", @$t1, @$t0, @@(@$t0->_Left), @@(@$t0->_Right)
$$ Recurse into _Left, _Right unless they point to the root of the tree.
$$ Note that we need to store the register state (t0 etc.), because otherwise the "recursive"
$$ invocation is going to clobber them for us. Luckily we have commands to push/pop state.
.if (@@(@$t0->_Left) != @@(@$t1)) {
.push /r /q
r? $t0 = @$t0->_Left
$$>a< ${$arg0} -n
.pop /r /q
}
.if (@@(@$t0->_Right) != @@(@$t1)) {
.push /r /q
r? $t0 = @$t0->_Right
$$>a< ${$arg0} -n
.pop /r /q
}
} .else {
r? $t0 = ${$arg1}
.if (${/d:$arg2}) {
.if ($sicmp("${$arg2}", "-c") == 0) {
r $t2 = 0
aS ${/v:command} "${$arg3}"
}
} .else {
r $t2 = 1
aS ${/v:command} " "
}
.printf "size = %d\n", @@(@$t0._Mysize)
$$ t0 now will contain the root of the tree but will be changed by subsequent invocations
$$ t1 on the other hand will contain the head node (always), this is our stop condition
r? $t0 = @$t0._Myhead->_Parent
r? $t1 = @$t0->_Parent
$$>a< ${$arg0} -n
ad command
}