-
Notifications
You must be signed in to change notification settings - Fork 10
/
el-compile
executable file
·80 lines (68 loc) · 2.24 KB
/
el-compile
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
#!/bin/sh
:; exec emacs --quick --script $0 -- "$@"
(setq debug-on-error t)
;; FIXME debug.el says it tries to preserve the start of the stack
;; trace, but in practice I'm not seeing this.
(setq debugger-batch-max-lines 1000)
(defconst elcomp--dir (file-name-directory load-file-name))
(load (expand-file-name "loadup.el" elcomp--dir) nil t)
(elcomp--loadup)
(defun elcomp--skip-comments ()
(while (forward-comment 1)))
(defun elcomp--read-forms ()
(let ((result '()))
(elcomp--skip-comments)
(while (not (eobp))
(push (read (current-buffer)) result)
(elcomp--skip-comments))
result))
(defun elcomp--read-forms-from-file (lisp-file)
(save-excursion
(find-file lisp-file)
(goto-char (point-min))
(elcomp--read-forms)))
(defun elcomp--driver-convert-one (output-file lisp-file)
(message "Reading %s..." lisp-file)
(let ((forms (elcomp--read-forms-from-file lisp-file)))
(let ((unit (make-elcomp--compilation-unit)))
;; FIXME for now we only handle a file full of defuns
;; and eval-when-compile.
(dolist (form forms)
(cl-case (car form)
(eval-when-compile
(eval (cons 'progn (cdr form))))
((defun define-ffi-library define-ffi-function)
(elcomp--plan-to-compile unit form))
(t
(message "Skipping form %S" (car form)))))
(elcomp--translate-all unit)
(elcomp--c-translate unit
(if output-file
(file-name-sans-extension
(file-name-nondirectory output-file)))))))
(defun elcomp--driver-compile (output-file files)
(find-file (or output-file "OUTPUT"))
(setq-local backup-inhibited t)
(erase-buffer)
(dolist (file files)
;; FIXME this only works for a single file
(elcomp--driver-convert-one output-file file))
(save-buffer))
;; FIXME it would be nice to have an argument parsing library in
;; elisp.
(when (equal (car argv) "--")
(pop argv))
(if (equal (car argv) "--help")
(message "Usage: el-compile FILE...")
(let ((filename nil))
(when (equal (car argv) "--output")
(pop argv)
(setf filename (pop argv))
;; Arrange for FFI to be available.
(elcomp--use-ffi))
(elcomp--driver-compile filename
(mapcar #'expand-file-name argv))))
(setf argv nil)
;; Local variables:
;; Mode: emacs-lisp
;; End: