eliscript 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -0
- package/README.md +135 -0
- package/bin/eliscript +16 -0
- package/bin/eliscript-bootstrap +15 -0
- package/bin/eliscript-build +15 -0
- package/bin/eliscript-check +15 -0
- package/bin/eliscript-eval +15 -0
- package/bin/eliscript-format +15 -0
- package/bin/eliscript-org +10 -0
- package/bin/eliscript-portable +17 -0
- package/bin/eliscript-seed +10 -0
- package/bin/eliscript-seed-build +10 -0
- package/bin/eliscript-watch +15 -0
- package/bootstrap/README.md +100 -0
- package/bootstrap/compiler/analyzer.eli +1426 -0
- package/bootstrap/compiler/compiler.eli +472 -0
- package/bootstrap/compiler/emitter.eli +1745 -0
- package/bootstrap/compiler/expander.eli +2522 -0
- package/bootstrap/compiler/formatter.eli +359 -0
- package/bootstrap/compiler/ir.eli +297 -0
- package/bootstrap/compiler/lower.eli +661 -0
- package/bootstrap/compiler/project.eli +1120 -0
- package/bootstrap/compiler/reader.eli +321 -0
- package/bootstrap/compiler/source-map.eli +165 -0
- package/bootstrap/compiler/symbol.eli +92 -0
- package/bootstrap/compiler/syntax.eli +54 -0
- package/bootstrap/compiler/transient-analysis.eli +825 -0
- package/bootstrap/host/build.mjs +28 -0
- package/bootstrap/host/bun.mjs +282 -0
- package/bootstrap/host/check-cli.mjs +163 -0
- package/bootstrap/host/eliscript-cli.mjs +36 -0
- package/bootstrap/host/evaluation-cli.mjs +401 -0
- package/bootstrap/host/evaluation.mjs +560 -0
- package/bootstrap/host/format-cli.mjs +139 -0
- package/bootstrap/host/project-cli.mjs +295 -0
- package/bootstrap/host/project.mjs +1080 -0
- package/bootstrap/host/watch-cli.mjs +129 -0
- package/bootstrap/host/watch.mjs +267 -0
- package/browser/host.mjs +357 -0
- package/browser/worker.mjs +60 -0
- package/compiler/README.md +118 -0
- package/compiler/eliscript-analyzer.el +716 -0
- package/compiler/eliscript-cli.el +108 -0
- package/compiler/eliscript-diagnostic.el +158 -0
- package/compiler/eliscript-emitter.el +1351 -0
- package/compiler/eliscript-evaluation.el +259 -0
- package/compiler/eliscript-expander.el +1630 -0
- package/compiler/eliscript-form.el +79 -0
- package/compiler/eliscript-ir-emitter.el +1460 -0
- package/compiler/eliscript-ir.el +356 -0
- package/compiler/eliscript-lower.el +463 -0
- package/compiler/eliscript-macro-eval.el +811 -0
- package/compiler/eliscript-parameters.el +324 -0
- package/compiler/eliscript-portable.el +492 -0
- package/compiler/eliscript-project-cli.el +156 -0
- package/compiler/eliscript-project.el +1676 -0
- package/compiler/eliscript-reader.el +421 -0
- package/compiler/eliscript-source-map.el +192 -0
- package/compiler/eliscript-symbol.el +101 -0
- package/compiler/eliscript-transient-analysis.el +817 -0
- package/compiler/eliscript.el +239 -0
- package/dist/bootstrap/analyzer.mjs +968 -0
- package/dist/bootstrap/analyzer.mjs.map +1 -0
- package/dist/bootstrap/compiler.mjs +228 -0
- package/dist/bootstrap/compiler.mjs.map +1 -0
- package/dist/bootstrap/emitter.mjs +1173 -0
- package/dist/bootstrap/emitter.mjs.map +1 -0
- package/dist/bootstrap/expander.mjs +1469 -0
- package/dist/bootstrap/expander.mjs.map +1 -0
- package/dist/bootstrap/formatter.mjs +304 -0
- package/dist/bootstrap/formatter.mjs.map +1 -0
- package/dist/bootstrap/ir.mjs +193 -0
- package/dist/bootstrap/ir.mjs.map +1 -0
- package/dist/bootstrap/lower.mjs +344 -0
- package/dist/bootstrap/lower.mjs.map +1 -0
- package/dist/bootstrap/project.mjs +585 -0
- package/dist/bootstrap/project.mjs.map +1 -0
- package/dist/bootstrap/reader.mjs +259 -0
- package/dist/bootstrap/reader.mjs.map +1 -0
- package/dist/bootstrap/source-map.mjs +154 -0
- package/dist/bootstrap/source-map.mjs.map +1 -0
- package/dist/bootstrap/symbol.mjs +74 -0
- package/dist/bootstrap/symbol.mjs.map +1 -0
- package/dist/bootstrap/syntax.mjs +38 -0
- package/dist/bootstrap/syntax.mjs.map +1 -0
- package/dist/bootstrap/transient-analysis.mjs +660 -0
- package/dist/bootstrap/transient-analysis.mjs.map +1 -0
- package/dist/browser/compiler.js +6491 -0
- package/editor/README.md +83 -0
- package/editor/eliscript-mode.el +878 -0
- package/editor/eliscript-repl.el +501 -0
- package/package.json +163 -0
- package/platform/README.md +48 -0
- package/platform/browser.mjs +204 -0
- package/platform/worker.mjs +166 -0
- package/runtime/README.md +296 -0
- package/runtime/core/collection-internals.mjs +512 -0
- package/runtime/core/collection.mjs +645 -0
- package/runtime/core/data-text.mjs +532 -0
- package/runtime/core/data.mjs +268 -0
- package/runtime/core/identifier.mjs +314 -0
- package/runtime/core/lazy-sequence.mjs +244 -0
- package/runtime/core/list-internals.mjs +18 -0
- package/runtime/core/list.mjs +273 -0
- package/runtime/core/map-internals.mjs +793 -0
- package/runtime/core/map.mjs +394 -0
- package/runtime/core/metadata-internals.mjs +14 -0
- package/runtime/core/metadata.mjs +44 -0
- package/runtime/core/object-impl.mjs +65 -0
- package/runtime/core/object-impl.mjs.map +1 -0
- package/runtime/core/object.mjs +13 -0
- package/runtime/core/order.mjs +234 -0
- package/runtime/core/persistent-kind.mjs +43 -0
- package/runtime/core/protocol-error.mjs +36 -0
- package/runtime/core/protocol-impl.mjs +326 -0
- package/runtime/core/protocol-impl.mjs.map +1 -0
- package/runtime/core/protocol.mjs +14 -0
- package/runtime/core/queue-internals.mjs +27 -0
- package/runtime/core/queue.mjs +238 -0
- package/runtime/core/record.mjs +346 -0
- package/runtime/core/regex.mjs +184 -0
- package/runtime/core/sequence.mjs +632 -0
- package/runtime/core/set-algebra.mjs +287 -0
- package/runtime/core/set-internals.mjs +33 -0
- package/runtime/core/set.mjs +378 -0
- package/runtime/core/sorted-internals.mjs +215 -0
- package/runtime/core/sorted.mjs +598 -0
- package/runtime/core/text-impl.mjs +95 -0
- package/runtime/core/text-impl.mjs.map +1 -0
- package/runtime/core/text.mjs +15 -0
- package/runtime/core/transducer.mjs +668 -0
- package/runtime/core/transient-internals.mjs +38 -0
- package/runtime/core/transient.mjs +53 -0
- package/runtime/core/truth.mjs +3 -0
- package/runtime/core/type.mjs +262 -0
- package/runtime/core/value-internals.mjs +188 -0
- package/runtime/core/value.mjs +93 -0
- package/runtime/core/vector-internals.mjs +102 -0
- package/runtime/core/vector.mjs +951 -0
- package/runtime/literals.mjs +34 -0
- package/runtime/source-mapping.mjs +220 -0
- package/runtime/testing/list.mjs +52 -0
- package/runtime/testing/map.mjs +145 -0
- package/runtime/testing/queue.mjs +49 -0
- package/runtime/testing/set.mjs +61 -0
- package/runtime/testing/sorted.mjs +105 -0
- package/runtime/testing/value.mjs +17 -0
- package/runtime/testing/vector.mjs +102 -0
- package/runtime/worker-value-codec.mjs +565 -0
- package/runtime/worker-value-stream.mjs +786 -0
- package/runtime/worker.mjs +975 -0
- package/stdlib/README.md +774 -0
- package/stdlib/bit.eli +36 -0
- package/stdlib/core/collection.eli +134 -0
- package/stdlib/core/data-text.eli +16 -0
- package/stdlib/core/data.eli +306 -0
- package/stdlib/core/identifier.eli +32 -0
- package/stdlib/core/lazy-sequence.eli +63 -0
- package/stdlib/core/metadata.eli +20 -0
- package/stdlib/core/object.eli +89 -0
- package/stdlib/core/order.eli +133 -0
- package/stdlib/core/protocol.eli +387 -0
- package/stdlib/core/record.eli +16 -0
- package/stdlib/core/regex.eli +17 -0
- package/stdlib/core/seq.eli +701 -0
- package/stdlib/core/set.eli +312 -0
- package/stdlib/core/sorted.eli +53 -0
- package/stdlib/core/text.eli +103 -0
- package/stdlib/core/transducer.eli +59 -0
- package/stdlib/core/transient.eli +24 -0
- package/stdlib/core/type.eli +19 -0
- package/stdlib/core/walk.eli +195 -0
- package/stdlib/core/zipper.eli +508 -0
- package/stdlib/data-text.eli +1092 -0
- package/stdlib/data.eli +42 -0
- package/stdlib/deferred.eli +70 -0
- package/stdlib/function.eli +120 -0
- package/stdlib/hierarchy.eli +245 -0
- package/stdlib/identifier.eli +147 -0
- package/stdlib/interop/js.eli +616 -0
- package/stdlib/json.eli +870 -0
- package/stdlib/metadata.eli +56 -0
- package/stdlib/multimethod.eli +464 -0
- package/stdlib/numeric.eli +193 -0
- package/stdlib/object.eli +96 -0
- package/stdlib/persistent-list.eli +145 -0
- package/stdlib/persistent-map.eli +724 -0
- package/stdlib/persistent-queue.eli +32 -0
- package/stdlib/persistent-set.eli +236 -0
- package/stdlib/persistent-vector.eli +342 -0
- package/stdlib/result.eli +141 -0
- package/stdlib/sequence.eli +106 -0
- package/stdlib/state/atom.eli +265 -0
- package/stdlib/text.eli +88 -0
- package/stdlib/value.eli +325 -0
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
;;; eliscript-portable.el --- Portable function validation -*- lexical-binding: t; -*-
|
|
2
|
+
|
|
3
|
+
;;; Commentary:
|
|
4
|
+
|
|
5
|
+
;; Portable declarations form a closed, statically checked subset suitable for
|
|
6
|
+
;; execution in a JavaScript worker over explicit versioned transport values.
|
|
7
|
+
|
|
8
|
+
;;; Code:
|
|
9
|
+
|
|
10
|
+
(require 'cl-lib)
|
|
11
|
+
(require 'eliscript-diagnostic)
|
|
12
|
+
(require 'eliscript-form)
|
|
13
|
+
(require 'eliscript-parameters)
|
|
14
|
+
|
|
15
|
+
(cl-defstruct (eliscript-portable--declaration
|
|
16
|
+
(:constructor eliscript-portable--declaration-create))
|
|
17
|
+
name
|
|
18
|
+
kind
|
|
19
|
+
form
|
|
20
|
+
initializer
|
|
21
|
+
parameters
|
|
22
|
+
body)
|
|
23
|
+
|
|
24
|
+
(defconst eliscript-portable--operators
|
|
25
|
+
'(if when unless progn do while and or not
|
|
26
|
+
+ * - / % mod = /= not= < <= > >= 1+ 1-
|
|
27
|
+
int32 uint32 imul32 bit-and bit-or bit-xor bit-not
|
|
28
|
+
bit-shift-left bit-shift-right unsigned-bit-shift-right
|
|
29
|
+
value-type host-identity-token string-code-unit-at string-from-code-unit
|
|
30
|
+
string-to-number string-to-bigint number-float64-words
|
|
31
|
+
eq equal null nil? undefined? nullish?
|
|
32
|
+
list vector hash-map hash-set js-array car cdr cons js-cons nth js-nth aref
|
|
33
|
+
length js-length
|
|
34
|
+
object-keys object-has? object-assoc __eliscript_arity_error
|
|
35
|
+
str funcall apply js-object get cond lambda fn let let* setq set!
|
|
36
|
+
quote))
|
|
37
|
+
|
|
38
|
+
(defconst eliscript-portable--forbidden-operators
|
|
39
|
+
'((js* . "raw JavaScript")
|
|
40
|
+
(print . "console output")
|
|
41
|
+
(put . "object mutation")
|
|
42
|
+
(js-call . "host method calls")
|
|
43
|
+
(new . "host constructors")
|
|
44
|
+
(async . "asynchronous functions")
|
|
45
|
+
(await . "asynchronous suspension")
|
|
46
|
+
(throw . "exception control flow")
|
|
47
|
+
(try . "exception control flow")))
|
|
48
|
+
|
|
49
|
+
(defvar eliscript-portable--filename nil)
|
|
50
|
+
(defvar eliscript-portable--entry nil)
|
|
51
|
+
(defvar eliscript-portable--current-span nil)
|
|
52
|
+
|
|
53
|
+
(defun eliscript-portable--fail (format-string &rest arguments)
|
|
54
|
+
"Signal a portable analysis error using FORMAT-STRING and ARGUMENTS."
|
|
55
|
+
(apply #'eliscript-diagnostic-signal
|
|
56
|
+
'eliscript-analyze-error "ELI-P0001" "portable-analysis"
|
|
57
|
+
eliscript-portable--filename eliscript-portable--current-span
|
|
58
|
+
format-string arguments))
|
|
59
|
+
|
|
60
|
+
(defun eliscript-portable--value (form)
|
|
61
|
+
"Return the reader value represented by FORM."
|
|
62
|
+
(eliscript-form-value form))
|
|
63
|
+
|
|
64
|
+
(defun eliscript-portable--flatten (forms)
|
|
65
|
+
"Return top-level FORMS with module wrappers removed."
|
|
66
|
+
(apply
|
|
67
|
+
#'append
|
|
68
|
+
(mapcar
|
|
69
|
+
(lambda (form)
|
|
70
|
+
(let ((value (eliscript-portable--value form)))
|
|
71
|
+
(if (and (consp value)
|
|
72
|
+
(eq (eliscript-portable--value (car value)) 'module))
|
|
73
|
+
(eliscript-portable--flatten (cddr value))
|
|
74
|
+
(list form))))
|
|
75
|
+
forms)))
|
|
76
|
+
|
|
77
|
+
(defun eliscript-portable--declarations (forms)
|
|
78
|
+
"Collect portable-relevant declarations from FORMS."
|
|
79
|
+
(let ((table (make-hash-table :test #'eq)))
|
|
80
|
+
(dolist (form (eliscript-portable--flatten forms))
|
|
81
|
+
(let ((value (eliscript-portable--value form)))
|
|
82
|
+
(when (consp value)
|
|
83
|
+
(let ((operator (eliscript-portable--value (car value)))
|
|
84
|
+
(arguments (cdr value)))
|
|
85
|
+
(pcase operator
|
|
86
|
+
('defconst
|
|
87
|
+
(puthash
|
|
88
|
+
(eliscript-portable--value (car arguments))
|
|
89
|
+
(eliscript-portable--declaration-create
|
|
90
|
+
:name (eliscript-portable--value (car arguments))
|
|
91
|
+
:kind 'constant :form form :initializer (cadr arguments))
|
|
92
|
+
table))
|
|
93
|
+
('defvar
|
|
94
|
+
(puthash
|
|
95
|
+
(eliscript-portable--value (car arguments))
|
|
96
|
+
(eliscript-portable--declaration-create
|
|
97
|
+
:name (eliscript-portable--value (car arguments))
|
|
98
|
+
:kind 'variable :form form :initializer (cadr arguments))
|
|
99
|
+
table))
|
|
100
|
+
((or 'defun 'defn 'defportable 'defasync)
|
|
101
|
+
(puthash
|
|
102
|
+
(eliscript-portable--value (car arguments))
|
|
103
|
+
(eliscript-portable--declaration-create
|
|
104
|
+
:name (eliscript-portable--value (car arguments))
|
|
105
|
+
:kind (if (eq operator 'defportable) 'portable 'function)
|
|
106
|
+
:form form
|
|
107
|
+
:parameters (cadr arguments)
|
|
108
|
+
:body (cddr arguments))
|
|
109
|
+
table))
|
|
110
|
+
('import
|
|
111
|
+
(dolist (name (eliscript-portable--import-names arguments))
|
|
112
|
+
(puthash
|
|
113
|
+
name
|
|
114
|
+
(eliscript-portable--declaration-create
|
|
115
|
+
:name name :kind 'import :form form)
|
|
116
|
+
table)))
|
|
117
|
+
('import-portable
|
|
118
|
+
(dolist (name (eliscript-portable--import-names arguments))
|
|
119
|
+
(puthash
|
|
120
|
+
name
|
|
121
|
+
(eliscript-portable--declaration-create
|
|
122
|
+
:name name :kind 'portable-import :form form)
|
|
123
|
+
table))))))))
|
|
124
|
+
table))
|
|
125
|
+
|
|
126
|
+
(defun eliscript-portable--import-names (arguments)
|
|
127
|
+
"Return local import names from import ARGUMENTS."
|
|
128
|
+
(let ((specifiers (cdr arguments))
|
|
129
|
+
names)
|
|
130
|
+
(while specifiers
|
|
131
|
+
(let ((specifier (eliscript-portable--value (pop specifiers))))
|
|
132
|
+
(if (memq specifier '(:default :as))
|
|
133
|
+
(push (eliscript-portable--value (pop specifiers)) names)
|
|
134
|
+
(push specifier names))))
|
|
135
|
+
names))
|
|
136
|
+
|
|
137
|
+
(defun eliscript-portable--local-scope (&optional names)
|
|
138
|
+
"Create a local-name table initialized with NAMES."
|
|
139
|
+
(let ((scope (make-hash-table :test #'eq)))
|
|
140
|
+
(dolist (name names)
|
|
141
|
+
(puthash (eliscript-portable--value name) t scope))
|
|
142
|
+
scope))
|
|
143
|
+
|
|
144
|
+
(defun eliscript-portable--copy-scope (scope)
|
|
145
|
+
"Return a shallow copy of local SCOPE."
|
|
146
|
+
(copy-hash-table scope))
|
|
147
|
+
|
|
148
|
+
(defun eliscript-portable--parameter-forms (parameters)
|
|
149
|
+
"Return binding forms from function PARAMETERS."
|
|
150
|
+
(apply
|
|
151
|
+
#'append
|
|
152
|
+
(mapcar
|
|
153
|
+
(lambda (parameter)
|
|
154
|
+
(eliscript-binding-names
|
|
155
|
+
(eliscript-parameter-form parameter)
|
|
156
|
+
(lambda (_form message) (eliscript-portable--fail "%s" message))))
|
|
157
|
+
(eliscript-parameters-parse
|
|
158
|
+
parameters
|
|
159
|
+
(lambda (_form message) (eliscript-portable--fail "%s" message))))))
|
|
160
|
+
|
|
161
|
+
(defun eliscript-portable--binding-name (binding)
|
|
162
|
+
"Return the target form from lexical BINDING."
|
|
163
|
+
(if (eliscript-binding-pattern-p binding)
|
|
164
|
+
binding
|
|
165
|
+
(car (eliscript-portable--value binding))))
|
|
166
|
+
|
|
167
|
+
(defun eliscript-portable--add-pattern (pattern scope)
|
|
168
|
+
"Add every name in binding PATTERN to portable SCOPE."
|
|
169
|
+
(dolist
|
|
170
|
+
(name
|
|
171
|
+
(eliscript-binding-names
|
|
172
|
+
pattern
|
|
173
|
+
(lambda (_form message) (eliscript-portable--fail "%s" message))))
|
|
174
|
+
(puthash (eliscript-portable--value name) t scope)))
|
|
175
|
+
|
|
176
|
+
(defun eliscript-portable--binding-value (binding)
|
|
177
|
+
"Return the initializer from lexical BINDING, or nil."
|
|
178
|
+
(let ((value (eliscript-portable--value binding)))
|
|
179
|
+
(and (consp value) (cadr value))))
|
|
180
|
+
|
|
181
|
+
(defun eliscript-portable--pattern-defaults
|
|
182
|
+
(pattern scope declarations dependencies)
|
|
183
|
+
"Validate defaults nested in PATTERN using portable lexical SCOPE."
|
|
184
|
+
(dolist
|
|
185
|
+
(default
|
|
186
|
+
(eliscript-binding-defaults
|
|
187
|
+
pattern
|
|
188
|
+
(lambda (_form message) (eliscript-portable--fail "%s" message))))
|
|
189
|
+
(eliscript-portable--expression default scope declarations dependencies)))
|
|
190
|
+
|
|
191
|
+
(defun eliscript-portable--reference
|
|
192
|
+
(form scope declarations dependencies)
|
|
193
|
+
"Validate symbol FORM and record it in DEPENDENCIES when top-level."
|
|
194
|
+
(let ((name (eliscript-portable--value form)))
|
|
195
|
+
(unless (gethash name scope)
|
|
196
|
+
(when (string-match-p "[./]" (symbol-name name))
|
|
197
|
+
(eliscript-portable--fail
|
|
198
|
+
"portable function %s uses qualified host reference: %s"
|
|
199
|
+
eliscript-portable--entry name))
|
|
200
|
+
(let ((declaration (gethash name declarations)))
|
|
201
|
+
(when declaration
|
|
202
|
+
(pcase (eliscript-portable--declaration-kind declaration)
|
|
203
|
+
((or 'portable 'constant 'portable-import)
|
|
204
|
+
(puthash name t dependencies))
|
|
205
|
+
(kind
|
|
206
|
+
(eliscript-portable--fail
|
|
207
|
+
"portable function %s depends on non-portable %s: %s"
|
|
208
|
+
eliscript-portable--entry kind name))))))))
|
|
209
|
+
|
|
210
|
+
(defun eliscript-portable--expression
|
|
211
|
+
(form scope declarations dependencies)
|
|
212
|
+
"Validate portable expression FORM in lexical SCOPE."
|
|
213
|
+
(when form
|
|
214
|
+
(let* ((eliscript-portable--current-span
|
|
215
|
+
(or (eliscript-form-span form) eliscript-portable--current-span))
|
|
216
|
+
(value (eliscript-portable--value form)))
|
|
217
|
+
(cond
|
|
218
|
+
((or (null value) (eq value t) (numberp value) (stringp value)
|
|
219
|
+
(memq value '(false undefined))) nil)
|
|
220
|
+
((keywordp value) nil)
|
|
221
|
+
((symbolp value)
|
|
222
|
+
(eliscript-portable--reference form scope declarations dependencies))
|
|
223
|
+
((vectorp value)
|
|
224
|
+
(eliscript-portable--sequence
|
|
225
|
+
(append value nil) scope declarations dependencies))
|
|
226
|
+
((consp value)
|
|
227
|
+
(eliscript-portable--call form scope declarations dependencies))))))
|
|
228
|
+
|
|
229
|
+
(defun eliscript-portable--sequence
|
|
230
|
+
(forms scope declarations dependencies)
|
|
231
|
+
"Validate portable FORMS in lexical SCOPE."
|
|
232
|
+
(dolist (form forms)
|
|
233
|
+
(eliscript-portable--expression form scope declarations dependencies)))
|
|
234
|
+
|
|
235
|
+
(defun eliscript-portable--function
|
|
236
|
+
(arguments scope declarations dependencies)
|
|
237
|
+
"Validate a lambda-like ARGUMENT list."
|
|
238
|
+
(let* ((parameters (eliscript-portable--parameter-forms (car arguments)))
|
|
239
|
+
(child (eliscript-portable--copy-scope scope)))
|
|
240
|
+
(dolist (parameter
|
|
241
|
+
(eliscript-parameters-parse
|
|
242
|
+
(car arguments)
|
|
243
|
+
(lambda (_form message) (eliscript-portable--fail "%s" message))))
|
|
244
|
+
(eliscript-portable--pattern-defaults
|
|
245
|
+
(eliscript-parameter-form parameter) scope declarations dependencies))
|
|
246
|
+
(dolist (parameter parameters)
|
|
247
|
+
(puthash (eliscript-portable--value parameter) t child))
|
|
248
|
+
(eliscript-portable--sequence
|
|
249
|
+
(cdr arguments) child declarations dependencies)))
|
|
250
|
+
|
|
251
|
+
(defun eliscript-portable--let
|
|
252
|
+
(arguments scope sequential declarations dependencies)
|
|
253
|
+
"Validate let ARGUMENTS, honoring SEQUENTIAL binding visibility."
|
|
254
|
+
(let* ((bindings (eliscript-portable--value (car arguments)))
|
|
255
|
+
(child (eliscript-portable--copy-scope scope)))
|
|
256
|
+
(if sequential
|
|
257
|
+
(dolist (binding bindings)
|
|
258
|
+
(eliscript-portable--expression
|
|
259
|
+
(eliscript-portable--binding-value binding)
|
|
260
|
+
child declarations dependencies)
|
|
261
|
+
(eliscript-portable--pattern-defaults
|
|
262
|
+
(eliscript-portable--binding-name binding)
|
|
263
|
+
child declarations dependencies)
|
|
264
|
+
(eliscript-portable--add-pattern
|
|
265
|
+
(eliscript-portable--binding-name binding) child))
|
|
266
|
+
(progn
|
|
267
|
+
(dolist (binding bindings)
|
|
268
|
+
(eliscript-portable--expression
|
|
269
|
+
(eliscript-portable--binding-value binding)
|
|
270
|
+
scope declarations dependencies))
|
|
271
|
+
(dolist (binding bindings)
|
|
272
|
+
(eliscript-portable--pattern-defaults
|
|
273
|
+
(eliscript-portable--binding-name binding)
|
|
274
|
+
scope declarations dependencies))
|
|
275
|
+
(dolist (binding bindings)
|
|
276
|
+
(eliscript-portable--add-pattern
|
|
277
|
+
(eliscript-portable--binding-name binding) child))))
|
|
278
|
+
(eliscript-portable--sequence
|
|
279
|
+
(cdr arguments) child declarations dependencies)))
|
|
280
|
+
|
|
281
|
+
(defun eliscript-portable--assignment
|
|
282
|
+
(arguments scope declarations dependencies)
|
|
283
|
+
"Validate assignment ARGUMENTS as local-only mutation."
|
|
284
|
+
(while arguments
|
|
285
|
+
(let* ((name-form (pop arguments))
|
|
286
|
+
(name (eliscript-portable--value name-form))
|
|
287
|
+
(value (pop arguments)))
|
|
288
|
+
(unless (gethash name scope)
|
|
289
|
+
(let ((eliscript-portable--current-span
|
|
290
|
+
(or (eliscript-form-span name-form)
|
|
291
|
+
eliscript-portable--current-span)))
|
|
292
|
+
(eliscript-portable--fail
|
|
293
|
+
"portable function %s may only assign local bindings: %s"
|
|
294
|
+
eliscript-portable--entry name)))
|
|
295
|
+
(eliscript-portable--expression
|
|
296
|
+
value scope declarations dependencies))))
|
|
297
|
+
|
|
298
|
+
(defun eliscript-portable--object
|
|
299
|
+
(arguments scope declarations dependencies)
|
|
300
|
+
"Validate object ARGUMENTS without treating literal keys as references."
|
|
301
|
+
(while arguments
|
|
302
|
+
(let* ((key (pop arguments))
|
|
303
|
+
(key-value (eliscript-portable--value key))
|
|
304
|
+
(value (pop arguments)))
|
|
305
|
+
(unless (or (keywordp key-value) (stringp key-value)
|
|
306
|
+
(symbolp key-value))
|
|
307
|
+
(eliscript-portable--expression
|
|
308
|
+
key scope declarations dependencies))
|
|
309
|
+
(eliscript-portable--expression
|
|
310
|
+
value scope declarations dependencies))))
|
|
311
|
+
|
|
312
|
+
(defun eliscript-portable--host-key-call
|
|
313
|
+
(arguments scope declarations dependencies)
|
|
314
|
+
"Validate host-key ARGUMENTS while keeping Keyword keys syntactic."
|
|
315
|
+
(cl-loop
|
|
316
|
+
for argument in arguments
|
|
317
|
+
for index from 0
|
|
318
|
+
unless (and (= index 1)
|
|
319
|
+
(keywordp (eliscript-portable--value argument)))
|
|
320
|
+
do (eliscript-portable--expression
|
|
321
|
+
argument scope declarations dependencies)))
|
|
322
|
+
|
|
323
|
+
(defun eliscript-portable--call (form scope declarations dependencies)
|
|
324
|
+
"Validate portable call FORM."
|
|
325
|
+
(let* ((items (eliscript-portable--value form))
|
|
326
|
+
(operator-form (car items))
|
|
327
|
+
(operator (eliscript-portable--value operator-form))
|
|
328
|
+
(arguments (cdr items))
|
|
329
|
+
(forbidden (and (symbolp operator)
|
|
330
|
+
(assq operator
|
|
331
|
+
eliscript-portable--forbidden-operators))))
|
|
332
|
+
(when forbidden
|
|
333
|
+
(eliscript-portable--fail
|
|
334
|
+
"portable function %s cannot use %s (%s)"
|
|
335
|
+
eliscript-portable--entry operator (cdr forbidden)))
|
|
336
|
+
(pcase operator
|
|
337
|
+
('quote nil)
|
|
338
|
+
((or 'lambda 'fn)
|
|
339
|
+
(eliscript-portable--function
|
|
340
|
+
arguments scope declarations dependencies))
|
|
341
|
+
('let
|
|
342
|
+
(eliscript-portable--let
|
|
343
|
+
arguments scope nil declarations dependencies))
|
|
344
|
+
('let*
|
|
345
|
+
(eliscript-portable--let
|
|
346
|
+
arguments scope t declarations dependencies))
|
|
347
|
+
((or 'setq 'set!)
|
|
348
|
+
(eliscript-portable--assignment
|
|
349
|
+
arguments scope declarations dependencies))
|
|
350
|
+
('js-object
|
|
351
|
+
(eliscript-portable--object
|
|
352
|
+
arguments scope declarations dependencies))
|
|
353
|
+
((or 'get 'aref 'object-has? 'object-assoc)
|
|
354
|
+
(eliscript-portable--host-key-call
|
|
355
|
+
arguments scope declarations dependencies))
|
|
356
|
+
((pred (lambda (name) (memq name eliscript-portable--operators)))
|
|
357
|
+
(eliscript-portable--sequence
|
|
358
|
+
arguments scope declarations dependencies))
|
|
359
|
+
(_
|
|
360
|
+
(eliscript-portable--expression
|
|
361
|
+
operator-form scope declarations dependencies)
|
|
362
|
+
(eliscript-portable--sequence
|
|
363
|
+
arguments scope declarations dependencies)))))
|
|
364
|
+
|
|
365
|
+
(defun eliscript-portable--dependencies (declaration declarations)
|
|
366
|
+
"Return validated direct dependencies for DECLARATION."
|
|
367
|
+
(let* ((eliscript-portable--entry
|
|
368
|
+
(eliscript-portable--declaration-name declaration))
|
|
369
|
+
(eliscript-portable--current-span
|
|
370
|
+
(eliscript-form-span (eliscript-portable--declaration-form declaration)))
|
|
371
|
+
(dependencies (make-hash-table :test #'eq))
|
|
372
|
+
(scope
|
|
373
|
+
(eliscript-portable--local-scope
|
|
374
|
+
(eliscript-portable--parameter-forms
|
|
375
|
+
(eliscript-portable--declaration-parameters declaration)))))
|
|
376
|
+
(pcase (eliscript-portable--declaration-kind declaration)
|
|
377
|
+
('portable
|
|
378
|
+
(eliscript-portable--sequence
|
|
379
|
+
(eliscript-portable--declaration-body declaration)
|
|
380
|
+
scope declarations dependencies))
|
|
381
|
+
('constant
|
|
382
|
+
(eliscript-portable--expression
|
|
383
|
+
(eliscript-portable--declaration-initializer declaration)
|
|
384
|
+
scope declarations dependencies)))
|
|
385
|
+
(let (names)
|
|
386
|
+
(maphash (lambda (name _present) (push name names)) dependencies)
|
|
387
|
+
(nreverse names))))
|
|
388
|
+
|
|
389
|
+
(defun eliscript-portable--closure
|
|
390
|
+
(forms entries filename &optional allow-portable-imports)
|
|
391
|
+
"Validate ENTRIES in FORMS and return their transitive declaration names.
|
|
392
|
+
|
|
393
|
+
ALLOW-PORTABLE-IMPORTS defers cross-module proof to the project builder."
|
|
394
|
+
(let* ((eliscript-portable--filename filename)
|
|
395
|
+
(declarations (eliscript-portable--declarations forms))
|
|
396
|
+
(visited (make-hash-table :test #'eq))
|
|
397
|
+
closure)
|
|
398
|
+
(cl-labels
|
|
399
|
+
((visit
|
|
400
|
+
(name root)
|
|
401
|
+
(unless (gethash name visited)
|
|
402
|
+
(puthash name t visited)
|
|
403
|
+
(let ((declaration (gethash name declarations)))
|
|
404
|
+
(unless declaration
|
|
405
|
+
(setq eliscript-portable--entry root)
|
|
406
|
+
(eliscript-portable--fail
|
|
407
|
+
"unknown portable entry: %s" name))
|
|
408
|
+
(unless (memq (eliscript-portable--declaration-kind declaration)
|
|
409
|
+
'(portable constant portable-import))
|
|
410
|
+
(setq eliscript-portable--entry root
|
|
411
|
+
eliscript-portable--current-span
|
|
412
|
+
(eliscript-form-span
|
|
413
|
+
(eliscript-portable--declaration-form declaration)))
|
|
414
|
+
(eliscript-portable--fail
|
|
415
|
+
"portable entry %s is not declared with defportable" name))
|
|
416
|
+
(when (and (eq (eliscript-portable--declaration-kind declaration)
|
|
417
|
+
'portable-import)
|
|
418
|
+
(not allow-portable-imports))
|
|
419
|
+
(setq eliscript-portable--entry root
|
|
420
|
+
eliscript-portable--current-span
|
|
421
|
+
(eliscript-form-span
|
|
422
|
+
(eliscript-portable--declaration-form declaration)))
|
|
423
|
+
(eliscript-portable--fail
|
|
424
|
+
"portable import %s requires a project build" name))
|
|
425
|
+
(push name closure)
|
|
426
|
+
(dolist (dependency
|
|
427
|
+
(eliscript-portable--dependencies
|
|
428
|
+
declaration declarations))
|
|
429
|
+
(visit dependency root))))))
|
|
430
|
+
(dolist (entry entries)
|
|
431
|
+
(let ((declaration (gethash entry declarations)))
|
|
432
|
+
(unless (and declaration
|
|
433
|
+
(eq (eliscript-portable--declaration-kind declaration)
|
|
434
|
+
'portable))
|
|
435
|
+
(setq eliscript-portable--entry entry)
|
|
436
|
+
(eliscript-portable--fail
|
|
437
|
+
"portable entry %s is not declared with defportable" entry)))
|
|
438
|
+
(visit entry entry)))
|
|
439
|
+
(nreverse closure)))
|
|
440
|
+
|
|
441
|
+
(defun eliscript-portable-validate-module (forms &optional filename)
|
|
442
|
+
"Validate every portable declaration in FORMS from FILENAME."
|
|
443
|
+
(let (entries)
|
|
444
|
+
(dolist (form (eliscript-portable--flatten forms))
|
|
445
|
+
(let ((value (eliscript-portable--value form)))
|
|
446
|
+
(when (and (consp value)
|
|
447
|
+
(eq (eliscript-portable--value (car value)) 'defportable))
|
|
448
|
+
(push (eliscript-portable--value (cadr value)) entries))))
|
|
449
|
+
(eliscript-portable--closure forms (nreverse entries) filename t)
|
|
450
|
+
forms))
|
|
451
|
+
|
|
452
|
+
(defun eliscript-portable-select-module
|
|
453
|
+
(forms entries &optional filename allow-portable-imports)
|
|
454
|
+
"Return the declaration closure for portable ENTRIES in FORMS.
|
|
455
|
+
|
|
456
|
+
ALLOW-PORTABLE-IMPORTS is reserved for graph-aware project builds."
|
|
457
|
+
(let* ((entry-symbols
|
|
458
|
+
(mapcar (lambda (entry)
|
|
459
|
+
(if (symbolp entry) entry (intern entry)))
|
|
460
|
+
entries))
|
|
461
|
+
(closure
|
|
462
|
+
(eliscript-portable--closure
|
|
463
|
+
forms entry-symbols filename allow-portable-imports))
|
|
464
|
+
(selected (make-hash-table :test #'eq)))
|
|
465
|
+
(dolist (name closure) (puthash name t selected))
|
|
466
|
+
(delq
|
|
467
|
+
nil
|
|
468
|
+
(mapcar
|
|
469
|
+
(lambda (form)
|
|
470
|
+
(let ((value (eliscript-portable--value form)))
|
|
471
|
+
(when (consp value)
|
|
472
|
+
(let ((operator (eliscript-portable--value (car value))))
|
|
473
|
+
(if (eq operator 'import-portable)
|
|
474
|
+
(let ((names
|
|
475
|
+
(cl-remove-if-not
|
|
476
|
+
(lambda (name-form)
|
|
477
|
+
(gethash
|
|
478
|
+
(eliscript-portable--value name-form) selected))
|
|
479
|
+
(cddr value))))
|
|
480
|
+
(when names
|
|
481
|
+
(eliscript-form-inherit
|
|
482
|
+
(append (list (car value) (cadr value)) names)
|
|
483
|
+
form)))
|
|
484
|
+
(and (memq operator '(defconst defportable))
|
|
485
|
+
(gethash
|
|
486
|
+
(eliscript-portable--value (cadr value)) selected)
|
|
487
|
+
form))))))
|
|
488
|
+
(eliscript-portable--flatten forms)))))
|
|
489
|
+
|
|
490
|
+
(provide 'eliscript-portable)
|
|
491
|
+
|
|
492
|
+
;;; eliscript-portable.el ends here
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
;;; eliscript-project-cli.el --- Batch project builder -*- lexical-binding: t; -*-
|
|
2
|
+
|
|
3
|
+
;;; Commentary:
|
|
4
|
+
|
|
5
|
+
;; Run with:
|
|
6
|
+
;; emacs --batch -Q --script compiler/eliscript-project-cli.el -- ENTRY --out-dir DIR
|
|
7
|
+
|
|
8
|
+
;;; Code:
|
|
9
|
+
|
|
10
|
+
(add-to-list 'load-path
|
|
11
|
+
(file-name-directory (or load-file-name buffer-file-name)))
|
|
12
|
+
(require 'eliscript-project)
|
|
13
|
+
|
|
14
|
+
(defconst eliscript-project-cli--usage
|
|
15
|
+
(concat
|
|
16
|
+
"Usage: eliscript-build [--config FILE] [--root DIR] [--portable NAME]\n"
|
|
17
|
+
" [--no-cache]\n"
|
|
18
|
+
" [--json] [--diagnostic-format human|json]\n"
|
|
19
|
+
" --out-dir DIR ENTRY...\n\n"
|
|
20
|
+
"Compile ENTRIES and their relative .eli imports into an ESM directory tree.\n"
|
|
21
|
+
"Use --config FILE for a versioned project request. Explicit build flags\n"
|
|
22
|
+
"and ENTRIES override configured values; --no-cache always disables reuse.\n"
|
|
23
|
+
"Write eliscript-project.json with deterministic graph content digests.\n"
|
|
24
|
+
"Reuse verified modules by default; --no-cache forces complete compilation.\n"
|
|
25
|
+
"Use --json for a machine-readable build decision report on stdout.\n"
|
|
26
|
+
"Use JSON diagnostics for failures on stderr.\n"
|
|
27
|
+
"Repeat --portable to emit a verified, dependency-pruned portable graph.\n"))
|
|
28
|
+
|
|
29
|
+
(defun eliscript-project-cli--requested-diagnostic-format (arguments)
|
|
30
|
+
"Return a usable diagnostic format requested by raw ARGUMENTS."
|
|
31
|
+
(let ((remaining arguments)
|
|
32
|
+
(format-name "human"))
|
|
33
|
+
(while remaining
|
|
34
|
+
(when (and (equal (car remaining) "--diagnostic-format")
|
|
35
|
+
(cdr remaining)
|
|
36
|
+
(equal (cadr remaining) "json"))
|
|
37
|
+
(setq format-name "json"))
|
|
38
|
+
(setq remaining (cdr remaining)))
|
|
39
|
+
format-name))
|
|
40
|
+
|
|
41
|
+
(defun eliscript-project-cli--parse (arguments)
|
|
42
|
+
"Parse ARGUMENTS into a project request and presentation fields."
|
|
43
|
+
(when (equal (car arguments) "--")
|
|
44
|
+
(setq arguments (cdr arguments)))
|
|
45
|
+
(let ((use-cache t)
|
|
46
|
+
(json-report nil)
|
|
47
|
+
(diagnostic-format "human")
|
|
48
|
+
entries out-dir root portable-entries configuration)
|
|
49
|
+
(while arguments
|
|
50
|
+
(let ((argument (pop arguments)))
|
|
51
|
+
(cond
|
|
52
|
+
((member argument '("-h" "--help"))
|
|
53
|
+
(princ eliscript-project-cli--usage)
|
|
54
|
+
(kill-emacs 0))
|
|
55
|
+
((equal argument "--out-dir")
|
|
56
|
+
(unless arguments
|
|
57
|
+
(error "%s requires a directory" argument))
|
|
58
|
+
(setq out-dir (pop arguments)))
|
|
59
|
+
((equal argument "--config")
|
|
60
|
+
(unless arguments
|
|
61
|
+
(error "%s requires a file" argument))
|
|
62
|
+
(when configuration
|
|
63
|
+
(error "multiple --config files are not supported"))
|
|
64
|
+
(setq configuration (pop arguments)))
|
|
65
|
+
((equal argument "--root")
|
|
66
|
+
(unless arguments
|
|
67
|
+
(error "%s requires a directory" argument))
|
|
68
|
+
(setq root (pop arguments)))
|
|
69
|
+
((equal argument "--portable")
|
|
70
|
+
(unless arguments
|
|
71
|
+
(error "%s requires an entry name" argument))
|
|
72
|
+
(push (pop arguments) portable-entries))
|
|
73
|
+
((equal argument "--no-cache")
|
|
74
|
+
(setq use-cache nil))
|
|
75
|
+
((equal argument "--json")
|
|
76
|
+
(setq json-report t))
|
|
77
|
+
((equal argument "--diagnostic-format")
|
|
78
|
+
(unless arguments
|
|
79
|
+
(error "%s requires human or json" argument))
|
|
80
|
+
(setq diagnostic-format (pop arguments))
|
|
81
|
+
(unless (member diagnostic-format '("human" "json"))
|
|
82
|
+
(error "unsupported diagnostic format: %s" diagnostic-format)))
|
|
83
|
+
((string-prefix-p "-" argument)
|
|
84
|
+
(error "unknown option: %s" argument))
|
|
85
|
+
(t (push argument entries)))))
|
|
86
|
+
(setq entries (nreverse entries))
|
|
87
|
+
(let ((request
|
|
88
|
+
(if configuration
|
|
89
|
+
(let ((configured
|
|
90
|
+
(eliscript-project-read-configuration configuration)))
|
|
91
|
+
(when entries
|
|
92
|
+
(if (= (length entries) 1)
|
|
93
|
+
(progn
|
|
94
|
+
(setf (eliscript-project-request-entry configured)
|
|
95
|
+
(car entries))
|
|
96
|
+
(setf (eliscript-project-request-entries configured)
|
|
97
|
+
nil))
|
|
98
|
+
(setf (eliscript-project-request-entry configured) nil)
|
|
99
|
+
(setf (eliscript-project-request-entries configured)
|
|
100
|
+
entries)))
|
|
101
|
+
(when out-dir
|
|
102
|
+
(setf (eliscript-project-request-out-dir configured) out-dir))
|
|
103
|
+
(when root
|
|
104
|
+
(setf (eliscript-project-request-root configured) root))
|
|
105
|
+
(when portable-entries
|
|
106
|
+
(setf (eliscript-project-request-portable-entries configured)
|
|
107
|
+
(nreverse portable-entries)))
|
|
108
|
+
(unless use-cache
|
|
109
|
+
(setf (eliscript-project-request-use-cache configured) nil))
|
|
110
|
+
configured)
|
|
111
|
+
(progn
|
|
112
|
+
(unless entries
|
|
113
|
+
(error "missing entry file"))
|
|
114
|
+
(unless out-dir
|
|
115
|
+
(error "missing --out-dir"))
|
|
116
|
+
(eliscript-project-request-create
|
|
117
|
+
:entry (and (= (length entries) 1) (car entries))
|
|
118
|
+
:entries (and (> (length entries) 1) entries)
|
|
119
|
+
:out-dir out-dir
|
|
120
|
+
:root root
|
|
121
|
+
:portable-entries (nreverse portable-entries)
|
|
122
|
+
:use-cache use-cache)))))
|
|
123
|
+
(list request json-report diagnostic-format))))
|
|
124
|
+
|
|
125
|
+
(defun eliscript-project-cli-main (arguments)
|
|
126
|
+
"Build an Eliscript project according to command-line ARGUMENTS."
|
|
127
|
+
(let ((requested-format
|
|
128
|
+
(eliscript-project-cli--requested-diagnostic-format arguments)))
|
|
129
|
+
(condition-case error-data
|
|
130
|
+
(pcase-let ((`(,request ,json-report ,diagnostic-format)
|
|
131
|
+
(eliscript-project-cli--parse arguments)))
|
|
132
|
+
(setq requested-format diagnostic-format)
|
|
133
|
+
(let ((result (eliscript-project-execute request)))
|
|
134
|
+
(princ
|
|
135
|
+
(if json-report
|
|
136
|
+
(json-serialize
|
|
137
|
+
(eliscript-project-build-report result)
|
|
138
|
+
:false-object :false)
|
|
139
|
+
(mapconcat #'identity
|
|
140
|
+
(eliscript-project-build-result-entry-outputs result)
|
|
141
|
+
"\n")))
|
|
142
|
+
(princ "\n")))
|
|
143
|
+
(error
|
|
144
|
+
(if (equal requested-format "json")
|
|
145
|
+
(message
|
|
146
|
+
"%s"
|
|
147
|
+
(eliscript-diagnostic-to-json
|
|
148
|
+
(eliscript-diagnostic-from-error error-data)))
|
|
149
|
+
(message
|
|
150
|
+
"eliscript-build: %s"
|
|
151
|
+
(eliscript-diagnostic-condition-message error-data)))
|
|
152
|
+
(kill-emacs 1)))))
|
|
153
|
+
|
|
154
|
+
(eliscript-project-cli-main command-line-args-left)
|
|
155
|
+
|
|
156
|
+
;;; eliscript-project-cli.el ends here
|