This commit is contained in:
retropikzel 2026-04-12 15:47:23 +03:00
parent f073d84eb4
commit bf70aa7bab
4 changed files with 33 additions and 33 deletions

View File

@ -41,10 +41,9 @@ test: testfiles
cd .tmp && ./test-program cd .tmp && ./test-program
test-docker: testfiles test-docker: testfiles
cd .tmp && SNOW_PACKAGES="srfi.64 srfi.60 srfi.145 srfi.180 retropikzel.mouth" \ cd .tmp && SNOW_PACKAGES="srfi.39 srfi.64 srfi.60 srfi.145 srfi.180 retropikzel.mouth" \
APT_PACKAGES="libcurl4-openssl-dev" \ APT_PACKAGES="" \
COMPILE_R7RS=${SCHEME} \ COMPILE_R7RS=${SCHEME} \
CSC_OPIONS="-L -lcurl" \
test-r7rs test.${SFX} ${PKG} test-r7rs test.${SFX} ${PKG}
retropikzel/wasm/plus.wasm: retropikzel/wasm/plus.c retropikzel/wasm/plus.wasm: retropikzel/wasm/plus.c

View File

@ -1,29 +1,22 @@
(define show-docstring? (define return (make-parameter (lambda (x) x) (lambda (x) x)))
(make-parameter #f (lambda (x) x)))
(define docstring (define doc-string
(make-parameter (make-parameter
"" ""
(lambda (str) (lambda (x)
(if (show-docstring?) (apply (return) (list x)))))
(error (string-append "docstring:" str))
""))))
;; TODO: stop at like 100 arguments, it means the procedure has no docstring
;; TODO: Change all arguments to procedures that throw errors
;; TODO: Use eval to run the procedure in empty environment so nothing happens if it does not have docstring?
(define (doc procedure) (define (doc procedure)
(letrec* (letrec*
((looper (lambda (args) ((looper
(call-with-current-continuation (lambda (args cont)
(lambda (k) (if (> (length args) 100)
#f
(with-exception-handler (with-exception-handler
(lambda (x) (lambda (x)
(let ((msg (error-object-message x))) (cont (looper (cons (lambda () (error "" '())) args) cont)))
(if (string=? (string-copy msg 0 10) "docstring:")
(k (string-copy msg 10))
(k (looper (cons #t args))))))
(lambda () (lambda ()
(show-docstring? #t) (return cont)
(apply procedure args)))))))) (apply procedure args)))))))
(looper '()))) (call-with-current-continuation (lambda (cont) (looper '() cont)))))

View File

@ -3,7 +3,8 @@
(import (scheme base) (import (scheme base)
(scheme write) (scheme write)
(srfi 39)) (srfi 39))
(export docstring (export doc-string
doc) doc
)
(include "docstring.scm")) (include "docstring.scm"))

View File

@ -1,14 +1,21 @@
;(test-begin "docstring") ;(test-begin "docstring")
(define (plus a b) (define (plus a b)
(docstring "Adds a to b") (doc-string "Add a to b")
(+ a b)) (+ a b))
(plus 1 2)
(write (doc plus)) (define (minus a b)
(- a b))
(write (plus 1 1))
(newline)
(display (doc plus))
(newline) (newline)
(write (minus 1 1))
(newline)
(display (doc minus))
(newline)
;(test-end "docstring") ;(test-end "docstring")