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,356 @@
|
|
|
1
|
+
;;; eliscript-ir.el --- Intermediate representation for Eliscript -*- lexical-binding: t; -*-
|
|
2
|
+
|
|
3
|
+
;;; Commentary:
|
|
4
|
+
|
|
5
|
+
;; The IR separates analyzed language semantics from reader-shaped forms. It
|
|
6
|
+
;; deliberately keeps source spans on every node so later emitters can produce
|
|
7
|
+
;; source maps without consulting the reader representation.
|
|
8
|
+
|
|
9
|
+
;;; Code:
|
|
10
|
+
|
|
11
|
+
(require 'cl-lib)
|
|
12
|
+
|
|
13
|
+
(cl-defstruct (eliscript-ir-program
|
|
14
|
+
(:constructor eliscript-ir-program-create))
|
|
15
|
+
filename
|
|
16
|
+
body)
|
|
17
|
+
|
|
18
|
+
(cl-defstruct (eliscript-ir-node
|
|
19
|
+
(:constructor eliscript-ir-node-create))
|
|
20
|
+
kind
|
|
21
|
+
span
|
|
22
|
+
value
|
|
23
|
+
children
|
|
24
|
+
properties)
|
|
25
|
+
|
|
26
|
+
(defconst eliscript-ir-node-kinds
|
|
27
|
+
'(module-declaration import-declaration import-default import-namespace
|
|
28
|
+
import-named variable-declaration function-declaration export-declaration
|
|
29
|
+
export-default expression-statement parameter-binding
|
|
30
|
+
array-binding-pattern map-binding-pattern map-binding-entry
|
|
31
|
+
binding-name binding-hole reference literal
|
|
32
|
+
array-literal persistent-list-literal persistent-vector-literal
|
|
33
|
+
persistent-map-literal persistent-set-literal persistent-queue-literal
|
|
34
|
+
quoted-literal function-expression await-expression
|
|
35
|
+
throw-expression try-expression catch-clause catch-binding finally-clause
|
|
36
|
+
conditional conditional-sugar
|
|
37
|
+
conditional-chain conditional-clause sequence lexical-bindings
|
|
38
|
+
lexical-binding assignment assignment-pair loop binding-loop recur
|
|
39
|
+
short-circuit intrinsic
|
|
40
|
+
object-literal object-property property-read property-write method-call
|
|
41
|
+
constructor-call raw-javascript print string-concat invoke apply-call call)
|
|
42
|
+
"Public node kinds emitted by the lowering pass.")
|
|
43
|
+
|
|
44
|
+
(defun eliscript-ir-make-program (filename body)
|
|
45
|
+
"Create an IR program for FILENAME from top-level node BODY."
|
|
46
|
+
(unless (proper-list-p body)
|
|
47
|
+
(error "IR program body must be a proper list: %S" body))
|
|
48
|
+
(when (cl-find-if-not #'eliscript-ir-node-p body)
|
|
49
|
+
(error "IR program body must contain only IR nodes: %S" body))
|
|
50
|
+
(eliscript-ir-program-create :filename filename :body body))
|
|
51
|
+
|
|
52
|
+
(defun eliscript-ir-make-node (kind span &optional value children properties)
|
|
53
|
+
"Create an IR node of KIND at SPAN with VALUE, CHILDREN, and PROPERTIES."
|
|
54
|
+
(unless (memq kind eliscript-ir-node-kinds)
|
|
55
|
+
(error "Unknown Eliscript IR node kind: %S" kind))
|
|
56
|
+
(unless (or (null children) (proper-list-p children))
|
|
57
|
+
(error "IR node children must be a proper list: %S" children))
|
|
58
|
+
(when (cl-find-if-not #'eliscript-ir-node-p children)
|
|
59
|
+
(error "IR node children must all be IR nodes: %S" children))
|
|
60
|
+
(eliscript-ir-node-create
|
|
61
|
+
:kind kind
|
|
62
|
+
:span span
|
|
63
|
+
:value value
|
|
64
|
+
:children children
|
|
65
|
+
:properties properties))
|
|
66
|
+
|
|
67
|
+
(defun eliscript-ir-property (node property)
|
|
68
|
+
"Return PROPERTY from IR NODE's property list."
|
|
69
|
+
(plist-get (eliscript-ir-node-properties node) property))
|
|
70
|
+
|
|
71
|
+
(defun eliscript-ir-walk (program function)
|
|
72
|
+
"Call FUNCTION in preorder for every node reachable from IR PROGRAM."
|
|
73
|
+
(unless (eliscript-ir-program-p program)
|
|
74
|
+
(error "Expected an Eliscript IR program: %S" program))
|
|
75
|
+
(cl-labels ((walk-node
|
|
76
|
+
(node)
|
|
77
|
+
(funcall function node)
|
|
78
|
+
(mapc #'walk-node (eliscript-ir-node-children node))))
|
|
79
|
+
(mapc #'walk-node (eliscript-ir-program-body program))))
|
|
80
|
+
|
|
81
|
+
(defun eliscript-ir--binding-to-form (node)
|
|
82
|
+
"Convert lexical binding NODE to a reader-shaped form."
|
|
83
|
+
(let* ((pattern (eliscript-ir-property node :pattern))
|
|
84
|
+
(children (eliscript-ir-node-children node))
|
|
85
|
+
(name (if pattern
|
|
86
|
+
(eliscript-ir-node-to-form (car children))
|
|
87
|
+
(eliscript-ir-node-value node)))
|
|
88
|
+
(values (if pattern (cdr children) children)))
|
|
89
|
+
(pcase (eliscript-ir-property node :style)
|
|
90
|
+
('symbol name)
|
|
91
|
+
(_ (if values
|
|
92
|
+
(list name (eliscript-ir-node-to-form (car values)))
|
|
93
|
+
(list name))))))
|
|
94
|
+
|
|
95
|
+
(defun eliscript-ir--binding-target-to-form (node)
|
|
96
|
+
"Convert binding wrapper NODE to its reader-shaped target."
|
|
97
|
+
(if (eliscript-ir-property node :pattern)
|
|
98
|
+
(eliscript-ir-node-to-form (car (eliscript-ir-node-children node)))
|
|
99
|
+
(eliscript-ir-node-value node)))
|
|
100
|
+
|
|
101
|
+
(defun eliscript-ir--operator-form (node)
|
|
102
|
+
"Convert operator-style IR NODE to a reader-shaped form."
|
|
103
|
+
(cons (eliscript-ir-node-value node)
|
|
104
|
+
(mapcar #'eliscript-ir-node-to-form
|
|
105
|
+
(eliscript-ir-node-children node))))
|
|
106
|
+
|
|
107
|
+
(defun eliscript-ir--parameters-to-form (nodes)
|
|
108
|
+
"Convert parameter binding NODES to a canonical parameter list."
|
|
109
|
+
(let (forms optional-marker)
|
|
110
|
+
(dolist (node nodes)
|
|
111
|
+
(pcase (eliscript-ir-property node :parameter-kind)
|
|
112
|
+
('optional
|
|
113
|
+
(unless optional-marker
|
|
114
|
+
(push '&optional forms)
|
|
115
|
+
(setq optional-marker t)))
|
|
116
|
+
('rest (push '&rest forms)))
|
|
117
|
+
(push (eliscript-ir--binding-target-to-form node) forms))
|
|
118
|
+
(nreverse forms)))
|
|
119
|
+
|
|
120
|
+
(defun eliscript-ir-node-to-form (node)
|
|
121
|
+
"Convert IR NODE to a canonical reader-shaped form for compatibility."
|
|
122
|
+
(unless (eliscript-ir-node-p node)
|
|
123
|
+
(error "Expected an Eliscript IR node: %S" node))
|
|
124
|
+
(pcase (eliscript-ir-node-kind node)
|
|
125
|
+
((or 'literal 'reference 'binding-name)
|
|
126
|
+
(eliscript-ir-node-value node))
|
|
127
|
+
((or 'parameter-binding 'catch-binding)
|
|
128
|
+
(eliscript-ir--binding-target-to-form node))
|
|
129
|
+
('binding-hole nil)
|
|
130
|
+
('array-binding-pattern
|
|
131
|
+
(let* ((children (eliscript-ir-node-children node))
|
|
132
|
+
(forms (mapcar #'eliscript-ir-node-to-form children)))
|
|
133
|
+
(when (eliscript-ir-property node :rest)
|
|
134
|
+
(setq forms
|
|
135
|
+
(append (butlast forms)
|
|
136
|
+
(list '&rest (car (last forms))))))
|
|
137
|
+
(apply #'vector forms)))
|
|
138
|
+
('map-binding-pattern
|
|
139
|
+
(let* ((children (eliscript-ir-node-children node))
|
|
140
|
+
(entry-count (eliscript-ir-property node :entry-count))
|
|
141
|
+
(entries (cl-subseq children 0 entry-count))
|
|
142
|
+
(as (and (eliscript-ir-property node :as)
|
|
143
|
+
(nth entry-count children)))
|
|
144
|
+
pairs defaults)
|
|
145
|
+
(dolist (entry entries)
|
|
146
|
+
(let* ((entry-children (eliscript-ir-node-children entry))
|
|
147
|
+
(target (eliscript-ir-node-to-form (nth 0 entry-children)))
|
|
148
|
+
(key (eliscript-ir-node-to-form (nth 1 entry-children))))
|
|
149
|
+
(setq pairs (append pairs (list target key)))
|
|
150
|
+
(when (eliscript-ir-property entry :default)
|
|
151
|
+
(setq defaults
|
|
152
|
+
(append defaults
|
|
153
|
+
(list target
|
|
154
|
+
(eliscript-ir-node-to-form
|
|
155
|
+
(nth 2 entry-children))))))))
|
|
156
|
+
(cons 'hash-map
|
|
157
|
+
(append pairs
|
|
158
|
+
(and defaults
|
|
159
|
+
(list :or (cons 'hash-map defaults)))
|
|
160
|
+
(and as
|
|
161
|
+
(list :as (eliscript-ir-node-to-form as)))))))
|
|
162
|
+
('quoted-literal
|
|
163
|
+
(list 'quote (eliscript-ir-node-value node)))
|
|
164
|
+
('array-literal
|
|
165
|
+
(cons 'js-array
|
|
166
|
+
(mapcar #'eliscript-ir-node-to-form
|
|
167
|
+
(eliscript-ir-node-children node))))
|
|
168
|
+
('persistent-list-literal
|
|
169
|
+
(cons 'list
|
|
170
|
+
(mapcar #'eliscript-ir-node-to-form
|
|
171
|
+
(eliscript-ir-node-children node))))
|
|
172
|
+
('persistent-vector-literal
|
|
173
|
+
(cons 'vector
|
|
174
|
+
(mapcar #'eliscript-ir-node-to-form
|
|
175
|
+
(eliscript-ir-node-children node))))
|
|
176
|
+
('persistent-map-literal
|
|
177
|
+
(cons 'hash-map
|
|
178
|
+
(mapcar #'eliscript-ir-node-to-form
|
|
179
|
+
(eliscript-ir-node-children node))))
|
|
180
|
+
('persistent-set-literal
|
|
181
|
+
(cons 'hash-set
|
|
182
|
+
(mapcar #'eliscript-ir-node-to-form
|
|
183
|
+
(eliscript-ir-node-children node))))
|
|
184
|
+
('persistent-queue-literal
|
|
185
|
+
(cons 'queue
|
|
186
|
+
(mapcar #'eliscript-ir-node-to-form
|
|
187
|
+
(eliscript-ir-node-children node))))
|
|
188
|
+
('module-declaration
|
|
189
|
+
(cons 'module
|
|
190
|
+
(cons (eliscript-ir-node-value node)
|
|
191
|
+
(mapcar #'eliscript-ir-node-to-form
|
|
192
|
+
(eliscript-ir-node-children node)))))
|
|
193
|
+
('import-declaration
|
|
194
|
+
(cons (if (eliscript-ir-property node :portable)
|
|
195
|
+
'import-portable
|
|
196
|
+
'import)
|
|
197
|
+
(cons
|
|
198
|
+
(eliscript-ir-node-value node)
|
|
199
|
+
(apply
|
|
200
|
+
#'append
|
|
201
|
+
(mapcar
|
|
202
|
+
(lambda (specifier)
|
|
203
|
+
(pcase (eliscript-ir-node-kind specifier)
|
|
204
|
+
('import-default
|
|
205
|
+
(list :default (eliscript-ir-node-value specifier)))
|
|
206
|
+
('import-namespace
|
|
207
|
+
(list :as (eliscript-ir-node-value specifier)))
|
|
208
|
+
('import-named (list (eliscript-ir-node-value specifier)))))
|
|
209
|
+
(eliscript-ir-node-children node))))))
|
|
210
|
+
('variable-declaration
|
|
211
|
+
(cons (eliscript-ir-property node :source-operator)
|
|
212
|
+
(cons (eliscript-ir-node-value node)
|
|
213
|
+
(mapcar #'eliscript-ir-node-to-form
|
|
214
|
+
(eliscript-ir-node-children node)))))
|
|
215
|
+
((or 'function-declaration 'function-expression)
|
|
216
|
+
(let* ((operator
|
|
217
|
+
(if (eq (eliscript-ir-node-kind node) 'function-declaration)
|
|
218
|
+
(or (eliscript-ir-property node :source-operator) 'defun)
|
|
219
|
+
(if (eliscript-ir-property node :async) 'async 'lambda)))
|
|
220
|
+
(children (eliscript-ir-node-children node))
|
|
221
|
+
(parameter-count (eliscript-ir-property node :parameter-count))
|
|
222
|
+
(parameters
|
|
223
|
+
(eliscript-ir--parameters-to-form
|
|
224
|
+
(cl-subseq children 0 parameter-count)))
|
|
225
|
+
(body (mapcar #'eliscript-ir-node-to-form
|
|
226
|
+
(nthcdr parameter-count children))))
|
|
227
|
+
(if (memq operator '(defun defn defportable defasync))
|
|
228
|
+
(cons operator
|
|
229
|
+
(cons (eliscript-ir-node-value node)
|
|
230
|
+
(cons parameters body)))
|
|
231
|
+
(cons operator (cons parameters body)))))
|
|
232
|
+
('await-expression
|
|
233
|
+
(list 'await
|
|
234
|
+
(eliscript-ir-node-to-form
|
|
235
|
+
(car (eliscript-ir-node-children node)))))
|
|
236
|
+
('throw-expression
|
|
237
|
+
(list 'throw
|
|
238
|
+
(eliscript-ir-node-to-form
|
|
239
|
+
(car (eliscript-ir-node-children node)))))
|
|
240
|
+
('try-expression
|
|
241
|
+
(let* ((children (eliscript-ir-node-children node))
|
|
242
|
+
(body-count (eliscript-ir-property node :body-count)))
|
|
243
|
+
(cons
|
|
244
|
+
'try
|
|
245
|
+
(append
|
|
246
|
+
(mapcar #'eliscript-ir-node-to-form
|
|
247
|
+
(cl-subseq children 0 body-count))
|
|
248
|
+
(mapcar #'eliscript-ir-node-to-form
|
|
249
|
+
(nthcdr body-count children))))))
|
|
250
|
+
('catch-clause
|
|
251
|
+
(let ((children (eliscript-ir-node-children node)))
|
|
252
|
+
(cons
|
|
253
|
+
'catch
|
|
254
|
+
(cons
|
|
255
|
+
(eliscript-ir--binding-target-to-form (car children))
|
|
256
|
+
(mapcar #'eliscript-ir-node-to-form (cdr children))))))
|
|
257
|
+
('finally-clause
|
|
258
|
+
(cons 'finally
|
|
259
|
+
(mapcar #'eliscript-ir-node-to-form
|
|
260
|
+
(eliscript-ir-node-children node))))
|
|
261
|
+
('export-declaration
|
|
262
|
+
(cons 'export
|
|
263
|
+
(mapcar #'eliscript-ir-node-value
|
|
264
|
+
(eliscript-ir-node-children node))))
|
|
265
|
+
('export-default
|
|
266
|
+
(list 'export-default
|
|
267
|
+
(eliscript-ir-node-to-form
|
|
268
|
+
(car (eliscript-ir-node-children node)))))
|
|
269
|
+
('expression-statement
|
|
270
|
+
(eliscript-ir-node-to-form (car (eliscript-ir-node-children node))))
|
|
271
|
+
('conditional-chain
|
|
272
|
+
(cons 'cond
|
|
273
|
+
(mapcar #'eliscript-ir-node-to-form
|
|
274
|
+
(eliscript-ir-node-children node))))
|
|
275
|
+
('conditional-clause
|
|
276
|
+
(mapcar #'eliscript-ir-node-to-form
|
|
277
|
+
(eliscript-ir-node-children node)))
|
|
278
|
+
('lexical-bindings
|
|
279
|
+
(let* ((children (eliscript-ir-node-children node))
|
|
280
|
+
(binding-count (eliscript-ir-property node :binding-count)))
|
|
281
|
+
(cons (if (eliscript-ir-property node :sequential) 'let* 'let)
|
|
282
|
+
(cons
|
|
283
|
+
(mapcar #'eliscript-ir--binding-to-form
|
|
284
|
+
(cl-subseq children 0 binding-count))
|
|
285
|
+
(mapcar #'eliscript-ir-node-to-form
|
|
286
|
+
(nthcdr binding-count children))))))
|
|
287
|
+
('binding-loop
|
|
288
|
+
(let* ((children (eliscript-ir-node-children node))
|
|
289
|
+
(binding-count (eliscript-ir-property node :binding-count)))
|
|
290
|
+
(cons
|
|
291
|
+
'loop
|
|
292
|
+
(cons
|
|
293
|
+
(mapcar #'eliscript-ir--binding-to-form
|
|
294
|
+
(cl-subseq children 0 binding-count))
|
|
295
|
+
(mapcar #'eliscript-ir-node-to-form
|
|
296
|
+
(nthcdr binding-count children))))))
|
|
297
|
+
('recur
|
|
298
|
+
(cons 'recur
|
|
299
|
+
(mapcar #'eliscript-ir-node-to-form
|
|
300
|
+
(eliscript-ir-node-children node))))
|
|
301
|
+
('lexical-binding (eliscript-ir--binding-to-form node))
|
|
302
|
+
('assignment
|
|
303
|
+
(cons (eliscript-ir-node-value node)
|
|
304
|
+
(apply
|
|
305
|
+
#'append
|
|
306
|
+
(mapcar
|
|
307
|
+
(lambda (pair)
|
|
308
|
+
(list (eliscript-ir-node-value pair)
|
|
309
|
+
(eliscript-ir-node-to-form
|
|
310
|
+
(car (eliscript-ir-node-children pair)))))
|
|
311
|
+
(eliscript-ir-node-children node)))))
|
|
312
|
+
('assignment-pair
|
|
313
|
+
(error "Assignment pairs are emitted through their parent node"))
|
|
314
|
+
('object-literal
|
|
315
|
+
(cons
|
|
316
|
+
'js-object
|
|
317
|
+
(apply
|
|
318
|
+
#'append
|
|
319
|
+
(mapcar
|
|
320
|
+
(lambda (property)
|
|
321
|
+
(if (eliscript-ir-property property :computed)
|
|
322
|
+
(list
|
|
323
|
+
(eliscript-ir-node-to-form
|
|
324
|
+
(nth 0 (eliscript-ir-node-children property)))
|
|
325
|
+
(eliscript-ir-node-to-form
|
|
326
|
+
(nth 1 (eliscript-ir-node-children property))))
|
|
327
|
+
(list
|
|
328
|
+
(eliscript-ir-node-value property)
|
|
329
|
+
(eliscript-ir-node-to-form
|
|
330
|
+
(car (eliscript-ir-node-children property))))))
|
|
331
|
+
(eliscript-ir-node-children node)))))
|
|
332
|
+
('object-property
|
|
333
|
+
(error "Object properties are emitted through their parent node"))
|
|
334
|
+
((or 'import-default 'import-namespace 'import-named)
|
|
335
|
+
(error "Import specifiers are emitted through their parent node"))
|
|
336
|
+
('call
|
|
337
|
+
(mapcar #'eliscript-ir-node-to-form
|
|
338
|
+
(eliscript-ir-node-children node)))
|
|
339
|
+
((or 'conditional 'conditional-sugar 'sequence 'loop 'short-circuit
|
|
340
|
+
'intrinsic 'property-read 'property-write 'method-call
|
|
341
|
+
'constructor-call 'raw-javascript 'print 'string-concat 'invoke
|
|
342
|
+
'apply-call)
|
|
343
|
+
(eliscript-ir--operator-form node))
|
|
344
|
+
(_ (error "Cannot convert IR node kind to a form: %S"
|
|
345
|
+
(eliscript-ir-node-kind node)))))
|
|
346
|
+
|
|
347
|
+
(defun eliscript-ir-program-to-forms (program)
|
|
348
|
+
"Convert IR PROGRAM to canonical reader-shaped module forms."
|
|
349
|
+
(unless (eliscript-ir-program-p program)
|
|
350
|
+
(error "Expected an Eliscript IR program: %S" program))
|
|
351
|
+
(mapcar #'eliscript-ir-node-to-form
|
|
352
|
+
(eliscript-ir-program-body program)))
|
|
353
|
+
|
|
354
|
+
(provide 'eliscript-ir)
|
|
355
|
+
|
|
356
|
+
;;; eliscript-ir.el ends here
|