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,101 @@
|
|
|
1
|
+
;;; eliscript-symbol.el --- Eliscript identifier mapping -*- lexical-binding: t; -*-
|
|
2
|
+
|
|
3
|
+
;;; Commentary:
|
|
4
|
+
|
|
5
|
+
;; Identifier validation and deterministic ECMAScript name mapping are shared
|
|
6
|
+
;; by analysis and emission so collisions are diagnosed before output.
|
|
7
|
+
|
|
8
|
+
;;; Code:
|
|
9
|
+
|
|
10
|
+
(require 'subr-x)
|
|
11
|
+
(require 'eliscript-diagnostic)
|
|
12
|
+
|
|
13
|
+
(defconst eliscript-symbol-reserved-words
|
|
14
|
+
'("await" "break" "case" "catch" "class" "const" "continue"
|
|
15
|
+
"debugger" "default" "delete" "do" "else" "enum" "export"
|
|
16
|
+
"extends" "false" "finally" "for" "function" "if" "implements"
|
|
17
|
+
"import" "in" "instanceof" "interface" "let" "new" "null"
|
|
18
|
+
"package" "private" "protected" "public" "return" "static"
|
|
19
|
+
"super" "switch" "this" "throw" "true" "try" "typeof" "var"
|
|
20
|
+
"void" "while" "with" "yield"))
|
|
21
|
+
|
|
22
|
+
(defconst eliscript-symbol-internal-prefix "__eliscript_"
|
|
23
|
+
"ECMAScript identifier prefix reserved for generated compiler bindings.")
|
|
24
|
+
|
|
25
|
+
(defconst eliscript-symbol-strict-binding-names '("arguments" "eval")
|
|
26
|
+
"Identifiers forbidden as bindings in strict ECMAScript modules.")
|
|
27
|
+
|
|
28
|
+
(defun eliscript-symbol--fail (format-string &rest arguments)
|
|
29
|
+
"Signal an identifier error using FORMAT-STRING and ARGUMENTS."
|
|
30
|
+
(apply #'eliscript-diagnostic-signal
|
|
31
|
+
'eliscript-compile-error "ELI-S0001" "symbol"
|
|
32
|
+
nil nil format-string arguments))
|
|
33
|
+
|
|
34
|
+
(defun eliscript-symbol-munge-segment (name)
|
|
35
|
+
"Convert Lisp identifier segment NAME to an ECMAScript identifier."
|
|
36
|
+
(let ((index 0)
|
|
37
|
+
pieces)
|
|
38
|
+
(while (< index (length name))
|
|
39
|
+
(let ((character (aref name index)))
|
|
40
|
+
(push
|
|
41
|
+
(cond
|
|
42
|
+
((string-match-p "[A-Za-z0-9_$]" (char-to-string character))
|
|
43
|
+
(char-to-string character))
|
|
44
|
+
((eq character ?-) "_")
|
|
45
|
+
((eq character ??) "_QMARK_")
|
|
46
|
+
((eq character ?!) "_BANG_")
|
|
47
|
+
((eq character ?*) "_STAR_")
|
|
48
|
+
((eq character ?+) "_PLUS_")
|
|
49
|
+
((eq character ?=) "_EQ_")
|
|
50
|
+
((eq character ?<) "_LT_")
|
|
51
|
+
((eq character ?>) "_GT_")
|
|
52
|
+
(t (format "_U%04X_" character)))
|
|
53
|
+
pieces))
|
|
54
|
+
(setq index (1+ index)))
|
|
55
|
+
(let ((result (apply #'concat (nreverse pieces))))
|
|
56
|
+
(when (string-empty-p result)
|
|
57
|
+
(eliscript-symbol--fail "empty identifier"))
|
|
58
|
+
(when (string-match-p "\\`[0-9]" result)
|
|
59
|
+
(setq result (concat "_" result)))
|
|
60
|
+
(when (member result eliscript-symbol-reserved-words)
|
|
61
|
+
(setq result (concat result "$")))
|
|
62
|
+
result)))
|
|
63
|
+
|
|
64
|
+
(defun eliscript-symbol-binding-name (symbol)
|
|
65
|
+
"Return the ECMAScript binding name for SYMBOL."
|
|
66
|
+
(unless (symbolp symbol)
|
|
67
|
+
(eliscript-symbol--fail "expected binding name, got %S" symbol))
|
|
68
|
+
(when (or (keywordp symbol)
|
|
69
|
+
(memq symbol '(nil t false undefined))
|
|
70
|
+
(string-prefix-p "&" (symbol-name symbol)))
|
|
71
|
+
(eliscript-symbol--fail "reserved value cannot be a binding: %S" symbol))
|
|
72
|
+
(let ((name (symbol-name symbol)))
|
|
73
|
+
(when (string-match-p "[./]" name)
|
|
74
|
+
(eliscript-symbol--fail "qualified name cannot be a binding: %s" name))
|
|
75
|
+
(let ((output-name (eliscript-symbol-munge-segment name)))
|
|
76
|
+
(when (member output-name eliscript-symbol-strict-binding-names)
|
|
77
|
+
(setq output-name (concat output-name "$")))
|
|
78
|
+
(when (string-prefix-p eliscript-symbol-internal-prefix output-name)
|
|
79
|
+
(eliscript-symbol--fail
|
|
80
|
+
"binding name uses reserved compiler prefix: %s" name))
|
|
81
|
+
output-name)))
|
|
82
|
+
|
|
83
|
+
(defun eliscript-symbol-reference-name (symbol)
|
|
84
|
+
"Return an ECMAScript reference for SYMBOL."
|
|
85
|
+
(let* ((name (symbol-name symbol))
|
|
86
|
+
(qualified (string-match-p "[./]" name))
|
|
87
|
+
(reference
|
|
88
|
+
(mapconcat #'eliscript-symbol-munge-segment
|
|
89
|
+
(split-string name "[./]" t)
|
|
90
|
+
".")))
|
|
91
|
+
(when (and (not qualified)
|
|
92
|
+
(member reference eliscript-symbol-strict-binding-names))
|
|
93
|
+
(setq reference (concat reference "$")))
|
|
94
|
+
(when (string-prefix-p eliscript-symbol-internal-prefix reference)
|
|
95
|
+
(eliscript-symbol--fail
|
|
96
|
+
"reference uses reserved compiler prefix: %s" symbol))
|
|
97
|
+
reference))
|
|
98
|
+
|
|
99
|
+
(provide 'eliscript-symbol)
|
|
100
|
+
|
|
101
|
+
;;; eliscript-symbol.el ends here
|