ref: 0.0.9 beaker/chicken-lint.scm -rw-r--r-- 1.4 KiB View raw
                                                                                
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
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Lint Scheme source files.
;;;
;;; Copyright (c) 2018-2019, Evan Hanson
;;;
;;; See LICENSE for details.
;;;

;;
;; The `chicken-lint` program checks a source file with a set of simple
;; lint rules.
;;
;; Potential problems are written as S-expressions to standard error.
;;
;; Note that this program invokes `csc`, so any compile-time code in the
;; program will be executed.
;;
(declare
  (module (chicken-lint))
  (import (chicken foreign)
          (chicken format)
          (chicken pathname)
          (chicken process)
          (chicken process-context)))

(define (usage status)
  (printf "Usage: ~a [csc-options ...] filename ..." (pathname-file (program-name)))
  (print)
  (exit status))

(define (csc)
  (make-pathname
   (foreign-value "C_TARGET_BIN_HOME" c-string)
   (foreign-value "C_CSC_PROGRAM" c-string)))

(define (csc-options)
  (list "-analyze-only" "-extend" "beaker" "-no-warnings" "-optimize-level" "0"))

(define (analyse-program args)
  (receive (_ _ status) (process-wait (process-run (csc) (append (csc-options) args)))
    (exit status)))

(define (main)
  (let ((args '()))
    ((flip for-each)
     (command-line-arguments)
     (lambda (arg)
       (if (member arg '("-h" "-help" "--help"))
           (usage 0)
           (set! args (cons arg args)))))
    (analyse-program (reverse args))))

(cond-expand
  (compiling (main))
  (else))