Skip to content

Commit 64bbf54

Browse files
authored
Revive esdebug (#234)
Update the `esdebug` script so it works with current es versions: - Replace #! /bin/es with #!/usr/local/bin/es, reflecting the standard install location today - Replace `line` call with %read - Replace `return` with `result` where the exception behavior isn't necessary - Replace $&while with a lexically-captured while function - Replace the dispatch parameter to %interactive-loop with dynamically-defined fn-%dispatch - Handle exit's change to an exception
1 parent beec36c commit 64bbf54

1 file changed

Lines changed: 26 additions & 14 deletions

File tree

esdebug

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#! /bin/es -p
1+
#!/usr/local/bin/es -p
22
# esdebug: a debugger for es scripts ($Revision: 1.1.1.1 $)
33

44
# TODO
@@ -37,7 +37,7 @@ fn _print {
3737
}
3838

3939
fn _get {
40-
$&seq {echo >[1=3] -n $*} {return `{line <[0=3]}}
40+
$&seq {echo >[1=3] -n $*} {%split ' '\t <={%read <[0=3]}}
4141
}
4242

4343
_prompt = '(esdebug) '
@@ -173,7 +173,7 @@ _debug-watch = @ vars {
173173
} {
174174
_print new $var '=' $*
175175
} {
176-
return $*
176+
result $*
177177
}
178178
}
179179
}
@@ -196,7 +196,7 @@ _debug-trap = @ vars {
196196
local (old = $$var; new = $*)
197197
_debug break
198198
} {
199-
return $*
199+
result $*
200200
}
201201
}
202202
}
@@ -258,13 +258,14 @@ let (commands =) {
258258
# the main debugger loop
259259
#
260260

261+
let (fn-while = $fn-while)
261262
fn-_debug = $&noreturn @ {
262263
$&if {~ $1 break || $_stepping} {
263264
<= {
264-
$&while {
265+
while true {
265266
let (cmd = <={_get $_prompt}) {
266267
$&seq {
267-
$&while {~ $cmd(1) $_prompt} {
268+
while {~ $cmd(1) $_prompt} {
268269
cmd = $cmd(2 ...)
269270
}
270271
} {
@@ -289,7 +290,8 @@ fn-_debug = $&noreturn @ {
289290
#
290291

291292
history =
292-
fn %interactive-loop dispatch {
293+
let (fn-while = $fn-while)
294+
fn %interactive-loop {
293295
let (result = <= true) {
294296
catch @ e type msg {
295297
$&if {~ $e eof} {
@@ -298,7 +300,13 @@ fn %interactive-loop dispatch {
298300
} {
299301
_debug break
300302
} {
301-
return $result
303+
result $result
304+
}
305+
} {~ $e exit} {
306+
$&seq {
307+
_print exiting ...
308+
} {
309+
result $type
302310
}
303311
} {
304312
$&seq {
@@ -315,20 +323,24 @@ fn %interactive-loop dispatch {
315323
$&seq {
316324
_print parsing input from $_program:
317325
} {
318-
$&while {~ $#cmd 0} {
326+
while {~ $#cmd 0} {
319327
cmd = <={%parse}
320328
}
321329
} {
322330
_debug
323331
} {
324-
catch @ e {
325-
$&seq {
326-
_print exception: $e
332+
catch @ e rest {
333+
if {~ $e exit} {
334+
throw $e $rest
327335
} {
328-
_debug
336+
$&seq {
337+
_print exception: $e ...
338+
} {
339+
_debug
340+
}
329341
}
330342
} {
331-
result = <={$dispatch $cmd}
343+
result = <={$fn-%dispatch $cmd}
332344
}
333345
}
334346
}

0 commit comments

Comments
 (0)