-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.lisp
74 lines (70 loc) · 2.16 KB
/
build.lisp
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
(require :parenscript)
;; add 'import' to compiler
(ps:defpsmacro
import (&key default names path)
(when default
(write-string
(concatenate 'string "import "
(ps:symbol-to-js-string default) " from \"" path "\";"))
(fresh-line))
(when names
(write-string "import {")
(loop
for i from 0 to (length names)
for name in names
do
(if (atom name)
(write-string (concatenate 'string " " (ps:symbol-to-js-string name)))
(write-string (concatenate 'string " "
(ps:symbol-to-js-string (car name))
" as "
(ps:symbol-to-js-string (car (cdr name))))))
(write-string ","))
(write-string (concatenate 'string " } from \"" path "\";"))
(fresh-line))
nil)
;; add 'export' to compiler
(ps:defpsmacro
export (&key names default)
(when names
(write-string "export {")
(loop
for i from 0 to (length names)
for name in names
do
(if (atom name)
(write-string (concatenate 'string " " (ps:symbol-to-js-string name)))
(write-string (concatenate 'string " "
(ps:symbol-to-js-string (car name))
" as "
(ps:symbol-to-js-string (car (cdr name))))))
(write-string ","))
(write-string " };")
(fresh-line))
(when default
(write-string (concatenate 'string "export default "
(ps:symbol-to-js-string default) ";"))
(fresh-line))
nil)
(defun ps2js (f)
(in-package :ps)
(do
((form (read f nil) (read f nil)))
((not form))
(format t "/* ~A */~%" form)
(format t "~A~%" (ps:ps* form))))
(defun main (argv)
;; Set internal variable
(format t "~A~%" (ps:ps (defvar *__ps_mv_reg*)))
(pop argv)
(loop for arg in argv do
(let ((probe-results (probe-file arg)))
(when probe-results
(with-open-file
(f arg)
(handler-bind
((error
(lambda (e)
(format *error-output* "~A~%" e)
(sb-ext:exit :code 1))))
(ps2js f)))))))