This repository was archived by the owner on May 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.lisp
More file actions
162 lines (160 loc) · 9.22 KB
/
Copy pathmodule.lisp
File metadata and controls
162 lines (160 loc) · 9.22 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
(in-package :lcc)
(defun specify-module (def attrs)
(when (> (length attrs) 0) (error (format nil "wrong attributes ~A" attrs)))
(let* ((name (specify-decl-name< (nth 1 def)))
(clauses (nthcdr 2 def))
(module-specifier (make-specifier name '|@MODULE| nil nil nil nil nil nil nil))
(tmp-module-spec *module-spec*)
(tmp-module-path *module-path*))
(setq *module-spec* module-specifier)
(setq *module-path* (append *module-path* (list (name module-specifier))))
(let ((attributes '()))
(dolist (clause clauses)
(if (consp clause)
(let ((construct (car clause)))
(cond ((find (char (symbol-name construct) 0) "@#")
(add-inner (specify-preprocessor clause attributes) module-specifier)
(setq attributes '()))
((key-eq construct '|static|) (push clause attributes))
((key-eq construct '|decl|) (push clause attributes))
((key-eq construct '|inline|) (push clause attributes))
((key-eq construct '|register|) (push clause attributes))
((key-eq construct '|auto|) (push clause attributes))
((key-eq construct '|extern|) (push clause attributes))
((key-eq construct '|include|) (setq attributes '()))
((key-eq construct '|var|)
(add-inner (specify-variable clause attributes) module-specifier)
(setq attributes '()))
((key-eq construct '|func|)
(add-inner (specify-function clause attributes) module-specifier)
(setq attributes '()))
((key-eq construct '|method|)
(add-inner (specify-function clause attributes) module-specifier)
(setq attributes '()))
((key-eq construct '|enum|)
(add-inner (specify-enum clause attributes) module-specifier)
(setq attributes '()))
((key-eq construct '|struct|)
(add-inner (specify-struct clause attributes) module-specifier)
(setq attributes '()))
((key-eq construct '|union|)
(add-inner (specify-union clause attributes) module-specifier)
(setq attributes '()))
((key-eq construct '|module|)
(add-inner (specify-module clause attributes) module-specifier)
(setq attributes '()))
(t (error (format nil "unknown clause ~A in module ~A" construct name)))))
(error (format nil "syntax error ~A" clause)))))
(setq *module-path* tmp-module-path)
(setq *module-spec* tmp-module-spec)
module-specifier))
(defun compile-module (spec lvl globals &key ((:nested is-nested) nil))
(let ((name (name spec)))
(if *target-header*
(progn ; in header file
(maphash #'(lambda (in-name in-spec)
(case (construct in-spec)
('|@VAR| (compile-variable in-spec lvl globals :unique t))
('|@FUNC| (compile-function in-spec lvl globals :unique t))
('|@METHOD| (compile-function in-spec lvl globals :unique t))
('|@PREPROC| (compile-preprocessor in-spec lvl globals))
('|@ENUM| (compile-enum in-spec lvl globals :unique t))
('|@STRUCT| (compile-struct in-spec lvl globals :unique t))
('|@UNION| (compile-union in-spec lvl globals :unique t))
('|@MODULE| (compile-module in-spec lvl globals :nested t))
(otherwise nil)))
(inners spec))
;; (output "~&~A" (indent lvl))
;; (unless is-nested (set-ast-line (output "const ")))
;; (set-ast-line (output "struct "))
;; (if is-nested
;; (set-ast-line (output "~A_module {~%" (unique spec)))
;; (set-ast-line (output "~A_module {~%" name)))
;; (maphash #'(lambda (in-name in-spec)
;; (case (construct in-spec)
;; ('|@VAR| (compile-variable in-spec (1+ lvl) globals))
;; ('|@FUNC| (compile-function in-spec (1+ lvl) globals :type t)
;; (output ";~%"))
;; ('|@METHOD| (compile-function in-spec (1+ lvl) globals :type t)
;; (output ";~%"))
;; ('|@PREPROC| (compile-preprocessor in-spec (1+ lvl) globals))
;; ('|@TYPEDEF| (compile-typedef in-spec (1+ lvl) globals))
;; ('|@ENUM| (compile-enum in-spec (1+ lvl) globals))
;; ('|@STRUCT| (output "~&~A" (indent (1+ lvl)))
;; (output "struct ")
;; (set-ast-line (output "~A " (unique in-spec)))
;; (set-ast-line (output "~A" (name in-spec)))
;; (output ";~%"))
;; ('|@UNION| (output "~&~A" (indent (1+ lvl)))
;; (output "union ")
;; (set-ast-line (output "~A " (unique in-spec)))
;; (set-ast-line (output "~A" (name in-spec)))
;; (output ";~%"))
;; ('|@MODULE| (output "~&~A" (indent (1+ lvl)))
;; (output "struct ")
;; (set-ast-line (output "~A_module " (unique in-spec)))
;; (set-ast-line (output "~A" (name in-spec)))
;; (output ";~%"))
;; (otherwise nil)))
;; (inners spec))
;; (output "~&~A" (indent lvl))
;; (set-ast-line (output "} "))
;; (if is-nested
;; (set-ast-line (output ";~%"))
;; (set-ast-line (output "~A;~%" name)))
)
(progn ; in source file
(maphash #'(lambda (in-name in-spec)
(case (construct in-spec)
('|@VAR| (compile-variable in-spec lvl globals :unique t))
('|@FUNC| (compile-function in-spec lvl globals :unique t))
('|@METHOD| (compile-function in-spec lvl globals :unique t))
('|@PREPROC| (compile-preprocessor in-spec lvl globals))
('|@MODULE| (compile-module in-spec lvl globals :nested t))
(otherwise nil)))
(inners spec))
;; (output "~&~A" (indent lvl))
;; ;; (unless is-nested (set-ast-line (output "typedef ")))
;; (if is-nested
;; (progn
;; (set-ast-line (output "const struct "))
;; (set-ast-line (output "~A_module " (unique spec)))
;; (set-ast-line (output "~A " (unique spec))))
;; (progn
;; (set-ast-line (output "const struct "))
;; (set-ast-line (output "~A_module " name))
;; (set-ast-line (output "~A " name))))
;; (output "= { ~%")
;; (maphash #'(lambda (in-name in-spec)
;; (case (construct in-spec)
;; ('|@VAR| (output "~&~A" (indent (1+ lvl)))
;; (output ".")
;; (set-ast-line (output "~A " (name in-spec)))
;; (output "= ")
;; (set-ast-line (output "~A " (name in-spec)))
;; (output ",~%"))
;; ('|@FUNC| (output "~&~A" (indent (1+ lvl)))
;; (output ".")
;; (set-ast-line (output "~A " (name in-spec)))
;; (output "= ")
;; (set-ast-line (output "~A " (unique in-spec)))
;; (output ",~%"))
;; ('|@METHOD| (let ((name (name in-spec)))
;; (output "~&~A" (indent (1+ lvl)))
;; (output ".")
;; (set-ast-line (output "~A_~A " (car name) (cdr name)))
;; (output "= ")
;; (set-ast-line (output "~A " (unique in-spec)))
;; (output ",~%")))
;; ('|@PREPROC| (compile-preprocessor in-spec (1+ lvl) globals))
;; ('|@MODULE| (output "~&~A" (indent (1+ lvl)))
;; (output ".")
;; (set-ast-line (output "~A " (name in-spec)))
;; (output "= ")
;; (set-ast-line (output "~A " (unique in-spec)))
;; (output ",~%"))
;; (otherwise nil)))
;; (inners spec))
;; (output "~&~A" (indent lvl))
;; (output "};~%")
))))