forked from metawilm/cl-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclpython.asd
More file actions
249 lines (212 loc) · 12.1 KB
/
clpython.asd
File metadata and controls
249 lines (212 loc) · 12.1 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
;; -*- Mode: LISP; Syntax: COMMON-LISP; Package: CL-USER -*-
;;
;; This software is Copyright (c) Franz Inc. and Willem Broekema.
;; Franz Inc. and Willem Broekema grant you the rights to
;; distribute and use this software as governed by the terms
;; of the Lisp Lesser GNU Public License
;; (http://opensource.franz.com/preamble.html),
;; known as the LLGPL.
;;;; ASDF System Definitions
(in-package #:cl-user)
(eval-when (:compile-toplevel)
(error "This ASDF file should be run interpreted."))
;;; CL-Python is split into several ASDF systems, to make it possible to load
;;; specific components -- in particular, to load the compiler or parser without
;;; the runtime environment.
;;;
;;; The main system :CLPYTHON is the sum of all components, including contributions.
(asdf:defsystem :clpython.basic
:description "CLPython package and utils"
:depends-on (:closer-mop)
:serial t
:components ((:file "package")
(:module "util"
:components ((:file "utils")
(:file "readtable")
(:file "macro-state" :depends-on ("utils"))
(:file "patternmatch")))
(:module "shared"
:serial t
:components ((:file "ssetup")
(:file "aureadtable")
(:file "errors")
(:file "aupprint")))))
(asdf:defsystem :clpython.parser
:description "Python parser, code walker, and pretty printer"
:depends-on
#.`(:clpython.basic :closer-mop
#-allegro :yacc
#+allegro ,@(when (asdf:find-system :yacc nil) `(:yacc)))
:components ((:module "parser"
:components ((:file "grammar" )
(:file "lexer" :depends-on ("grammar"))
(:file "parser" :depends-on ("grammar" "lexer"))
(:file "grammar-aclyacc" :depends-on ("grammar" "lexer" "parser"))
(:file "grammar-clyacc" :depends-on ("grammar" "lexer" "parser"))
(:file "ast-util" :depends-on ("grammar"))
(:file "walk" )
(:file "pprint" )))))
(asdf:defsystem :clpython.compiler
:description "Python compiler"
:depends-on (:clpython.basic :clpython.parser :clpython.runtime :closer-mop)
:serial t
:components ((:module "compiler"
:serial t
:components ((:file "csetup" )
(:file "pydecl" )
(:file "namespace" )
(:file "compiler" )
(:file "generator" )
(:file "optimize" )))))
(asdf:defsystem :clpython.runtime
:description "Python runtime environment"
:depends-on (:clpython.basic :closer-mop #+ecl :cl-custom-hash-table :cl-fad)
:components ((:module "runtime"
:serial t
:components ((:file "rsetup" )
(:file "formatstring" )
(:file "metaclass" )
(:file "dictattr" )
(:file "classes" )
(:file "exceptions" )
(:file "habitat" )
(:file "run" )
(:file "import" )))))
(asdf:defsystem :clpython.lib
:description "Python module library"
:depends-on (:clpython.basic :clpython.runtime :clpython.compiler #| TODO: remove compiler dep |#)
:components ((:module "lib"
:serial t
:components ((:file "lsetup")
(:file "builtins-file" :depends-on ("lsetup"))
(:file "builtins-set" :depends-on ("lsetup"))
(:file "builtins-buffer" :depends-on ("lsetup"))
(:file "builtins" :depends-on ("builtins-file" "builtins-set" "builtins-buffer"))
(:file "array" :depends-on ("lsetup"))
(:file "_ast" :depends-on ("lsetup"))
(:file "binascii" :depends-on ("lsetup"))
(:file "_bsddb" :depends-on ("lsetup"))
(:file "_collections" :depends-on ("lsetup"))
(:file "_codecs" :depends-on ("lsetup"))
(:file "cStringIO" :depends-on ("lsetup"))
(:file "datetime" :depends-on ("lsetup"))
(:file "errno" :depends-on ("lsetup"))
(:file "exceptions" :depends-on ("lsetup"))
(:file "_functools" :depends-on ("lsetup"))
(:file "gc" :depends-on ("lsetup"))
(:file "imp" :depends-on ("lsetup"))
(:file "itertools" :depends-on ("lsetup"))
(:file "marshal" :depends-on ("lsetup"))
(:file "math" :depends-on ("lsetup"))
(:file "_md5" :depends-on ("lsetup"))
(:file "operator" :depends-on ("lsetup"))
(:file "posix" :depends-on ("lsetup"))
(:file "_random" :depends-on ("lsetup"))
(:file "re" :depends-on ("lsetup"))
(:file "_sha" :depends-on ("lsetup"))
(:file "_sha256" :depends-on ("lsetup"))
(:file "_sha512" :depends-on ("lsetup"))
(:file "_socket" :depends-on ("lsetup"))
(:file "_sre" :depends-on ("lsetup"))
(:file "_ssl" :depends-on ("lsetup"))
(:file "_struct" :depends-on ("lsetup"))
(:file "sys" :depends-on ("lsetup"))
(:file "string" :depends-on ("lsetup"))
(:file "symbol" :depends-on ("lsetup"))
(:file "thread" :depends-on ("lsetup"))
(:file "time" :depends-on ("lsetup"))
(:file "_weakref" :depends-on ("lsetup"))))))
(asdf:defsystem :clpython.contrib
:description "CLPython contributions and experiments"
:depends-on (:clpython.basic :clpython.runtime :clpython.compiler)
:components ((:module "contrib"
:components ((:file "repl")
(:file "lispy")
(:file "executable" )
#+(or) ;; disable while in development
;; #+(and allegro allegro-version>= (version>= 8 2))
(:file "source" )))))
;;; The main system
(asdf:defsystem :clpython
:description "CLPython - an implementation of Python in Common Lisp"
:depends-on (:clpython.basic :clpython.parser :clpython.runtime :clpython.compiler :clpython.lib :clpython.contrib)
:in-order-to ((asdf:test-op (asdf:load-op :clpython.test))))
;;; Unit test, linked to asdf operation "test-op" on the CL-Python system
(asdf:defsystem :clpython.test
:description "CLPython tests"
:depends-on (:clpython #-allegro :ptester)
:components ((:module "test"
:serial t
:components ((:file "tsetup")
(:file "parser-test")
(:file "compiler-test")
(:file "lang-test")
(:file "function-test")
(:file "mod-builtins-test")
(:file "mod-string-test")
(:file "mod-math-test")
(:file "mod-operator-test")))))
(defmethod asdf:perform :after ((op asdf:test-op) (c (eql (asdf:find-system :clpython))))
(funcall (find-symbol (string '#:run-tests) :clpython.test)))
(defmethod asdf:operation-done-p ((o asdf:test-op)
(c (eql (asdf:find-system :clpython))))
"Testing is never finished."
nil)
;;; In Allegro, which provides its own Yacc, CL-Yacc can optionally be used.
;;; In other implementations, Allegro Yacc is unavailable
(let* ((parser-mod (let ((sys (asdf:find-system :clpython.parser)))
(car (asdf:module-components sys)))))
#+allegro
(let ((cl-yacc-grammar (asdf:find-component parser-mod "grammar-clyacc")))
(defmethod asdf:perform :around ((op asdf:load-op) (c (eql cl-yacc-grammar)))
(when (asdf:find-system :yacc nil)
(call-next-method)))
(defmethod asdf:perform :around ((op asdf:compile-op) (c (eql cl-yacc-grammar)))
(when (asdf:find-system :yacc nil)
(call-next-method))))
#-allegro
(let ((allegro-yacc-grammar (asdf:find-component parser-mod "grammar-aclyacc")))
(defmethod asdf:perform :around ((op asdf:load-op) (c (eql allegro-yacc-grammar)))
nil)
(defmethod asdf:perform :around ((op asdf:compile-op) (c (eql allegro-yacc-grammar)))
nil)))
;;; Suppress some warnings about package trickery
(defmacro suppress-package-warnings (&body body)
`(handler-bind (#+sbcl
(sb-int:package-at-variance #'muffle-warning)
#+lispworks
(simple-warning (lambda (c)
(let ((fmt (slot-value c 'conditions::format-string)))
(when (search "Using DEFPACKAGE" fmt)
(muffle-warning c))))))
,@body))
(let* ((package-file (let ((sys (asdf:find-system :clpython.basic)))
(car (asdf:module-components sys))))
(lib-mod (let ((sys (asdf:find-system :clpython.lib)))
(car (asdf:module-components sys))))
(lib-pkg-file (asdf:find-component lib-mod "psetup"))
(pkg-files (list package-file lib-pkg-file)))
(#+allegro without-redefinition-warnings ;; invalid complaint about method redefinition
#-allegro progn
(dolist (pkg-file pkg-files)
(defmethod asdf:perform :around ((op asdf:compile-op) (c (eql pkg-file)))
(suppress-package-warnings
(call-next-method)))
(defmethod asdf:perform :around ((op asdf:load-op) (c (eql pkg-file)))
(suppress-package-warnings
(call-next-method))))))
;;; Show usage after loading the system
(defun show-clpython-quick-start ()
(format t "~%CLPython quick start guide:~%")
(format t " Run a string of Python code: (~S \"for i in range(4): print i\")~%"
(find-symbol (string '#:run) :clpython))
(format t " Run a Python file: (~S #p\"~~/example/foo.py\")~%"
(find-symbol (string '#:run) :clpython))
(format t " Start the Python \"interpreter\" (REPL): (~S)~%"
(find-symbol (string '#:repl) :clpython.app.repl))
(format t " To start mixed Python/Lisp input mode: (~S)~%"
(find-symbol (string '#:enter-mixed-lisp-python-syntax) :clpython))
(format t " Run the test suite: ~S~%~%"
'(asdf:operate 'asdf:test-op :clpython)))
(defmethod asdf:perform :after ((op asdf:load-op) (c (eql (asdf:find-system :clpython))))
(show-clpython-quick-start))