eliscript 0.1.0 → 0.1.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/README.md +9 -8
- package/bootstrap/compiler/emitter.eli +161 -63
- package/bootstrap/host/check-cli.mjs +0 -1
- package/bootstrap/host/check-cli.mjs.map +1 -1
- package/bootstrap/host/compiler-session.eli +2 -1
- package/bootstrap/host/eliscript-cli.mjs +2 -9
- package/bootstrap/host/eliscript-cli.mjs.map +1 -1
- package/bootstrap/host/project-cli.mjs +1 -11
- package/bootstrap/host/project-cli.mjs.map +1 -1
- package/bootstrap/host/project.mjs +2 -8
- package/bootstrap/host/project.mjs.map +1 -1
- package/browser/README.md +1 -1
- package/compiler/README.md +2 -2
- package/compiler/eliscript-emitter.el +229 -85
- package/compiler/eliscript-ir-emitter.el +64 -34
- package/compiler/eliscript-project.el +20 -5
- package/dist/backends/async.mjs +1 -90
- package/dist/backends/async.mjs.map +1 -1
- package/dist/backends/binary.mjs +1 -91
- package/dist/backends/binary.mjs.map +1 -1
- package/dist/backends/capabilities.mjs +1 -90
- package/dist/backends/capabilities.mjs.map +1 -1
- package/dist/backends/elf.mjs +1 -90
- package/dist/backends/elf.mjs.map +1 -1
- package/dist/backends/managed.mjs +1 -94
- package/dist/backends/managed.mjs.map +1 -1
- package/dist/backends/memory.mjs +1 -90
- package/dist/backends/memory.mjs.map +1 -1
- package/dist/backends/native.mjs +1 -91
- package/dist/backends/native.mjs.map +1 -1
- package/dist/backends/numeric.mjs +1 -90
- package/dist/backends/numeric.mjs.map +1 -1
- package/dist/backends/optimize.mjs +1 -90
- package/dist/backends/optimize.mjs.map +1 -1
- package/dist/backends/regexp.mjs +1 -91
- package/dist/backends/regexp.mjs.map +1 -1
- package/dist/backends/sha256.mjs +2 -96
- package/dist/backends/sha256.mjs.map +1 -1
- package/dist/backends/wasm.mjs +1 -90
- package/dist/backends/wasm.mjs.map +1 -1
- package/dist/bootstrap/analyzer.mjs +1 -95
- package/dist/bootstrap/analyzer.mjs.map +1 -1
- package/dist/bootstrap/compiler.mjs +1 -105
- package/dist/bootstrap/compiler.mjs.map +1 -1
- package/dist/bootstrap/emitter.mjs +848 -807
- package/dist/bootstrap/emitter.mjs.map +1 -1
- package/dist/bootstrap/expander.mjs +1 -96
- package/dist/bootstrap/expander.mjs.map +1 -1
- package/dist/bootstrap/formatter.mjs +1 -104
- package/dist/bootstrap/formatter.mjs.map +1 -1
- package/dist/bootstrap/ir.mjs +18 -172
- package/dist/bootstrap/ir.mjs.map +1 -1
- package/dist/bootstrap/lower.mjs +1 -92
- package/dist/bootstrap/lower.mjs.map +1 -1
- package/dist/bootstrap/project.mjs +23 -209
- package/dist/bootstrap/project.mjs.map +1 -1
- package/dist/bootstrap/reader.mjs +1 -96
- package/dist/bootstrap/reader.mjs.map +1 -1
- package/dist/bootstrap/source-map.mjs +7 -112
- package/dist/bootstrap/source-map.mjs.map +1 -1
- package/dist/bootstrap/symbol.mjs +7 -114
- package/dist/bootstrap/symbol.mjs.map +1 -1
- package/dist/bootstrap/syntax.mjs +10 -176
- package/dist/bootstrap/syntax.mjs.map +1 -1
- package/dist/bootstrap/transient-analysis.mjs +1 -93
- package/dist/bootstrap/transient-analysis.mjs.map +1 -1
- package/dist/browser/compiler.js +105 -104
- package/dist/browser/loader.js +1 -1
- package/dist/browser/loader.mjs +5 -124
- package/dist/compiler-artifact.json +1 -1
- package/dist/host/compiler-session.mjs +205 -297
- package/dist/host/compiler-session.mjs.map +1 -1
- package/dist/host/compiler-tools.mjs +1 -91
- package/dist/host/compiler-tools.mjs.map +1 -1
- package/dist/literal-sources/runtime/core/order.eli +32 -10
- package/dist/literal-sources/runtime/core/sequence.eli +69 -28
- package/dist/literal-sources/runtime/core/vector.eli +2 -4
- package/dist/literal-sources/stdlib/managed-literal-protocols.eli +5 -5
- package/dist/literal-sources/stdlib/managed-literals.eli +1 -1
- package/dist/package.json +1 -0
- package/dist/runtime/math.mjs +62 -252
- package/dist/runtime/math.mjs.map +1 -1
- package/dist/runtime/prelude.mjs +95 -0
- package/dist/runtime/prelude.mjs.macro-origins.json +1 -0
- package/dist/runtime/prelude.mjs.map +1 -0
- package/dist/runtime/unicode-case-data.mjs +1 -95
- package/dist/runtime/unicode-case-data.mjs.map +1 -1
- package/dist/runtime/unicode-case.mjs +3 -97
- package/dist/runtime/unicode-case.mjs.map +1 -1
- package/dist/stage3-release.json +1 -1
- package/editor/README.md +9 -4
- package/editor/eliscript-compat.el +164 -2
- package/editor/eliscript-mode.el +1 -1
- package/editor/eliscript-repl.el +1 -1
- package/package.json +2 -1
- package/runtime/README.md +21 -1
- package/runtime/core/protocol-impl.mjs +1 -115
- package/runtime/core/protocol-impl.mjs.map +1 -1
- package/runtime/core/text-impl.mjs +1 -90
- package/runtime/core/text-impl.mjs.map +1 -1
- package/runtime/core/vector.eli +1 -1
- package/runtime/core/vector.mjs +0 -9
- package/runtime/emacs-compat.eli +5957 -2
- package/runtime/emacs-compat.mjs +13522 -2295
- package/runtime/emacs-compat.mjs.map +1 -0
- package/runtime/math.mjs +62 -252
- package/runtime/math.mjs.map +1 -1
- package/runtime/prelude.eli +4 -0
- package/runtime/prelude.mjs +95 -0
- package/runtime/prelude.mjs.map +1 -0
- package/runtime/unicode-case-data.mjs +1 -95
- package/runtime/unicode-case-data.mjs.map +1 -1
- package/runtime/unicode-case.mjs +3 -97
- package/runtime/unicode-case.mjs.map +1 -1
- package/stdlib/managed-literals.eli +1 -1
- package/stdlib/managed-runtime-vector.eli +2 -4
- package/tools/backends/compiler-build.mjs +3 -93
- package/tools/backends/compiler-cli.mjs +2 -15
- package/tools/backends/compiler-corpus-bit.mjs +2 -95
- package/tools/backends/compiler-corpus-cli-adapters.mjs +1 -97
- package/tools/backends/compiler-corpus-debugging.mjs +2 -95
- package/tools/backends/compiler-corpus-emitter.mjs +1 -97
- package/tools/backends/compiler-corpus-execution.mjs +2 -108
- package/tools/backends/compiler-corpus-fuzz.mjs +2 -95
- package/tools/backends/compiler-corpus-host-context.mjs +2 -99
- package/tools/backends/compiler-corpus-identity-host.mjs +18 -123
- package/tools/backends/compiler-corpus-identity-value-adapters.mjs +0 -9
- package/tools/backends/compiler-corpus-literal-provider.mjs +1 -91
- package/tools/backends/compiler-corpus-managed-adapters.mjs +1 -99
- package/tools/backends/compiler-corpus-managed-fixtures.mjs +2 -113
- package/tools/backends/compiler-corpus-matchers.mjs +3 -106
- package/tools/backends/compiler-corpus-original-program.mjs +1 -91
- package/tools/backends/compiler-corpus-process.mjs +1 -92
- package/tools/backends/compiler-corpus-program-driver.mjs +1 -3
- package/tools/backends/compiler-corpus-project-adapters.mjs +1 -95
- package/tools/backends/compiler-corpus-project-entry-host.mjs +2 -92
- package/tools/backends/compiler-corpus-project-transport.mjs +1 -90
- package/tools/backends/compiler-corpus-raw-fixture-observer.mjs +1 -91
- package/tools/backends/compiler-corpus-raw-language-fixtures.mjs +1 -92
- package/tools/backends/compiler-corpus-raw-math-fixture.mjs +1 -91
- package/tools/backends/compiler-corpus-raw-special-fixtures.mjs +1 -91
- package/tools/backends/compiler-corpus-reference.mjs +1 -90
- package/tools/backends/compiler-corpus-runtime-adapters.mjs +2 -110
- package/tools/backends/compiler-corpus-tools-cli.mjs +1 -95
- package/tools/backends/compiler-corpus-tools-reference.mjs +22 -163
- package/tools/backends/compiler-corpus.mjs +3 -125
- package/tools/backends/compiler-matrix.mjs +1 -92
- package/tools/backends/compiler-package-browser.mjs +1 -90
- package/tools/backends/compiler-package.mjs +3 -95
- package/tools/backends/compiler-unicode-profile-host.mjs +1 -91
- package/tools/backends/dist/bootstrap-js-stages.mjs +1 -91
- package/tools/backends/dist/bootstrap-js-stages.mjs.map +1 -1
- package/tools/backends/dist/managed-ir-inventory.mjs +1 -91
- package/tools/backends/dist/managed-ir-inventory.mjs.map +1 -1
- package/tools/backends/dist/record-grid.mjs +1 -91
- package/tools/backends/dist/record-grid.mjs.map +1 -1
- package/tools/backends/dist/release-cli.mjs +4 -94
- package/tools/backends/dist/release-cli.mjs.map +1 -1
- package/tools/backends/dist/run-artifact.mjs +1 -91
- package/tools/backends/dist/run-artifact.mjs.map +1 -1
- package/tools/backends/eliscript/compiler-corpus-bit.eli +1 -0
- package/tools/backends/managed-foreign-binding.mjs +1 -95
- package/tools/backends/managed-host-lifecycle.mjs +1 -91
- package/tools/backends/managed-host-object-provider.mjs +18 -59
- package/tools/backends/managed-host-object-realm.mjs +1 -91
- package/tools/backends/managed-host-proxy.mjs +9 -18
- package/tools/backends/managed-host-runtime.mjs +3 -105
- package/tools/backends/managed-host.mjs +1 -104
- package/tools/backends/managed-module-graph.mjs +1 -97
- package/tools/backends/managed-runtime.mjs +1 -96
- package/tools/backends/managed-source-view.mjs +13 -108
- package/tools/backends/native-managed-runtime.mjs +1 -91
- package/tools/backends/native-memory.mjs +1 -91
- package/tools/backends/stage3-targets.mjs +1 -91
- package/tools/bootstrap-runtime.el +3 -2
- package/tools/project/project.eli +1 -1
- package/tools/testing/stdlib-bit-corpus-host.mjs +1 -90
- package/tools/testing/stdlib-bit.mjs +1 -90
- package/dist/bootstrap/package.json +0 -1
- package/dist/bootstrap/runtime/math.mjs +0 -1117
- package/dist/bootstrap/runtime/math.mjs.map +0 -1
- package/dist/bootstrap/runtime/unicode-case-data.mjs +0 -10125
- package/dist/bootstrap/runtime/unicode-case-data.mjs.map +0 -1
- package/dist/bootstrap/runtime/unicode-case.mjs +0 -281
- package/dist/bootstrap/runtime/unicode-case.mjs.map +0 -1
package/editor/README.md
CHANGED
|
@@ -8,16 +8,21 @@ mode for `.eli` source. Add this directory to `load-path` and require the mode:
|
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
11
|
-
The mode
|
|
12
|
-
`
|
|
13
|
-
`
|
|
14
|
-
|
|
11
|
+
The mode, its evaluation library, and the `0.1.0`/`0.1.1` `1+5+2` Emacs-compatible
|
|
12
|
+
extension libraries (`eliscript-compat.el`, `eliscript-contract.el`,
|
|
13
|
+
`eliscript-data.el`, `eliscript-bind.el`, `eliscript-module.el`,
|
|
14
|
+
`eliscript-async.el`, `eliscript-js.el`, and `eliscript-abi.el`) are ordinary
|
|
15
|
+
Emacs packages. All carry `Version: 0.1.1`, `Package-Requires: ((emacs "29.1"))`,
|
|
16
|
+
and the standard `Author`, `Keywords`, and `URL` fields, so
|
|
17
|
+
`package-buffer-info` reads them and an archive or a source checkout can
|
|
18
|
+
install them.
|
|
15
19
|
|
|
16
20
|
From a checkout, without installing anything:
|
|
17
21
|
|
|
18
22
|
```elisp
|
|
19
23
|
(add-to-list 'load-path "/path/to/eliscript/editor")
|
|
20
24
|
(require 'eliscript-mode)
|
|
25
|
+
(require 'eliscript-compat) ; loads the 0.1.0 1+5+2 extension packs in Emacs
|
|
21
26
|
```
|
|
22
27
|
|
|
23
28
|
From the repository itself, using Emacs 29 or newer, which fetches the sources
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
;;; Code:
|
|
10
10
|
|
|
11
11
|
(require 'cl-lib)
|
|
12
|
+
(require 'json)
|
|
12
13
|
(require 'eliscript-contract)
|
|
13
14
|
(require 'eliscript-data)
|
|
14
15
|
(require 'eliscript-bind)
|
|
@@ -83,6 +84,20 @@
|
|
|
83
84
|
(defvar eliscript-compat--session-touched-symbols nil
|
|
84
85
|
"Symbols created or modified during the current evaluation session.")
|
|
85
86
|
|
|
87
|
+
(defvar eliscript-compat--accelerated-functions nil
|
|
88
|
+
"Alist of (FN-SYM . ORIG-FN) modified by `eliscript-compat-accelerate-function'.")
|
|
89
|
+
|
|
90
|
+
(defconst eliscript-compat--project-directory
|
|
91
|
+
(expand-file-name
|
|
92
|
+
".."
|
|
93
|
+
(file-name-directory (or load-file-name buffer-file-name default-directory)))
|
|
94
|
+
"Root directory of the Eliscript project.")
|
|
95
|
+
|
|
96
|
+
(declare-function eliscript-worker-live-p "eliscript-worker" (worker))
|
|
97
|
+
(declare-function eliscript-worker-call-sync "eliscript-worker"
|
|
98
|
+
(worker module export arguments &rest keys))
|
|
99
|
+
(declare-function eliscript-compile-file "eliscript" (input-file &optional output-file))
|
|
100
|
+
|
|
86
101
|
(progn
|
|
87
102
|
(defun eliscript-compat-reset-state! ()
|
|
88
103
|
"Restore clean 0.1.0 evaluation state and canonical extension bindings."
|
|
@@ -90,6 +105,11 @@
|
|
|
90
105
|
(eliscript-data-reset-state!)
|
|
91
106
|
(eliscript-module-reset-state!)
|
|
92
107
|
(eliscript-async-reset-state!)
|
|
108
|
+
(dolist (pair eliscript-compat--accelerated-functions)
|
|
109
|
+
(when (symbolp (car pair))
|
|
110
|
+
(fset (car pair) (cdr pair))
|
|
111
|
+
(put (car pair) 'eliscript-compat-native-function nil)))
|
|
112
|
+
(setq eliscript-compat--accelerated-functions nil)
|
|
93
113
|
(dolist (sym eliscript-compat--session-touched-symbols)
|
|
94
114
|
(unless (gethash sym eliscript-compat--canonical-fn-cells)
|
|
95
115
|
(fmakunbound sym)
|
|
@@ -158,13 +178,38 @@
|
|
|
158
178
|
`(defun ,name ,args
|
|
159
179
|
,@(when doc (list doc))
|
|
160
180
|
,@wrapped))))
|
|
161
|
-
((memq head '(defvar defconst defmacro))
|
|
181
|
+
((memq head '(defvar defconst defmacro cl-defun))
|
|
162
182
|
(let ((name (nth 1 form)))
|
|
163
183
|
(when (symbolp name)
|
|
164
184
|
(push name eliscript-compat--session-touched-symbols)))
|
|
165
185
|
form)
|
|
166
186
|
(t form)))))
|
|
167
187
|
|
|
188
|
+
(defun eliscript-compat--collect-defined-functions (source)
|
|
189
|
+
"Return a list of function symbol names defined at top level in SOURCE."
|
|
190
|
+
(let ((names nil))
|
|
191
|
+
(with-temp-buffer
|
|
192
|
+
(insert source)
|
|
193
|
+
(goto-char (point-min))
|
|
194
|
+
(condition-case nil
|
|
195
|
+
(while t
|
|
196
|
+
(let ((form (read (current-buffer))))
|
|
197
|
+
(when (consp form)
|
|
198
|
+
(let ((head (car form))
|
|
199
|
+
(second (nth 1 form)))
|
|
200
|
+
(cond
|
|
201
|
+
((and (memq head '(defun cl-defun defun-case defun-bind defun-tail defun-async))
|
|
202
|
+
(symbolp second))
|
|
203
|
+
(cl-pushnew (symbol-name second) names :test #'equal))
|
|
204
|
+
((eq head 'progn)
|
|
205
|
+
(dolist (sub (cdr form))
|
|
206
|
+
(when (and (consp sub)
|
|
207
|
+
(memq (car sub) '(defun cl-defun defun-case defun-bind defun-tail defun-async))
|
|
208
|
+
(symbolp (nth 1 sub)))
|
|
209
|
+
(cl-pushnew (symbol-name (nth 1 sub)) names :test #'equal)))))))))
|
|
210
|
+
(end-of-file nil)))
|
|
211
|
+
(nreverse names)))
|
|
212
|
+
|
|
168
213
|
(progn
|
|
169
214
|
(defun eliscript-compat-eval-string (source)
|
|
170
215
|
"Read, statically check, and evaluate all forms in SOURCE string."
|
|
@@ -177,7 +222,124 @@
|
|
|
177
222
|
(let* ((raw-form (read (current-buffer)))
|
|
178
223
|
(checked-form (eliscript-compat--preprocess-form raw-form)))
|
|
179
224
|
(setq last-val (eval checked-form t))))
|
|
180
|
-
(end-of-file last-val)))))
|
|
225
|
+
(end-of-file last-val)))))
|
|
226
|
+
|
|
227
|
+
(defun eliscript-compat-eval-file (file)
|
|
228
|
+
"Read and evaluate unmodified Emacs Lisp or Eliscript FILE in 0.1.0 session."
|
|
229
|
+
(with-temp-buffer
|
|
230
|
+
(insert-file-contents file)
|
|
231
|
+
(eliscript-compat-eval-string (buffer-string))))
|
|
232
|
+
|
|
233
|
+
(defun eliscript-compat--eliscript-string (text)
|
|
234
|
+
"Return TEXT as a string literal readable by both Eliscript readers."
|
|
235
|
+
(concat "\""
|
|
236
|
+
(replace-regexp-in-string
|
|
237
|
+
"[\"\\[:cntrl:]\177]"
|
|
238
|
+
(lambda (match)
|
|
239
|
+
(pcase (aref match 0)
|
|
240
|
+
(?\" "\\\"") (?\\ "\\\\") (?\n "\\n") (?\t "\\t") (?\r "\\r")
|
|
241
|
+
(c (format "\\u%04x" c))))
|
|
242
|
+
text t t)
|
|
243
|
+
"\""))
|
|
244
|
+
|
|
245
|
+
(defun eliscript-compat--elisp-module-source (source function-names module-name)
|
|
246
|
+
"Return Eliscript module text that evaluates Elisp SOURCE in a session.
|
|
247
|
+
FUNCTION-NAMES are the top-level functions SOURCE defines; MODULE-NAME names
|
|
248
|
+
the generated module. The result is Eliscript, compiled like any other module."
|
|
249
|
+
(let ((print-length nil) (print-level nil) (print-circle nil)
|
|
250
|
+
(print-escape-newlines nil) (print-escape-nonascii nil))
|
|
251
|
+
(concat
|
|
252
|
+
"(module " (symbol-name (intern module-name)) "\n"
|
|
253
|
+
" (import \"eliscript/runtime/emacs-compat\""
|
|
254
|
+
" createCompatSession evalCompatProgram callCompatElisp invokeCompatFunction)\n"
|
|
255
|
+
" (defconst elisp-source " (eliscript-compat--eliscript-string source) ")\n"
|
|
256
|
+
" (defconst elisp-function-names (js-array"
|
|
257
|
+
(mapconcat (lambda (name) (concat " " (eliscript-compat--eliscript-string name))) function-names "")
|
|
258
|
+
"))\n"
|
|
259
|
+
" (defconst session (createCompatSession))\n"
|
|
260
|
+
" (defconst loaded (evalCompatProgram elisp-source (js-object :session session)))\n"
|
|
261
|
+
" (defun callElisp (name arguments) (callCompatElisp session name arguments))\n"
|
|
262
|
+
" (defun invokeElisp (name &rest arguments) (invokeCompatFunction session name arguments))\n"
|
|
263
|
+
" (defun elispFunctions () (js-call elisp-function-names :slice))\n"
|
|
264
|
+
" (export callElisp invokeElisp elispFunctions))\n")))
|
|
265
|
+
|
|
266
|
+
(defun eliscript-compat-compile-elisp-module (el-files out-mjs-file)
|
|
267
|
+
"Compile one or more unmodified EL-FILES into a Worker-ready OUT-MJS-FILE.
|
|
268
|
+
The intermediate Eliscript module is written next to OUT-MJS-FILE with the
|
|
269
|
+
extension .eli and compiled by the maintained Emacs Lisp Eliscript compiler.
|
|
270
|
+
OUT-MJS-FILE must be inside a project that resolves the `eliscript' package.
|
|
271
|
+
Return the absolute path of OUT-MJS-FILE."
|
|
272
|
+
(let* ((files (if (listp el-files) el-files (list el-files)))
|
|
273
|
+
(combined
|
|
274
|
+
(mapconcat
|
|
275
|
+
(lambda (f)
|
|
276
|
+
(with-temp-buffer
|
|
277
|
+
(insert-file-contents (expand-file-name f))
|
|
278
|
+
(buffer-string)))
|
|
279
|
+
files
|
|
280
|
+
"\n"))
|
|
281
|
+
(out-mjs (expand-file-name out-mjs-file))
|
|
282
|
+
(out-eli (concat (file-name-sans-extension out-mjs) ".eli"))
|
|
283
|
+
(module-name (concat "eliscript.generated."
|
|
284
|
+
(replace-regexp-in-string
|
|
285
|
+
"[^A-Za-z0-9-]" "-" (file-name-base out-mjs)))))
|
|
286
|
+
(unless (featurep 'eliscript)
|
|
287
|
+
(add-to-list 'load-path (expand-file-name "compiler" eliscript-compat--project-directory))
|
|
288
|
+
(require 'eliscript))
|
|
289
|
+
(make-directory (file-name-directory out-mjs) t)
|
|
290
|
+
(let ((coding-system-for-write 'utf-8-unix))
|
|
291
|
+
(with-temp-file out-eli
|
|
292
|
+
(insert (eliscript-compat--elisp-module-source
|
|
293
|
+
combined
|
|
294
|
+
(eliscript-compat--collect-defined-functions combined)
|
|
295
|
+
module-name))))
|
|
296
|
+
(eliscript-compile-file out-eli out-mjs)
|
|
297
|
+
out-mjs))
|
|
298
|
+
|
|
299
|
+
(defun eliscript-compat--native-function (fn-sym)
|
|
300
|
+
"Return the native Emacs Lisp definition of FN-SYM."
|
|
301
|
+
(or (get fn-sym 'eliscript-compat-native-function)
|
|
302
|
+
(symbol-function fn-sym)))
|
|
303
|
+
|
|
304
|
+
(defun eliscript-compat-offload-call (worker mjs-file fn-sym &rest args)
|
|
305
|
+
"Invoke FN-SYM with ARGS in MJS-FILE on WORKER, falling back to native Elisp.
|
|
306
|
+
Arguments and the result cross the Worker boundary as printed Emacs Lisp text
|
|
307
|
+
through the module export `callElisp'. Without a live WORKER, or when the
|
|
308
|
+
Worker call fails, the native definition of FN-SYM runs instead."
|
|
309
|
+
(if (and worker
|
|
310
|
+
(fboundp 'eliscript-worker-live-p)
|
|
311
|
+
(eliscript-worker-live-p worker)
|
|
312
|
+
(fboundp 'eliscript-worker-call-sync))
|
|
313
|
+
(condition-case nil
|
|
314
|
+
(let* ((sexp (let ((print-length nil) (print-level nil)
|
|
315
|
+
(print-circle nil) (print-escape-newlines nil))
|
|
316
|
+
(prin1-to-string args)))
|
|
317
|
+
(reply (eliscript-worker-call-sync
|
|
318
|
+
worker (expand-file-name mjs-file) "callElisp"
|
|
319
|
+
(list (symbol-name fn-sym) sexp))))
|
|
320
|
+
(unless (stringp reply)
|
|
321
|
+
(error "Invalid Eliscript Worker reply"))
|
|
322
|
+
(car (read-from-string reply)))
|
|
323
|
+
(error (apply (eliscript-compat--native-function fn-sym) args)))
|
|
324
|
+
(apply (eliscript-compat--native-function fn-sym) args)))
|
|
325
|
+
|
|
326
|
+
(defun eliscript-compat-accelerate-function (fn-sym mjs-file &optional worker-getter predicate)
|
|
327
|
+
"Install transparent Eliscript Worker acceleration on FN-SYM using MJS-FILE."
|
|
328
|
+
(let ((orig (or (get fn-sym 'eliscript-compat-native-function)
|
|
329
|
+
(symbol-function fn-sym))))
|
|
330
|
+
(unless (get fn-sym 'eliscript-compat-native-function)
|
|
331
|
+
(put fn-sym 'eliscript-compat-native-function orig)
|
|
332
|
+
(push (cons fn-sym orig) eliscript-compat--accelerated-functions))
|
|
333
|
+
(fset fn-sym
|
|
334
|
+
(lambda (&rest args)
|
|
335
|
+
(let ((worker (and worker-getter (funcall worker-getter))))
|
|
336
|
+
(if (and worker
|
|
337
|
+
(fboundp 'eliscript-worker-live-p)
|
|
338
|
+
(eliscript-worker-live-p worker)
|
|
339
|
+
(or (null predicate) (apply predicate args)))
|
|
340
|
+
(apply #'eliscript-compat-offload-call worker mjs-file fn-sym args)
|
|
341
|
+
(apply orig args)))))
|
|
342
|
+
fn-sym)))
|
|
181
343
|
|
|
182
344
|
(provide 'eliscript-compat)
|
|
183
345
|
|
package/editor/eliscript-mode.el
CHANGED
package/editor/eliscript-repl.el
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eliscript",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "An Emacs Lisp-flavored language that compiles to modern JavaScript.",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"repository": {
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"exports": {
|
|
22
22
|
"./runtime/math.mjs": "./runtime/math.mjs",
|
|
23
|
+
"./runtime/prelude.mjs": "./runtime/prelude.mjs",
|
|
23
24
|
"./runtime/emacs-compat": "./runtime/emacs-compat.mjs",
|
|
24
25
|
"./runtime/emacs-compat.mjs": "./runtime/emacs-compat.mjs",
|
|
25
26
|
"./runtime/unicode-case": "./runtime/unicode-case.mjs",
|
package/runtime/README.md
CHANGED
|
@@ -11,7 +11,8 @@ should still be emitted directly; helpers need a concrete semantic reason to
|
|
|
11
11
|
exist.
|
|
12
12
|
|
|
13
13
|
All runtime modules in this directory (`literals.eli`, `worker.eli`,
|
|
14
|
-
`math.eli`, `
|
|
14
|
+
`math.eli`, `prelude.eli`, `emacs-compat.eli`, `unicode-case.eli`,
|
|
15
|
+
`core/*.eli`, `testing/*.eli`, and `wire/*.eli`)
|
|
15
16
|
are maintained as `.eli` sources in Git and materialized or compiled to `.mjs`
|
|
16
17
|
during `make bootstrap-backends` (zero tracked `.mjs` files in the repository).
|
|
17
18
|
Eliscript modules may import `eliscript/runtime/*` either without the `.mjs`
|
|
@@ -22,6 +23,12 @@ The compiler still emits a local Lisp-truthiness helper for standalone
|
|
|
22
23
|
generated forms. `core/truth.eli` (`core/truth.mjs`) exposes the same semantics
|
|
23
24
|
to shared runtime algorithms: only `false`, `null`, and `undefined` are false.
|
|
24
25
|
|
|
26
|
+
`prelude.eli` (`prelude.mjs`) holds the operation helpers that would otherwise
|
|
27
|
+
repeat in every generated module: array text access, number conversion,
|
|
28
|
+
numeric operator coercion, and 32-bit integer multiplication. The compiler
|
|
29
|
+
recognizes this exact empty module and emits the complete helper set; other
|
|
30
|
+
modules import only the `__eliscript_*` helpers their operations use.
|
|
31
|
+
|
|
25
32
|
Host libraries are imported explicitly by application modules. The runtime
|
|
26
33
|
contains no UI-framework wrapper, element constructor, or bundler adapter.
|
|
27
34
|
|
|
@@ -314,3 +321,16 @@ Request contexts now include a frozen `capabilities` token from
|
|
|
314
321
|
`platform/worker.mjs`, granting only progress and cancellation. The same
|
|
315
322
|
confined resolver accepts package-owned `eliscript/platform/` imports and
|
|
316
323
|
rejects traversal outside that directory.
|
|
324
|
+
|
|
325
|
+
### Dual-Host Emacs Lisp Compatibility Runtime
|
|
326
|
+
|
|
327
|
+
`emacs-compat.eli` (`emacs-compat.mjs`) is a 100% pure Eliscript module (zero
|
|
328
|
+
`js*` capsules) that provides the `0.1.0`/`0.1.1` 100% Emacs Lisp-compatible
|
|
329
|
+
kernel, the explicit `1+5+2` extension libraries (`eliscript-contract`,
|
|
330
|
+
`eliscript-data`, `eliscript-bind`, `eliscript-module`, `eliscript-async`,
|
|
331
|
+
`eliscript-js`, `eliscript-abi`), industrial Emacs Lisp standard-library
|
|
332
|
+
primitives (`cl-defstruct`, `setf`/`cl-incf`/`cl-decf`/`push`/`pop`, `pcase`,
|
|
333
|
+
`cl-labels`/`cl-flet`/`cl-loop`, `rx`, pure Eliscript UTF-8 and SHA-256
|
|
334
|
+
`secure-hash`, virtual `with-temp-buffer`, and Emacs regular-expression
|
|
335
|
+
translation), and `compileCompatElispModule` / `callCompatElisp` for compiling
|
|
336
|
+
unmodified `.el` modules into ES modules accelerated by `eliscript-worker`.
|
|
@@ -2,169 +2,55 @@
|
|
|
2
2
|
import { tdz as __eliscript_tdz_error, immutable as __eliscript_const_error } from "data:text/javascript;base64,Y29uc3QgRSA9IFJlZmVyZW5jZUVycm9yOyBjb25zdCBUID0gVHlwZUVycm9yOyBleHBvcnQgZnVuY3Rpb24gdGR6KG5hbWUpIHsgdGhyb3cgbmV3IEUoIkNhbm5vdCBhY2Nlc3MgJyIgKyBuYW1lICsgIicgYmVmb3JlIGluaXRpYWxpemF0aW9uIik7IH0gZXhwb3J0IGZ1bmN0aW9uIGltbXV0YWJsZSgpIHsgdGhyb3cgbmV3IFQoIkFzc2lnbm1lbnQgdG8gY29uc3RhbnQgdmFyaWFibGUuIik7IH0K";
|
|
3
3
|
var __eliscript_tdz_ready_0;
|
|
4
4
|
function __eliscript_tdz_read_0() { if (__eliscript_tdz_ready_0 !== true) __eliscript_tdz_error("protocol_states"); return protocol_states; }
|
|
5
|
-
function __eliscript_tdz_write_0(__eliscript_tdz_value_0) { if (__eliscript_tdz_ready_0 !== true) __eliscript_tdz_error("protocol_states"); return __eliscript_const_error(); }
|
|
6
5
|
var __eliscript_tdz_ready_1;
|
|
7
6
|
function __eliscript_tdz_read_1() { if (__eliscript_tdz_ready_1 !== true) __eliscript_tdz_error("protocol_operation_owners"); return protocol_operation_owners; }
|
|
8
|
-
function __eliscript_tdz_write_1(__eliscript_tdz_value_1) { if (__eliscript_tdz_ready_1 !== true) __eliscript_tdz_error("protocol_operation_owners"); return __eliscript_const_error(); }
|
|
9
7
|
var __eliscript_tdz_ready_2;
|
|
10
8
|
function __eliscript_tdz_read_2() { if (__eliscript_tdz_ready_2 !== true) __eliscript_tdz_error("protocol_method_owners"); return protocol_method_owners; }
|
|
11
|
-
function __eliscript_tdz_write_2(__eliscript_tdz_value_2) { if (__eliscript_tdz_ready_2 !== true) __eliscript_tdz_error("protocol_method_owners"); return __eliscript_const_error(); }
|
|
12
9
|
var __eliscript_tdz_ready_3;
|
|
13
10
|
function __eliscript_tdz_read_3() { if (__eliscript_tdz_ready_3 !== true) __eliscript_tdz_error("protocol_missing"); return protocol_missing; }
|
|
14
|
-
function __eliscript_tdz_write_3(__eliscript_tdz_value_3) { if (__eliscript_tdz_ready_3 !== true) __eliscript_tdz_error("protocol_missing"); return __eliscript_const_error(); }
|
|
15
11
|
var __eliscript_tdz_ready_4;
|
|
16
12
|
function __eliscript_tdz_read_4() { if (__eliscript_tdz_ready_4 !== true) __eliscript_tdz_error("protocol_host_categories"); return protocol_host_categories; }
|
|
17
|
-
function __eliscript_tdz_write_4(__eliscript_tdz_value_4) { if (__eliscript_tdz_ready_4 !== true) __eliscript_tdz_error("protocol_host_categories"); return __eliscript_const_error(); }
|
|
18
13
|
var __eliscript_tdz_ready_5;
|
|
19
14
|
function __eliscript_tdz_read_5() { if (__eliscript_tdz_ready_5 !== true) __eliscript_tdz_error("protocol_definition_format"); return protocol_definition_format; }
|
|
20
|
-
function __eliscript_tdz_write_5(__eliscript_tdz_value_5) { if (__eliscript_tdz_ready_5 !== true) __eliscript_tdz_error("protocol_definition_format"); return __eliscript_const_error(); }
|
|
21
15
|
var __eliscript_tdz_ready_6;
|
|
22
16
|
function __eliscript_tdz_read_6() { if (__eliscript_tdz_ready_6 !== true) __eliscript_tdz_error("protocol_definition_version"); return protocol_definition_version; }
|
|
23
|
-
function __eliscript_tdz_write_6(__eliscript_tdz_value_6) { if (__eliscript_tdz_ready_6 !== true) __eliscript_tdz_error("protocol_definition_version"); return __eliscript_const_error(); }
|
|
24
17
|
var __eliscript_tdz_ready_7;
|
|
25
18
|
function __eliscript_tdz_read_7() { if (__eliscript_tdz_ready_7 !== true) __eliscript_tdz_error("protocol_max_operations"); return protocol_max_operations; }
|
|
26
|
-
function __eliscript_tdz_write_7(__eliscript_tdz_value_7) { if (__eliscript_tdz_ready_7 !== true) __eliscript_tdz_error("protocol_max_operations"); return __eliscript_const_error(); }
|
|
27
19
|
var __eliscript_tdz_ready_8;
|
|
28
20
|
function __eliscript_tdz_read_8() { if (__eliscript_tdz_ready_8 !== true) __eliscript_tdz_error("protocol_symbol"); return protocol_symbol; }
|
|
29
|
-
function __eliscript_tdz_write_8(__eliscript_tdz_value_8) { if (__eliscript_tdz_ready_8 !== true) __eliscript_tdz_error("protocol_symbol"); return __eliscript_const_error(); }
|
|
30
21
|
var __eliscript_tdz_ready_9;
|
|
31
22
|
function __eliscript_tdz_read_9() { if (__eliscript_tdz_ready_9 !== true) __eliscript_tdz_error("protocol_array_QMARK_"); return protocol_array_QMARK_; }
|
|
32
|
-
function __eliscript_tdz_write_9(__eliscript_tdz_value_9) { if (__eliscript_tdz_ready_9 !== true) __eliscript_tdz_error("protocol_array_QMARK_"); return __eliscript_const_error(); }
|
|
33
23
|
var __eliscript_tdz_ready_10;
|
|
34
24
|
function __eliscript_tdz_read_10() { if (__eliscript_tdz_ready_10 !== true) __eliscript_tdz_error("protocol_map"); return protocol_map; }
|
|
35
|
-
function __eliscript_tdz_write_10(__eliscript_tdz_value_10) { if (__eliscript_tdz_ready_10 !== true) __eliscript_tdz_error("protocol_map"); return __eliscript_const_error(); }
|
|
36
25
|
var __eliscript_tdz_ready_11;
|
|
37
26
|
function __eliscript_tdz_read_11() { if (__eliscript_tdz_ready_11 !== true) __eliscript_tdz_error("protocol_null_object"); return protocol_null_object; }
|
|
38
|
-
function __eliscript_tdz_write_11(__eliscript_tdz_value_11) { if (__eliscript_tdz_ready_11 !== true) __eliscript_tdz_error("protocol_null_object"); return __eliscript_const_error(); }
|
|
39
27
|
var __eliscript_tdz_ready_12;
|
|
40
28
|
function __eliscript_tdz_read_12() { if (__eliscript_tdz_ready_12 !== true) __eliscript_tdz_error("protocol_own_descriptors"); return protocol_own_descriptors; }
|
|
41
|
-
function __eliscript_tdz_write_12(__eliscript_tdz_value_12) { if (__eliscript_tdz_ready_12 !== true) __eliscript_tdz_error("protocol_own_descriptors"); return __eliscript_const_error(); }
|
|
42
29
|
var __eliscript_tdz_ready_13;
|
|
43
30
|
function __eliscript_tdz_read_13() { if (__eliscript_tdz_ready_13 !== true) __eliscript_tdz_error("protocol_own_keys"); return protocol_own_keys; }
|
|
44
|
-
function __eliscript_tdz_write_13(__eliscript_tdz_value_13) { if (__eliscript_tdz_ready_13 !== true) __eliscript_tdz_error("protocol_own_keys"); return __eliscript_const_error(); }
|
|
45
31
|
var __eliscript_tdz_ready_14;
|
|
46
32
|
function __eliscript_tdz_read_14() { if (__eliscript_tdz_ready_14 !== true) __eliscript_tdz_error("protocol_has_own"); return protocol_has_own; }
|
|
47
|
-
function __eliscript_tdz_write_14(__eliscript_tdz_value_14) { if (__eliscript_tdz_ready_14 !== true) __eliscript_tdz_error("protocol_has_own"); return __eliscript_const_error(); }
|
|
48
33
|
var __eliscript_tdz_ready_15;
|
|
49
34
|
function __eliscript_tdz_read_15() { if (__eliscript_tdz_ready_15 !== true) __eliscript_tdz_error("protocol_property_present"); return protocol_property_present; }
|
|
50
|
-
function __eliscript_tdz_write_15(__eliscript_tdz_value_15) { if (__eliscript_tdz_ready_15 !== true) __eliscript_tdz_error("protocol_property_present"); return __eliscript_const_error(); }
|
|
51
35
|
var __eliscript_tdz_ready_16;
|
|
52
36
|
function __eliscript_tdz_read_16() { if (__eliscript_tdz_ready_16 !== true) __eliscript_tdz_error("protocol_property_value"); return protocol_property_value; }
|
|
53
|
-
function __eliscript_tdz_write_16(__eliscript_tdz_value_16) { if (__eliscript_tdz_ready_16 !== true) __eliscript_tdz_error("protocol_property_value"); return __eliscript_const_error(); }
|
|
54
37
|
var __eliscript_tdz_ready_17;
|
|
55
38
|
function __eliscript_tdz_read_17() { if (__eliscript_tdz_ready_17 !== true) __eliscript_tdz_error("protocol_host_type"); return protocol_host_type; }
|
|
56
|
-
function __eliscript_tdz_write_17(__eliscript_tdz_value_17) { if (__eliscript_tdz_ready_17 !== true) __eliscript_tdz_error("protocol_host_type"); return __eliscript_const_error(); }
|
|
57
39
|
var __eliscript_tdz_ready_18;
|
|
58
40
|
function __eliscript_tdz_read_18() { if (__eliscript_tdz_ready_18 !== true) __eliscript_tdz_error("protocol_exact_prototype"); return protocol_exact_prototype; }
|
|
59
|
-
function __eliscript_tdz_write_18(__eliscript_tdz_value_18) { if (__eliscript_tdz_ready_18 !== true) __eliscript_tdz_error("protocol_exact_prototype"); return __eliscript_const_error(); }
|
|
60
41
|
var __eliscript_tdz_ready_19;
|
|
61
42
|
function __eliscript_tdz_read_19() { if (__eliscript_tdz_ready_19 !== true) __eliscript_tdz_error("protocol_object_prototype"); return protocol_object_prototype; }
|
|
62
|
-
function __eliscript_tdz_write_19(__eliscript_tdz_value_19) { if (__eliscript_tdz_ready_19 !== true) __eliscript_tdz_error("protocol_object_prototype"); return __eliscript_const_error(); }
|
|
63
43
|
var __eliscript_tdz_ready_20;
|
|
64
44
|
function __eliscript_tdz_read_20() { if (__eliscript_tdz_ready_20 !== true) __eliscript_tdz_error("protocol_get_prototype"); return protocol_get_prototype; }
|
|
65
|
-
function __eliscript_tdz_write_20(__eliscript_tdz_value_20) { if (__eliscript_tdz_ready_20 !== true) __eliscript_tdz_error("protocol_get_prototype"); return __eliscript_const_error(); }
|
|
66
45
|
var __eliscript_tdz_ready_21;
|
|
67
46
|
function __eliscript_tdz_read_21() { if (__eliscript_tdz_ready_21 !== true) __eliscript_tdz_error("protocol_freeze"); return protocol_freeze; }
|
|
68
|
-
function __eliscript_tdz_write_21(__eliscript_tdz_value_21) { if (__eliscript_tdz_ready_21 !== true) __eliscript_tdz_error("protocol_freeze"); return __eliscript_const_error(); }
|
|
69
47
|
var __eliscript_tdz_ready_22;
|
|
70
48
|
function __eliscript_tdz_read_22() { if (__eliscript_tdz_ready_22 !== true) __eliscript_tdz_error("protocol_define_enumerable"); return protocol_define_enumerable; }
|
|
71
|
-
function __eliscript_tdz_write_22(__eliscript_tdz_value_22) { if (__eliscript_tdz_ready_22 !== true) __eliscript_tdz_error("protocol_define_enumerable"); return __eliscript_const_error(); }
|
|
72
49
|
var __eliscript_tdz_ready_23;
|
|
73
50
|
function __eliscript_tdz_read_23() { if (__eliscript_tdz_ready_23 !== true) __eliscript_tdz_error("protocol_define_metadata"); return protocol_define_metadata; }
|
|
74
|
-
function __eliscript_tdz_write_23(__eliscript_tdz_value_23) { if (__eliscript_tdz_ready_23 !== true) __eliscript_tdz_error("protocol_define_metadata"); return __eliscript_const_error(); }
|
|
75
51
|
import "eliscript/runtime/unicode-case.mjs";
|
|
76
|
-
import {
|
|
52
|
+
import { __eliscript_at, __eliscript_at_direct, __eliscript_to_number, __eliscript_numeric_decrement, __eliscript_numeric_relation, __eliscript_numeric_sub, __eliscript_numeric_mul, __eliscript_numeric_div, __eliscript_numeric_rem, __eliscript_numeric_and, __eliscript_numeric_or, __eliscript_numeric_xor, __eliscript_numeric_shl, __eliscript_numeric_shr, __eliscript_numeric_ushr, __eliscript_numeric_neg, __eliscript_numeric_int32, __eliscript_numeric_uint32, __eliscript_numeric_not } from "eliscript/runtime/prelude.mjs";
|
|
77
53
|
const __eliscript_truthy = (value) => value !== false && value != null;
|
|
78
|
-
const __eliscript_number_intrinsic = globalThis.Number;
|
|
79
|
-
const __eliscript_bigint_intrinsic = globalThis.BigInt;
|
|
80
|
-
const __eliscript_numeric_apply = globalThis.Reflect.apply;
|
|
81
|
-
const __eliscript_numeric_symbol = globalThis.Symbol.toPrimitive;
|
|
82
|
-
const __eliscript_numeric_error = globalThis.TypeError;
|
|
83
|
-
const __eliscript_numeric_trim = globalThis.String.prototype.trim;
|
|
84
|
-
const __eliscript_numeric_slice = globalThis.String.prototype.slice;
|
|
85
|
-
const __eliscript_numeric_exec = globalThis.RegExp.prototype.exec;
|
|
86
|
-
const __eliscript_numeric_radix = /^(?:0[xX][0-9a-fA-F]+|0[oO][0-7]+|0[bB][01]+)$/;
|
|
87
|
-
const __eliscript_numeric_object = (value) => value !== null && (typeof value === "object" || typeof value === "function" || (typeof value === "undefined" && value !== void 0));
|
|
88
|
-
const __eliscript_numeric_primitive = (value) => {
|
|
89
|
-
if (!__eliscript_numeric_object(value)) return value;
|
|
90
|
-
const exotic = value[__eliscript_numeric_symbol];
|
|
91
|
-
if (exotic !== void 0 && exotic !== null) {
|
|
92
|
-
const result = __eliscript_numeric_apply(exotic, value, ["number"]);
|
|
93
|
-
if (!__eliscript_numeric_object(result)) return result;
|
|
94
|
-
throw new __eliscript_numeric_error("Cannot convert object to primitive value");
|
|
95
|
-
}
|
|
96
|
-
for (let index = 0; index < 2; index++) {
|
|
97
|
-
const method = value[index === 0 ? "valueOf" : "toString"];
|
|
98
|
-
if (typeof method === "function" || (typeof method === "undefined" && method !== void 0)) {
|
|
99
|
-
const result = __eliscript_numeric_apply(method, value, []);
|
|
100
|
-
if (!__eliscript_numeric_object(result)) return result;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
throw new __eliscript_numeric_error("Cannot convert object to primitive value");
|
|
104
|
-
};
|
|
105
|
-
const __eliscript_to_number = (value) => {
|
|
106
|
-
const primitive = __eliscript_numeric_primitive(value);
|
|
107
|
-
if (typeof primitive === "string") {
|
|
108
|
-
const text = __eliscript_numeric_apply(__eliscript_numeric_trim, primitive, []);
|
|
109
|
-
if (__eliscript_numeric_apply(__eliscript_numeric_exec, __eliscript_numeric_radix, [text]) !== null) {
|
|
110
|
-
let first = 2;
|
|
111
|
-
while (first < text.length && text[first] === "0") first++;
|
|
112
|
-
if (first === text.length) return 0;
|
|
113
|
-
const prefix = text[1];
|
|
114
|
-
const limit = prefix === "x" || prefix === "X" ? 256 : prefix === "b" || prefix === "B" ? 1024 : 342;
|
|
115
|
-
if (text.length - first > limit) return 1 / 0;
|
|
116
|
-
const token = __eliscript_numeric_apply(__eliscript_numeric_slice, text, [0, 2]) + __eliscript_numeric_apply(__eliscript_numeric_slice, text, [first]);
|
|
117
|
-
return __eliscript_number_intrinsic(__eliscript_bigint_intrinsic(token));
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return __eliscript_number_intrinsic(primitive);
|
|
121
|
-
};
|
|
122
|
-
const __eliscript_numeric = (value) => {
|
|
123
|
-
if (typeof value === "number" || typeof value === "bigint") return value;
|
|
124
|
-
const primitive = __eliscript_numeric_primitive(value);
|
|
125
|
-
if (typeof primitive === "number" || typeof primitive === "bigint") return primitive;
|
|
126
|
-
return typeof primitive === "string" ? __eliscript_to_number(primitive) : +primitive;
|
|
127
|
-
};
|
|
128
|
-
const __eliscript_implicit_number = (value) => {
|
|
129
|
-
if (typeof value === "number") return value;
|
|
130
|
-
const primitive = __eliscript_numeric_primitive(value);
|
|
131
|
-
if (typeof primitive === "bigint") throw new __eliscript_numeric_error("Cannot convert a BigInt value to a number");
|
|
132
|
-
return typeof primitive === "string" ? __eliscript_to_number(primitive) : +primitive;
|
|
133
|
-
};
|
|
134
|
-
const __eliscript_numeric_decrement = (value) => __eliscript_implicit_number(value) - 1;
|
|
135
|
-
const __eliscript_numeric_sub = (a, b) => { if (typeof a === "number" && typeof b === "number") return a - b; return __eliscript_numeric(a) - __eliscript_numeric(b); };
|
|
136
|
-
const __eliscript_numeric_mul = (a, b) => { if (typeof a === "number" && typeof b === "number") return a * b; return __eliscript_numeric(a) * __eliscript_numeric(b); };
|
|
137
|
-
const __eliscript_numeric_div = (a, b) => { if (typeof a === "number" && typeof b === "number") return a / b; return __eliscript_numeric(a) / __eliscript_numeric(b); };
|
|
138
|
-
const __eliscript_numeric_rem = (a, b) => { if (typeof a === "number" && typeof b === "number") return a % b; return __eliscript_numeric(a) % __eliscript_numeric(b); };
|
|
139
|
-
const __eliscript_numeric_and = (a, b) => { if (typeof a === "number" && typeof b === "number") return a & b; return __eliscript_numeric(a) & __eliscript_numeric(b); };
|
|
140
|
-
const __eliscript_numeric_or = (a, b) => { if (typeof a === "number" && typeof b === "number") return a | b; return __eliscript_numeric(a) | __eliscript_numeric(b); };
|
|
141
|
-
const __eliscript_numeric_xor = (a, b) => { if (typeof a === "number" && typeof b === "number") return a ^ b; return __eliscript_numeric(a) ^ __eliscript_numeric(b); };
|
|
142
|
-
const __eliscript_numeric_shl = (a, b) => { if (typeof a === "number" && typeof b === "number") return a << b; return __eliscript_numeric(a) << __eliscript_numeric(b); };
|
|
143
|
-
const __eliscript_numeric_shr = (a, b) => { if (typeof a === "number" && typeof b === "number") return a >> b; return __eliscript_numeric(a) >> __eliscript_numeric(b); };
|
|
144
|
-
const __eliscript_numeric_ushr = (a, b) => { if (typeof a === "number" && typeof b === "number") return a >>> b; return __eliscript_numeric(a) >>> __eliscript_numeric(b); };
|
|
145
|
-
const __eliscript_numeric_neg = (a) => typeof a === "number" ? -a : -__eliscript_numeric(a);
|
|
146
|
-
const __eliscript_numeric_int32 = (a) => typeof a === "number" ? a | 0 : __eliscript_numeric(a) | 0;
|
|
147
|
-
const __eliscript_numeric_uint32 = (a) => typeof a === "number" ? a >>> 0 : __eliscript_numeric(a) >>> 0;
|
|
148
|
-
const __eliscript_numeric_not = (a) => typeof a === "number" ? ~a : ~__eliscript_numeric(a);
|
|
149
|
-
const __eliscript_numeric_relation = (operator, left, right) => {
|
|
150
|
-
if (typeof left === "number" && typeof right === "number") {
|
|
151
|
-
if (operator === "<") return left < right;
|
|
152
|
-
if (operator === "<=") return left <= right;
|
|
153
|
-
if (operator === ">") return left > right;
|
|
154
|
-
return left >= right;
|
|
155
|
-
}
|
|
156
|
-
let a = __eliscript_numeric_primitive(left);
|
|
157
|
-
let b = __eliscript_numeric_primitive(right);
|
|
158
|
-
const x = typeof a, y = typeof b;
|
|
159
|
-
if (!((x === "string" && y === "string") || (x === "bigint" && y === "string") || (x === "string" && y === "bigint"))) {
|
|
160
|
-
a = __eliscript_numeric(a);
|
|
161
|
-
b = __eliscript_numeric(b);
|
|
162
|
-
}
|
|
163
|
-
if (operator === "<") return a < b;
|
|
164
|
-
if (operator === "<=") return a <= b;
|
|
165
|
-
if (operator === ">") return a > b;
|
|
166
|
-
return a >= b;
|
|
167
|
-
};
|
|
168
54
|
|
|
169
55
|
import {ProtocolDispatchError} from "../../runtime/core/protocol-error.mjs";
|
|
170
56
|
const protocol_states = new (globalThis.WeakMap)();
|