shithub: sl

Download patch

ref: d2e8d70b5ba0ac809041cde11a106e4a7d641670
parent: 9dc5cac76dd203b5b7e2f8d99cb4d5e587fd6a2d
author: spew <spew@cbza.org>
date: Sun Mar 23 15:55:25 EDT 2025

lsd: use let {[]} style, add doc-groups, change "Examples:" back

--- a/src/plan9/lsd.sl
+++ b/src/plan9/lsd.sl
@@ -23,11 +23,11 @@
 
 (def (procfile s . flags)
   (when (< pid 0) (error "no active pid"))
-  (let ((path (str "/proc/" pid "/" s)))
+  (let {[path (str "/proc/" pid "/" s)]}
     (apply file (cons path flags))))
 
 (def (writectl msg)
-  (let ((ctlf (procfile 'ctl :write)))
+  (let {[ctlf (procfile 'ctl :write)]}
     (io-write ctlf msg)
     (io-close ctlf)))
 
@@ -41,7 +41,7 @@
 
 (def (readnote)
   (trycatch
-    (let ((notef (procfile 'note :read)))
+    (let {[notef (procfile 'note :read)]}
       (prog1 (io-readall notef)
              (io-close notef)))
     (λ (e) (if (and (eq? (car e) 'io-error)
@@ -55,6 +55,7 @@
 
 (def (follow addr)
   "Return a list of the next possible executing instructions."
+  :doc-group lsd
   (lsd-follow addr))
 
 (def (io-pread f off rest)
@@ -80,9 +81,9 @@
 
 (def (readreg reg)
   (unless regsf (error "not attached to proc"))
-  (let ((f (case (reg-type reg)
+  (let {[f (case (reg-type reg)
              ((:gpreg) regsf)
-             ((:fpreg) fpregsf))))
+             ((:fpreg) fpregsf))]}
     (io-pread f (reg-addr reg) (list (reg-size reg)))))
 
 (def (readsym symbol . rest)
@@ -95,7 +96,7 @@
 
 (def (bpsave a) (readcore a 'byte (length bpinst)))
 
-(let ((bp_init (λ (loc)
+(let {[bp_init (λ (loc)
                  (when (< pid 0) (error "no running process"))
                  (unless (eq? (status) 'Stopped)
                          (begin (princ "Waiting... " status "\n")
@@ -105,15 +106,15 @@
                        ((num? loc) (u64 loc))
                        ((symbol? loc) (symbol-addr loc))
                        ((str? loc) (filepc loc))
-                       (else (error "sym|num|symbol|file:line"))))))
+                       (else (error "sym|num|symbol|file:line"))))]}
   (set! bpset (λ (loc)
-                (let ((addr (bp_init loc)))
+                (let {[addr (bp_init loc)]}
                   (when (has? bptbl addr)
                         (error "breakpoint already set at " loc))
                   (put! bptbl addr (bpsave addr))
                   (writecore addr bpinst))))
   (set! bpdel (λ (loc)
-                (let ((addr (bp_init loc)))
+                (let {[addr (bp_init loc)]}
                   (unless (has? bptbl addr)
                           (error "breakpoint not set at " loc))
                   (writecore addr (get bptbl addr))
@@ -131,11 +132,12 @@
    4. A string of the form \"file:line\" which specifies a line in a
       file of source code.
 
-   EXAMPLES
+   Examples:
 
        `(bpset 'strcpy)` ; breakpoint on strcpy function.
        `(bpset (curPC))` ; breakpoint on current instruction.
-       `(bpset \"/sys/src/cmd/cat.c:26\")` ; breakpoint on line 26.")
+       `(bpset \"/sys/src/cmd/cat.c:26\")` ; breakpoint on line 26."
+  :doc-group lsd)
 
 (doc-for (bpdel loc)
   "Delete a breakpoint.
@@ -149,11 +151,12 @@
    4. A string of the form \"file:line\" which specifies a line in a
       file of source code.
 
-   EXAMPLES
+   Examples:
 
        `(bpdel 'strcpy)` ; remove breakpoint on strcpy function.
        `(bpdel (curPC))` ; remove breakpoint on current instruction.
-       `(bpdel \"/sys/src/cmd/cat.c:26\")` ; remove breakpoint on line 26.")
+       `(bpdel \"/sys/src/cmd/cat.c:26\")` ; remove breakpoint on line 26."
+  :doc-group lsd)
 
 (def (detach)
   (when regsf (io-close regsf))
@@ -171,7 +174,7 @@
   (void))
 
 (def (status)
-  (let ((sf (procfile 'status)))
+  (let {[sf (procfile 'status)]}
     (prog1 (caddr (read-all sf))
            (io-close sf))))
 
@@ -189,13 +192,14 @@
 (def (step (n 1))
   "Step `n` assembly instructions. Return the next instruction
    address to be executed or `NIL` if the program has exited."
+  :doc-group lsd
   (if (= n 0)
       (curPC)
-      (let* ((addr (curPC))
-             (on-bp (has? bptbl addr)))
+      (let* {[addr (curPC)]
+             [on-bp (has? bptbl addr)]}
         (when on-bp (writecore addr (get bptbl addr)))
-        (let* ((f (follow addr))
-               (o (map bpsave f)))
+        (let* {[f (follow addr)]
+               [o (map bpsave f)]}
           (for-each (λ (a) (writecore a bpinst)) f)
           (startstop)
           (map writecore f o)
@@ -205,16 +209,18 @@
 (def (cont (:print T))
   "Continue program execution. Return the next instruction
    address to be executed or `NIL` if the program has exited."
+  :doc-group lsd
   (when (has? bptbl (curPC)) (step))
-  (let ((note (startstop)))
+  (let {[note (startstop)]}
     (and print (not (void? note)) (princ note "\n")))
-  (let ((pc (curPC)))
+  (let {[pc (curPC)]}
     (and print pc (princ (hex pc) "\n"))))
 
 (def (func)
   "Continue program execution until the current function returns."
-  (let* ((bp (frame-retpc (car (_stk))))
-         (o (bpsave bp)))
+  :doc-group lsd
+  (let* {[bp (frame-retpc (car (_stk)))]
+         [o (bpsave bp)]}
     (writecore bp bpinst)
     (cont :print NIL)
     (writecore bp o))
@@ -224,7 +230,8 @@
   "Step one line of the source code.
 
    This will step into functions not over."
-  (let ((orig (src)))
+  :doc-group lsd
+  (let {[orig (src)]}
     (def (go)
       (step)
       (if (not (equal? orig (src)))
@@ -239,7 +246,8 @@
        Stepping over a function call will remain on the same line
        whenever there is an assignment of the return value. You
        will have to step twice in that case."
-  (let ((f (car (_stk))))
+  :doc-group lsd
+  (let {[f (car (_stk))]}
     (line)
     (if (equal? f (car (_stk)))
         (curPC)
@@ -251,13 +259,14 @@
    Each element in the list has the form `(address . instr)` where `instr`
    is the disassembled instruction at the `address`.
 
-   EXAMPLES just like `(asm)` but returns a list instead of printing."
+   Examples: just like `(asm)` but returns a list instead of printing."
+  :doc-group lsd
   (if (<= n 0)
       ()
-      (let ((on-bp (has? bptbl addr)))
+      (let {[on-bp (has? bptbl addr)]}
         (when on-bp (writecore addr (get bptbl addr)))
-        (let ((instr (lsd-das addr))
-              (isize (lsd-instsize addr)))
+        (let {[instr (lsd-das addr)]
+              [isize (lsd-instsize addr)]}
           (when on-bp (writecore addr bpinst))
           (cons (cons addr instr) (asmlist (1- n) (+ addr isize)))))))
 
@@ -264,11 +273,12 @@
 (def (asm (n 5) (addr (curPC)))
   "Print the next `n` disassembled instructions at addr.
 
-   EXAMPLES
+   Examples:
 
        `(asm)` ; print out 5 from current program instruction.
        `(asm 10)` ; print out 10 from current program instruction.
        `(asm 3 (sym-addr 'strecpy))` ; 3 instructions from strecpy"
+  :doc-group lsd
   (for-each (λ (i) (princ (hex (car i)) "\t" (cdr i) "\n"))
             (asmlist n addr)))
 
@@ -275,6 +285,7 @@
 (def (src (addr (curPC)))
   "Return a string of the filename and line number corresponding
    to the instruction address."
+  :doc-group lsd
   (when addr (lsd-fileline addr)))
 
 (def (Bsrc (addr (curPC)))
@@ -281,8 +292,8 @@
   "Send a plumb message of the filename and line number
    corresponding to the instruction address so that the
    source code  can be viewed in your text editor."
-  (let ((s (src addr))
-        (plumbf (file "/mnt/plumb/send" :write)))
+  (let {[s (src addr)]
+        [plumbf (file "/mnt/plumb/send" :write)]}
     (io-write plumbf
               (str "plumb\n\n"
                    (path-cwd)
@@ -295,10 +306,11 @@
   "Step forward using the stepper and then plumb the
    new line to your editor.
 
-   EXAMPLES
+   Examples:
 
        `(B line)`; step one line and then see
        `(B cont)`; continue and then see where you stop"
+  :doc-group lsd
   (stepper)
   (Bsrc))
 
@@ -306,7 +318,7 @@
   "Return the instruction address corresponding to a filename
    and line number. It is the inverse of (src addr).
 
-   EXAMPLES
+   Examples:
 
        #;> (filepc \"/sys/src/cmd/cat.c:5\")
        2097192
@@ -314,11 +326,12 @@
        2097192
        #;> (src 2097192)
        \"/sys/src/cmd/cat.c:5\""
+  :doc-group lsd
   (if line
       (lsd-file2pc f line)
-      (let ((s (str-split f ":")))
+      (let {[s (str-split f ":")]}
         (unless (= (length s) 2) (error "invalid \"file:line\" format"))
-        (let ((line (str->num (cadr s))))
+        (let {[line (str->num (cadr s))]}
           (unless line (error "bad line number"))
           (lsd-file2pc (car s) line)))))
 
@@ -326,17 +339,19 @@
   "Return a symbol from the attached proc's symbol table or NIL.
    Input is a sym.
 
-   EXAMPLES
+   Examples:
 
        #;> (sym-find 'strecpy)
        #(symbol \"strecpy\" #\\T 2276784)"
-  (let* ((find (λ (tbl k) (and (has? tbl k) (get tbl k)))))
-    (or (find (global-text globals) s)
-        (find (global-data globals) s))))
+  :doc-group lsd
+  (def (find tbl k) (and (has? tbl k) (get tbl k)))
+  (or (find (global-text globals) s)
+      (find (global-data globals) s)))
 
 (def (sym-addr s)
   "Return the address of a symbol from the attached proc's
    symbol table or NIL. Input is a sym."
+  :doc-group lsd
   (symbol-addr (sym-global s)))
 
 (add-exit-hook
@@ -353,11 +368,12 @@
    Args will be passed unparsed as the argument vector to
    the executable.
 
-   EXAMPLES
+   Examples:
 
        `(new)`; new process with no arguments
        `(new \"-v\" \"/sys/src/cmd/sl/slmain.c\")`; two arguments."
-  (let ((v (apply lsd-new args)))
+  :doc-group lsd
+  (let {[v (apply lsd-new args)]}
     (when proc-stdin (io-close proc-stdin))
     (set! bptbl (table))
     (set! pid (aref v 0))
@@ -369,10 +385,10 @@
     pid))
 
 (def (lsd a)
-  (let* ((v (lsd-load a))
-         (f (λ (symbol tbl) (put! tbl (sym (symbol-name symbol)) symbol)))
-         (text (foldl f (table) (aref v 3)))
-         (data (foldl f (table) (aref v 4))))
+  (let* {[v (lsd-load a)]
+         [f (λ (symbol tbl) (put! tbl (sym (symbol-name symbol)) symbol))]
+         [text (foldl f (table) (aref v 3))]
+         [data (foldl f (table) (aref v 4))]}
     (set! pid (aref v 0))
     (set! registers (aref v 1))
     (set! bpinst (aref v 2))
@@ -379,6 +395,6 @@
     (set! globals (make-global :text text :data data)))
   (and (>= pid 0) (attach)))
 
-(let* ((proc (cadr *argv*))
-       (pid (str->num proc)))
+(let* {[proc (cadr *argv*)]
+       [pid (str->num proc)]}
   (if pid (lsd pid) (lsd proc)))