-
Notifications
You must be signed in to change notification settings - Fork 1
/
debug.red
171 lines (126 loc) · 3.6 KB
/
debug.red
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
Red [
Title: "do-trace.red"
duplicates: [
"do-trace"
"lib-debug.red"
"debug.red"
]
Build: 1.0.0.3
History: {
- added .do-trace-update-lines
}
]
.do-trace: function [.line-number [integer!] '.block [word! block! unset!] .file [file! url! string!]
/filter that-contains [string! file! url!]
/update .script-path
][
{
#### Example:
- [x] [1].
```
f: function [.file .argument][
do-trace 2 [
probe .argument
] .file
]
f %test-this-file.red "test this file"
```
- [x] [2].
```
g: function [.file .argument][
do-trace/filter 2 [
probe .argument
] .file "test"
]
g %this-should-not-be-traced.red "this file should not be traced"
```
}
if update [
.do-trace-update-lines .script-path
]
file: form .file
if filter [
either not find file that-contains [exit][
]
]
switch type?/word get/any '.block [
unset! [
print {TODO:}
]
block! [
.do-events/no-wait
print newline
print "---------------------------------"
print [file "line" .line-number ": "]
.do-events/no-wait
do :.block
ask rejoin ["pause on line " .line-number "..."]
]
]
]
do-trace: :.do-trace
; dependencies
.do-events: function [
{Launch the event loop, blocks until all windows are closed}
/no-wait "Process an event in the queue and returns at once"
return: [logic! word!] "Returned value from last event"
/local result
win
][
try [
either no-wait [
do-events/no-wait
][
do-events
]
]
]
.do-trace-update-lines: function[script-path][
source-code-lines: read/lines script-path
forall source-code-lines [
line-number: index? source-code-lines
source-code-line: source-code-lines/1
old-source-code-line: source-code-line
source-code-line: replace-line-number source-code-line line-number
either line-number = 1 [
write %temp.red source-code-line
][
write/append %temp.red source-code-line
]
write/append %temp.red rejoin ["" newline]
]
source-code: read %temp.red
parse source-code parse-rule: [
(count: 0)
any [
to "do-trace" thru "[" (count: count + 1)
thru "]" (count: count - 1)
thru "%" start: copy old-filename [to ".red" | to ".read"] copy extension [ to " " | to "^/"] ending:
(
if (old-filename <> {" start: copy old-filename [to "}) [
script-filename: .get-short-filename script-path
change/part start script-filename ending
]
)
]
]
write %temp2.red source-code
write-clipboard source-code
print "do-trace update written to clipboard"
]
do-trace-update-lines: :.do-trace-update-lines
; dependencies
.replace-line-number: function[source-code-line new-line-number][
parse-rule: [
thru "do-trace" thru " " start: copy line-number to " " ending: (
try [
line-number: to-integer to-float line-number
change/part start new-line-number ending
]
count: 0
)
]
parse source-code-line parse-rule
return source-code-line
]
replace-line-number: :.replace-line-number