eliscript 0.0.4 → 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-abi.el +170 -0
- package/editor/eliscript-async.el +375 -0
- package/editor/eliscript-bind.el +822 -0
- package/editor/eliscript-compat.el +346 -0
- package/editor/eliscript-contract.el +334 -0
- package/editor/eliscript-data.el +1544 -0
- package/editor/eliscript-js.el +318 -0
- package/editor/eliscript-mode.el +1 -1
- package/editor/eliscript-module.el +340 -0
- package/editor/eliscript-repl.el +1 -1
- package/package.json +4 -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 -0
- package/runtime/emacs-compat.mjs +13734 -0
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backends/binary.mjs","sources":["bootstrap/backends/binary.eli"],"sourcesContent":["(module eliscript.backend.binary\n (import \"./numeric.mjs\" backend-fail)\n\n ;; Packed output owns bounded word batches and exact UTF16 strings. Each\n ;; code unit stores two little-endian bytes, including unpaired surrogates.\n ;; The ordinary byte-array API keeps its original representation.\n (defun binary-output (&optional options)\n (let ((configuration (or options (js-object))))\n (if (not (Object/hasOwn configuration \"binaryEncoding\")) (js-array)\n (if (= (get configuration :binaryEncoding) \"u16le-chunks\")\n (js-object :length 0 :chunks (js-array) :pending (js-array) :low -1)\n (backend-fail nil \"unsupported binary output encoding\")))))\n\n (defun binary-flush (output)\n (let ((pending (get output :pending)))\n (when (> (js-length pending) 0)\n (js-call (get output :chunks) :push\n (Reflect/apply (get globalThis.String :fromCharCode) nil pending))\n (put output :pending (js-array)))))\n\n (defun binary-unit (output value)\n (js-call (get output :pending) :push value)\n (when (= (js-length (get output :pending)) 2048) (binary-flush output)))\n\n (defun binary-byte (output value)\n (if (Array/isArray output) (js-call output :push (bit-and value 255))\n (progn\n (if (< (get output :low) 0) (put output :low (bit-and value 255))\n (progn\n (binary-unit output (+ (get output :low) (* (bit-and value 255) 256)))\n (put output :low -1)))\n (put output :length (1+ (get output :length)))))\n output)\n\n (defun binary-u32 (output value)\n (if (and (not (Array/isArray output)) (< (get output :low) 0))\n (progn\n (binary-unit output (bit-and value 65535))\n (binary-unit output (unsigned-bit-shift-right value 16))\n (put output :length (+ (get output :length) 4)))\n (let ((i 0))\n (while (< i 4)\n (binary-byte output (bit-and value 255))\n (setq value (unsigned-bit-shift-right value 8)) (setq i (1+ i)))))\n output)\n\n (defun binary-push (output &rest values)\n (let ((index 0))\n (while (< index (js-length values))\n (binary-byte output (js-nth index values)) (setq index (1+ index))))\n (get output :length))\n\n (defun binary-child (output)\n (binary-output (if (Array/isArray output) (js-object)\n (js-object :binaryEncoding \"u16le-chunks\"))))\n\n (defun binary-length (input)\n (if (Array/isArray input) (js-length input)\n (if (= (get input :encoding nil) \"u16le-chunks\") (get input :byteLength) (get input :length))))\n\n (defun binary-byte-at (input index)\n (if (Array/isArray input) (js-nth index input)\n (let* ((unit (js-call globalThis.Math :floor (/ index 2)))\n (chunk (js-call globalThis.Math :floor (/ unit 2048))) (offset (% unit 2048))\n (chunks (get input :chunks))\n (value (if (< chunk (js-length chunks))\n (string-code-unit-at (js-nth chunk chunks) offset)\n (if (< offset (js-length (get input :pending)))\n (js-nth offset (get input :pending)) (get input :low)))))\n (bit-and (if (= (% index 2) 0) value (unsigned-bit-shift-right value 8)) 255))))\n\n ;; Reopening a finished public envelope retains its immutable chunk strings.\n ;; Only the final partial block is unpacked, never the complete byte stream.\n (defun binary-resume (input)\n (if (/= (get input :encoding nil) \"u16le-chunks\") input\n (let* ((output (binary-output (js-object :binaryEncoding \"u16le-chunks\")))\n (length (get input :byteLength)) (chunks (js-call (get input :chunks) :slice))\n (tail (% length 4096)))\n (put output :length length) (put output :chunks chunks)\n (when (> tail 0)\n (let ((last (js-call chunks :pop)) (index 0) (count (js-call globalThis.Math :floor (/ tail 2))))\n (while (< index count)\n (js-call (get output :pending) :push (string-code-unit-at last index))\n (setq index (1+ index)))\n (when (= (% tail 2) 1) (put output :low (bit-and (string-code-unit-at last count) 255)))))\n output)))\n\n (defun binary-append (output input)\n (let ((i 0))\n (while (< i (binary-length input)) (binary-byte output (binary-byte-at input i)) (setq i (1+ i))))\n output)\n\n (defun binary-append-owned-even (output input length)\n (let ((units (js-call globalThis.Math :floor (/ length 2))))\n (when (> units 0)\n (let* ((chunks (get input :chunks)) (chunk-index 0) (position 0)\n (pending (get output :pending))\n (carry (if (> (js-length pending) 0)\n (Reflect/apply (get globalThis.String :fromCharCode) nil pending) \"\")))\n (put output :pending (js-array))\n (while (< position units)\n (let ((chunk (if (< chunk-index (js-length chunks)) (js-nth chunk-index chunks)\n (Reflect/apply (get globalThis.String :fromCharCode) nil (get input :pending)))))\n ;; A finished odd source may include one padded high byte in\n ;; its last unit. Never transfer that unit as a complete pair.\n (when (> (js-length chunk) (- units position))\n (setq chunk (js-call chunk :slice 0 (- units position))))\n (setq position (+ position (js-length chunk)))\n (setq chunk-index (1+ chunk-index))\n (if (and (= (js-length carry) 0) (= (js-length chunk) 2048))\n (js-call (get output :chunks) :push chunk)\n (progn\n ;; carry has <2048 units and chunk has <=2048: this\n ;; temporary has at most 4095, regardless of stream size.\n (setq carry (str carry chunk))\n (when (>= (js-length carry) 2048)\n (js-call (get output :chunks) :push (js-call carry :slice 0 2048))\n (setq carry (js-call carry :slice 2048)))))))\n ;; Only the final tail is unpacked into the normal pending batch.\n ;; Intermediate carries stay strings rather than numeric arrays.\n (let ((index 0))\n (while (< index (js-length carry))\n (js-call (get output :pending) :push (string-code-unit-at carry index))\n (setq index (1+ index))))\n (put output :length (+ (get output :length) (* units 2)))))\n (when (= (% length 2) 1) (binary-byte output (binary-byte-at input (1- length)))))\n output)\n\n ;; Internal transfer for the WASM emitter's freshly allocated packed body\n ;; writers only. Public append and finished envelopes remain repeatable and\n ;; non-consuming. No caller option can select this path for typed input.\n (defun binary-append-owned (output input)\n (when (Object/is output input) (backend-fail nil \"cannot consume a binary writer into itself\"))\n (if (or (Array/isArray output) (Array/isArray input)\n (= (get input :encoding nil) \"u16le-chunks\"))\n (binary-append output input)\n (progn\n (unless (and (not (nil? output)) (not (nil? input))\n (Array/isArray (get output :chunks nil)) (Array/isArray (get output :pending nil))\n (Array/isArray (get input :chunks nil)) (Array/isArray (get input :pending nil))\n (not (Object/hasOwn output \"encoding\")) (not (Object/hasOwn input \"encoding\")))\n (backend-fail nil \"owned binary append requires fresh packed writers\"))\n (let ((length (get input :length)) (index 0))\n (if (< (get output :low) 0) (binary-append-owned-even output input length)\n ;; An odd destination needs cross-unit byte pairing. Preserve the\n ;; original path, including the source's exact odd final byte.\n (while (< index length)\n (binary-byte output (binary-byte-at input index)) (setq index (1+ index)))))\n ;; Replace storage, rather than clearing shared arrays in place: a\n ;; previously finished snapshot may still own the old chunk list.\n ;; Preserve emitter debug/span/scratch properties on both writers.\n (put input :length 0) (put input :chunks (js-array))\n (put input :pending (js-array)) (put input :low -1)\n output)))\n\n (defun binary-slice (output start end)\n (if (Array/isArray output) (js-call output :slice start end)\n (let ((result (js-array)) (limit (binary-length output)))\n (when (> end limit) (setq end limit))\n (while (< start end)\n (js-call result :push (binary-byte-at output start))\n (setq start (1+ start))) result)))\n\n (defun binary-finish (output)\n (if (Array/isArray output) output\n (progn\n (when (>= (get output :low) 0)\n (binary-unit output (get output :low)) (put output :low -1))\n (binary-flush output)\n (js-object :encoding \"u16le-chunks\" :byteLength (get output :length) :chunks (get output :chunks)))))\n\n (export binary-output binary-byte binary-u32 binary-push binary-child binary-length binary-resume\n binary-append binary-append-owned binary-slice binary-finish))\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACE,QAAwB;AAKxB,uBAAgC;EAC9B;gCAAqB,2FAAY,OAAR;;UAAnB;MACJ,IAAI,qBAAM,cAAc,eAAc;QAAmB,OAAA;;QACvD,IAAI,CAAG,CAAK,eAAc,sBAAiB;UACvC,OAAA,EAAW,UAAQ,GAAE,UAAQ,IAAW,WAAS,IAAW,OAAK;;UACnE,OAAC,aAAa,MAAI;;;;;;AAE1B,sBAAqB;EACnB;gCAAe,CAAK,QAAO;;UAArB;MACJ,IAAM,kCAAG,EAAW,wBAAS;QAC3B,CAAS,CAAK,QAAO,WAAS,QAC5B,eAAC,kBAAc,CAAK,mBAAkB,iBAAe,MAAI;QAC3D,OAAA,EAAK,QAAO,aAAS;;;;;;;AAE3B,qBAAoB,QAAO;EACzB,CAAS,CAAK,QAAO,YAAU,QAAM;EACrC,IAAM,CAAG,EAAW,CAAK,QAAO,8BAAW;IAAM,OAAC,aAAa;;;;;AAEjE,qBAAoB,QAAO;EACzB,uBAAK,cAAc;IAAQ,CAAS,QAAO,QAAM,wBAAS,OAAM;;IAE5D,IAAI,kCAAG,CAAK,QAAO,QAAM;MAAG,EAAK,QAAO,SAAK,wBAAS,OAAM;;MAEvD,YAAY,QAAO,CAA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iCADf,EAAK,CAAM,2CAA/B,EAAK,CAAM;MAIrB,aAAa,MAAI;;IACpB;mCAAc,CAAK,OAAM;mCAAiB;;YAApC;YAA6B;QACjC,IAAI,kCAAG,CAAK,QAAO,QAAM;UAAI,yBAAyB,QAAO,OAAM;;UAGjE,OAAO,kCAAG,OAAM;YACb,YAAY,QAAQ,eAAe,OAAM;YAAQ,CAAM,CAAA,QAAM,CAAI;;;;;IAIxE,EAAK,OAAM,YAAQ;IAAG,EAAK,OAAM,YAAQ;IACzC,EAAK,OAAM,aAAS;IAAY,EAAK,OAAM,SAAK;IAChD,OAAA;;;AAEN,sBAAqB,QAAO,OAAM;EAChC,uBAAK,cAAc;IAAQ,OAAA,CAAS,QAAO,SAAO,OAAM;;IACtD;mCAAc;mCAAoB,cAAc;;YAA1C;YAAoB;QACxB,IAAM,kCAAG,KAAI;UAAO,CAAM,CAAA,MAAI;;QAC9B,OAAO,kCAAG,OAAM;UACd,CAAS,QAAO,QAAO,eAAe,QAAO;UAC7C,CAAM,CAAA,QAAM,CAAI;;QAAS,OAAA;;;;;AAEjC,uBAAsB;EACpB,uBAAK,cAAc;IAAQ,OAAA;;IAEvB,IAAM,mCAAI,CAAK,QAAO,QAAM;MACzB,YAAY,QAAO,CAAK,QAAO;MAAO,EAAK,QAAO,SAAK;;IACzD,aAAa;IACd,OAAA,EAAW,YAAU,gBAAe,cAAY,CAAK,QAAO,WAAS,UAAQ,CAAK,QAAO;;;AAE/F,QAAQ,eAAc,aAAY,YAAW,aAAY,cAAa,eAAc,eAClF,eAAc,qBAAoB,cAAa"}
|
|
1
|
+
{"version":3,"file":"backends/binary.mjs","sources":["bootstrap/backends/binary.eli"],"sourcesContent":["(module eliscript.backend.binary\n (import \"./numeric.mjs\" backend-fail)\n\n ;; Packed output owns bounded word batches and exact UTF16 strings. Each\n ;; code unit stores two little-endian bytes, including unpaired surrogates.\n ;; The ordinary byte-array API keeps its original representation.\n (defun binary-output (&optional options)\n (let ((configuration (or options (js-object))))\n (if (not (Object/hasOwn configuration \"binaryEncoding\")) (js-array)\n (if (= (get configuration :binaryEncoding) \"u16le-chunks\")\n (js-object :length 0 :chunks (js-array) :pending (js-array) :low -1)\n (backend-fail nil \"unsupported binary output encoding\")))))\n\n (defun binary-flush (output)\n (let ((pending (get output :pending)))\n (when (> (js-length pending) 0)\n (js-call (get output :chunks) :push\n (Reflect/apply (get globalThis.String :fromCharCode) nil pending))\n (put output :pending (js-array)))))\n\n (defun binary-unit (output value)\n (js-call (get output :pending) :push value)\n (when (= (js-length (get output :pending)) 2048) (binary-flush output)))\n\n (defun binary-byte (output value)\n (if (Array/isArray output) (js-call output :push (bit-and value 255))\n (progn\n (if (< (get output :low) 0) (put output :low (bit-and value 255))\n (progn\n (binary-unit output (+ (get output :low) (* (bit-and value 255) 256)))\n (put output :low -1)))\n (put output :length (1+ (get output :length)))))\n output)\n\n (defun binary-u32 (output value)\n (if (and (not (Array/isArray output)) (< (get output :low) 0))\n (progn\n (binary-unit output (bit-and value 65535))\n (binary-unit output (unsigned-bit-shift-right value 16))\n (put output :length (+ (get output :length) 4)))\n (let ((i 0))\n (while (< i 4)\n (binary-byte output (bit-and value 255))\n (setq value (unsigned-bit-shift-right value 8)) (setq i (1+ i)))))\n output)\n\n (defun binary-push (output &rest values)\n (let ((index 0))\n (while (< index (js-length values))\n (binary-byte output (js-nth index values)) (setq index (1+ index))))\n (get output :length))\n\n (defun binary-child (output)\n (binary-output (if (Array/isArray output) (js-object)\n (js-object :binaryEncoding \"u16le-chunks\"))))\n\n (defun binary-length (input)\n (if (Array/isArray input) (js-length input)\n (if (= (get input :encoding nil) \"u16le-chunks\") (get input :byteLength) (get input :length))))\n\n (defun binary-byte-at (input index)\n (if (Array/isArray input) (js-nth index input)\n (let* ((unit (js-call globalThis.Math :floor (/ index 2)))\n (chunk (js-call globalThis.Math :floor (/ unit 2048))) (offset (% unit 2048))\n (chunks (get input :chunks))\n (value (if (< chunk (js-length chunks))\n (string-code-unit-at (js-nth chunk chunks) offset)\n (if (< offset (js-length (get input :pending)))\n (js-nth offset (get input :pending)) (get input :low)))))\n (bit-and (if (= (% index 2) 0) value (unsigned-bit-shift-right value 8)) 255))))\n\n ;; Reopening a finished public envelope retains its immutable chunk strings.\n ;; Only the final partial block is unpacked, never the complete byte stream.\n (defun binary-resume (input)\n (if (/= (get input :encoding nil) \"u16le-chunks\") input\n (let* ((output (binary-output (js-object :binaryEncoding \"u16le-chunks\")))\n (length (get input :byteLength)) (chunks (js-call (get input :chunks) :slice))\n (tail (% length 4096)))\n (put output :length length) (put output :chunks chunks)\n (when (> tail 0)\n (let ((last (js-call chunks :pop)) (index 0) (count (js-call globalThis.Math :floor (/ tail 2))))\n (while (< index count)\n (js-call (get output :pending) :push (string-code-unit-at last index))\n (setq index (1+ index)))\n (when (= (% tail 2) 1) (put output :low (bit-and (string-code-unit-at last count) 255)))))\n output)))\n\n (defun binary-append (output input)\n (let ((i 0))\n (while (< i (binary-length input)) (binary-byte output (binary-byte-at input i)) (setq i (1+ i))))\n output)\n\n (defun binary-append-owned-even (output input length)\n (let ((units (js-call globalThis.Math :floor (/ length 2))))\n (when (> units 0)\n (let* ((chunks (get input :chunks)) (chunk-index 0) (position 0)\n (pending (get output :pending))\n (carry (if (> (js-length pending) 0)\n (Reflect/apply (get globalThis.String :fromCharCode) nil pending) \"\")))\n (put output :pending (js-array))\n (while (< position units)\n (let ((chunk (if (< chunk-index (js-length chunks)) (js-nth chunk-index chunks)\n (Reflect/apply (get globalThis.String :fromCharCode) nil (get input :pending)))))\n ;; A finished odd source may include one padded high byte in\n ;; its last unit. Never transfer that unit as a complete pair.\n (when (> (js-length chunk) (- units position))\n (setq chunk (js-call chunk :slice 0 (- units position))))\n (setq position (+ position (js-length chunk)))\n (setq chunk-index (1+ chunk-index))\n (if (and (= (js-length carry) 0) (= (js-length chunk) 2048))\n (js-call (get output :chunks) :push chunk)\n (progn\n ;; carry has <2048 units and chunk has <=2048: this\n ;; temporary has at most 4095, regardless of stream size.\n (setq carry (str carry chunk))\n (when (>= (js-length carry) 2048)\n (js-call (get output :chunks) :push (js-call carry :slice 0 2048))\n (setq carry (js-call carry :slice 2048)))))))\n ;; Only the final tail is unpacked into the normal pending batch.\n ;; Intermediate carries stay strings rather than numeric arrays.\n (let ((index 0))\n (while (< index (js-length carry))\n (js-call (get output :pending) :push (string-code-unit-at carry index))\n (setq index (1+ index))))\n (put output :length (+ (get output :length) (* units 2)))))\n (when (= (% length 2) 1) (binary-byte output (binary-byte-at input (1- length)))))\n output)\n\n ;; Internal transfer for the WASM emitter's freshly allocated packed body\n ;; writers only. Public append and finished envelopes remain repeatable and\n ;; non-consuming. No caller option can select this path for typed input.\n (defun binary-append-owned (output input)\n (when (Object/is output input) (backend-fail nil \"cannot consume a binary writer into itself\"))\n (if (or (Array/isArray output) (Array/isArray input)\n (= (get input :encoding nil) \"u16le-chunks\"))\n (binary-append output input)\n (progn\n (unless (and (not (nil? output)) (not (nil? input))\n (Array/isArray (get output :chunks nil)) (Array/isArray (get output :pending nil))\n (Array/isArray (get input :chunks nil)) (Array/isArray (get input :pending nil))\n (not (Object/hasOwn output \"encoding\")) (not (Object/hasOwn input \"encoding\")))\n (backend-fail nil \"owned binary append requires fresh packed writers\"))\n (let ((length (get input :length)) (index 0))\n (if (< (get output :low) 0) (binary-append-owned-even output input length)\n ;; An odd destination needs cross-unit byte pairing. Preserve the\n ;; original path, including the source's exact odd final byte.\n (while (< index length)\n (binary-byte output (binary-byte-at input index)) (setq index (1+ index)))))\n ;; Replace storage, rather than clearing shared arrays in place: a\n ;; previously finished snapshot may still own the old chunk list.\n ;; Preserve emitter debug/span/scratch properties on both writers.\n (put input :length 0) (put input :chunks (js-array))\n (put input :pending (js-array)) (put input :low -1)\n output)))\n\n (defun binary-slice (output start end)\n (if (Array/isArray output) (js-call output :slice start end)\n (let ((result (js-array)) (limit (binary-length output)))\n (when (> end limit) (setq end limit))\n (while (< start end)\n (js-call result :push (binary-byte-at output start))\n (setq start (1+ start))) result)))\n\n (defun binary-finish (output)\n (if (Array/isArray output) output\n (progn\n (when (>= (get output :low) 0)\n (binary-unit output (get output :low)) (put output :low -1))\n (binary-flush output)\n (js-object :encoding \"u16le-chunks\" :byteLength (get output :length) :chunks (get output :chunks)))))\n\n (export binary-output binary-byte binary-u32 binary-push binary-child binary-length binary-resume\n binary-append binary-append-owned binary-slice binary-finish))\n"],"names":[],"mappings":";;;;;;AACE,QAAwB;AAKxB,uBAAgC;EAC9B;gCAAqB,2FAAY,OAAR;;UAAnB;MACJ,IAAI,qBAAM,cAAc,eAAc;QAAmB,OAAA;;QACvD,IAAI,CAAG,CAAK,eAAc,sBAAiB;UACvC,OAAA,EAAW,UAAQ,GAAE,UAAQ,IAAW,WAAS,IAAW,OAAK;;UACnE,OAAC,aAAa,MAAI;;;;;;AAE1B,sBAAqB;EACnB;gCAAe,CAAK,QAAO;;UAArB;MACJ,IAAM,kCAAG,EAAW,wBAAS;QAC3B,CAAS,CAAK,QAAO,WAAS,QAC5B,eAAC,kBAAc,CAAK,mBAAkB,iBAAe,MAAI;QAC3D,OAAA,EAAK,QAAO,aAAS;;;;;;;AAE3B,qBAAoB,QAAO;EACzB,CAAS,CAAK,QAAO,YAAU,QAAM;EACrC,IAAM,CAAG,EAAW,CAAK,QAAO,8BAAW;IAAM,OAAC,aAAa;;;;;AAEjE,qBAAoB,QAAO;EACzB,uBAAK,cAAc;IAAQ,CAAS,QAAO,QAAM,wBAAS,OAAM;;IAE5D,IAAI,kCAAG,CAAK,QAAO,QAAM;MAAG,EAAK,QAAO,SAAK,wBAAS,OAAM;;MAEvD,YAAY,QAAO,CAAG,CAAK,QAAO,SAAM,wBAAG,wBAAS,OAAM,MAAK;MAChE,EAAK,QAAO,SAAK;;IACrB,EAAK,QAAO,YAAQ,CAAI,CAAK,QAAO;;EACxC,OAAA;;AAEF,oBAAmB,QAAO;EACxB,IAAI,CAAK,qBAAM,cAAc,aAAS,kCAAG,CAAK,QAAO,QAAM;IAEpD,YAAY,QAAO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AQ,CAAM,CAAA,QAAM,CAAI;;;;;IAIxE,EAAK,OAAM,YAAQ;IAAG,EAAK,OAAM,YAAQ;IACzC,EAAK,OAAM,aAAS;IAAY,EAAK,OAAM,SAAK;IAChD,OAAA;;;AAEN,sBAAqB,QAAO,OAAM;EAChC,uBAAK,cAAc;IAAQ,OAAA,CAAS,QAAO,SAAO,OAAM;;IACtD;mCAAc;mCAAoB,cAAc;;YAA1C;YAAoB;QACxB,IAAM,kCAAG,KAAI;UAAO,CAAM,CAAA,MAAI;;QAC9B,OAAO,kCAAG,OAAM;UACd,CAAS,QAAO,QAAO,eAAe,QAAO;UAC7C,CAAM,CAAA,QAAM,CAAI;;QAAS,OAAA;;;;;AAEjC,uBAAsB;EACpB,uBAAK,cAAc;IAAQ,OAAA;;IAEvB,IAAM,mCAAI,CAAK,QAAO,QAAM;MACzB,YAAY,QAAO,CAAK,QAAO;MAAO,EAAK,QAAO,SAAK;;IACzD,aAAa;IACd,OAAA,EAAW,YAAU,gBAAe,cAAY,CAAK,QAAO,WAAS,UAAQ,CAAK,QAAO;;;AAE/F,QAAQ,eAAc,aAAY,YAAW,aAAY,cAAa,eAAc,eAClF,eAAc,qBAAoB,cAAa"}
|
|
@@ -1,96 +1,7 @@
|
|
|
1
1
|
// Generated by Eliscript. Do not edit.
|
|
2
2
|
import "eliscript/runtime/unicode-case.mjs";
|
|
3
|
+
import { __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";
|
|
3
4
|
const __eliscript_truthy = (value) => value !== false && value != null;
|
|
4
|
-
const __eliscript_number_intrinsic = globalThis.Number;
|
|
5
|
-
const __eliscript_bigint_intrinsic = globalThis.BigInt;
|
|
6
|
-
const __eliscript_numeric_apply = globalThis.Reflect.apply;
|
|
7
|
-
const __eliscript_numeric_symbol = globalThis.Symbol.toPrimitive;
|
|
8
|
-
const __eliscript_numeric_error = globalThis.TypeError;
|
|
9
|
-
const __eliscript_numeric_trim = globalThis.String.prototype.trim;
|
|
10
|
-
const __eliscript_numeric_slice = globalThis.String.prototype.slice;
|
|
11
|
-
const __eliscript_numeric_exec = globalThis.RegExp.prototype.exec;
|
|
12
|
-
const __eliscript_numeric_radix = /^(?:0[xX][0-9a-fA-F]+|0[oO][0-7]+|0[bB][01]+)$/;
|
|
13
|
-
const __eliscript_numeric_object = (value) => value !== null && (typeof value === "object" || typeof value === "function" || (typeof value === "undefined" && value !== void 0));
|
|
14
|
-
const __eliscript_numeric_primitive = (value) => {
|
|
15
|
-
if (!__eliscript_numeric_object(value)) return value;
|
|
16
|
-
const exotic = value[__eliscript_numeric_symbol];
|
|
17
|
-
if (exotic !== void 0 && exotic !== null) {
|
|
18
|
-
const result = __eliscript_numeric_apply(exotic, value, ["number"]);
|
|
19
|
-
if (!__eliscript_numeric_object(result)) return result;
|
|
20
|
-
throw new __eliscript_numeric_error("Cannot convert object to primitive value");
|
|
21
|
-
}
|
|
22
|
-
for (let index = 0; index < 2; index++) {
|
|
23
|
-
const method = value[index === 0 ? "valueOf" : "toString"];
|
|
24
|
-
if (typeof method === "function" || (typeof method === "undefined" && method !== void 0)) {
|
|
25
|
-
const result = __eliscript_numeric_apply(method, value, []);
|
|
26
|
-
if (!__eliscript_numeric_object(result)) return result;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
throw new __eliscript_numeric_error("Cannot convert object to primitive value");
|
|
30
|
-
};
|
|
31
|
-
const __eliscript_to_number = (value) => {
|
|
32
|
-
const primitive = __eliscript_numeric_primitive(value);
|
|
33
|
-
if (typeof primitive === "string") {
|
|
34
|
-
const text = __eliscript_numeric_apply(__eliscript_numeric_trim, primitive, []);
|
|
35
|
-
if (__eliscript_numeric_apply(__eliscript_numeric_exec, __eliscript_numeric_radix, [text]) !== null) {
|
|
36
|
-
let first = 2;
|
|
37
|
-
while (first < text.length && text[first] === "0") first++;
|
|
38
|
-
if (first === text.length) return 0;
|
|
39
|
-
const prefix = text[1];
|
|
40
|
-
const limit = prefix === "x" || prefix === "X" ? 256 : prefix === "b" || prefix === "B" ? 1024 : 342;
|
|
41
|
-
if (text.length - first > limit) return 1 / 0;
|
|
42
|
-
const token = __eliscript_numeric_apply(__eliscript_numeric_slice, text, [0, 2]) + __eliscript_numeric_apply(__eliscript_numeric_slice, text, [first]);
|
|
43
|
-
return __eliscript_number_intrinsic(__eliscript_bigint_intrinsic(token));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return __eliscript_number_intrinsic(primitive);
|
|
47
|
-
};
|
|
48
|
-
const __eliscript_numeric = (value) => {
|
|
49
|
-
if (typeof value === "number" || typeof value === "bigint") return value;
|
|
50
|
-
const primitive = __eliscript_numeric_primitive(value);
|
|
51
|
-
if (typeof primitive === "number" || typeof primitive === "bigint") return primitive;
|
|
52
|
-
return typeof primitive === "string" ? __eliscript_to_number(primitive) : +primitive;
|
|
53
|
-
};
|
|
54
|
-
const __eliscript_implicit_number = (value) => {
|
|
55
|
-
if (typeof value === "number") return value;
|
|
56
|
-
const primitive = __eliscript_numeric_primitive(value);
|
|
57
|
-
if (typeof primitive === "bigint") throw new __eliscript_numeric_error("Cannot convert a BigInt value to a number");
|
|
58
|
-
return typeof primitive === "string" ? __eliscript_to_number(primitive) : +primitive;
|
|
59
|
-
};
|
|
60
|
-
const __eliscript_numeric_decrement = (value) => __eliscript_implicit_number(value) - 1;
|
|
61
|
-
const __eliscript_numeric_sub = (a, b) => { if (typeof a === "number" && typeof b === "number") return a - b; return __eliscript_numeric(a) - __eliscript_numeric(b); };
|
|
62
|
-
const __eliscript_numeric_mul = (a, b) => { if (typeof a === "number" && typeof b === "number") return a * b; return __eliscript_numeric(a) * __eliscript_numeric(b); };
|
|
63
|
-
const __eliscript_numeric_div = (a, b) => { if (typeof a === "number" && typeof b === "number") return a / b; return __eliscript_numeric(a) / __eliscript_numeric(b); };
|
|
64
|
-
const __eliscript_numeric_rem = (a, b) => { if (typeof a === "number" && typeof b === "number") return a % b; return __eliscript_numeric(a) % __eliscript_numeric(b); };
|
|
65
|
-
const __eliscript_numeric_and = (a, b) => { if (typeof a === "number" && typeof b === "number") return a & b; return __eliscript_numeric(a) & __eliscript_numeric(b); };
|
|
66
|
-
const __eliscript_numeric_or = (a, b) => { if (typeof a === "number" && typeof b === "number") return a | b; return __eliscript_numeric(a) | __eliscript_numeric(b); };
|
|
67
|
-
const __eliscript_numeric_xor = (a, b) => { if (typeof a === "number" && typeof b === "number") return a ^ b; return __eliscript_numeric(a) ^ __eliscript_numeric(b); };
|
|
68
|
-
const __eliscript_numeric_shl = (a, b) => { if (typeof a === "number" && typeof b === "number") return a << b; return __eliscript_numeric(a) << __eliscript_numeric(b); };
|
|
69
|
-
const __eliscript_numeric_shr = (a, b) => { if (typeof a === "number" && typeof b === "number") return a >> b; return __eliscript_numeric(a) >> __eliscript_numeric(b); };
|
|
70
|
-
const __eliscript_numeric_ushr = (a, b) => { if (typeof a === "number" && typeof b === "number") return a >>> b; return __eliscript_numeric(a) >>> __eliscript_numeric(b); };
|
|
71
|
-
const __eliscript_numeric_neg = (a) => typeof a === "number" ? -a : -__eliscript_numeric(a);
|
|
72
|
-
const __eliscript_numeric_int32 = (a) => typeof a === "number" ? a | 0 : __eliscript_numeric(a) | 0;
|
|
73
|
-
const __eliscript_numeric_uint32 = (a) => typeof a === "number" ? a >>> 0 : __eliscript_numeric(a) >>> 0;
|
|
74
|
-
const __eliscript_numeric_not = (a) => typeof a === "number" ? ~a : ~__eliscript_numeric(a);
|
|
75
|
-
const __eliscript_numeric_relation = (operator, left, right) => {
|
|
76
|
-
if (typeof left === "number" && typeof right === "number") {
|
|
77
|
-
if (operator === "<") return left < right;
|
|
78
|
-
if (operator === "<=") return left <= right;
|
|
79
|
-
if (operator === ">") return left > right;
|
|
80
|
-
return left >= right;
|
|
81
|
-
}
|
|
82
|
-
let a = __eliscript_numeric_primitive(left);
|
|
83
|
-
let b = __eliscript_numeric_primitive(right);
|
|
84
|
-
const x = typeof a, y = typeof b;
|
|
85
|
-
if (!((x === "string" && y === "string") || (x === "bigint" && y === "string") || (x === "string" && y === "bigint"))) {
|
|
86
|
-
a = __eliscript_numeric(a);
|
|
87
|
-
b = __eliscript_numeric(b);
|
|
88
|
-
}
|
|
89
|
-
if (operator === "<") return a < b;
|
|
90
|
-
if (operator === "<=") return a <= b;
|
|
91
|
-
if (operator === ">") return a > b;
|
|
92
|
-
return a >= b;
|
|
93
|
-
};
|
|
94
5
|
|
|
95
6
|
import {backend_fail} from "./numeric.mjs";
|
|
96
7
|
function host_capability_definition(name, node) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backends/capabilities.mjs","sources":["bootstrap/backends/capabilities.eli"],"sourcesContent":["(module eliscript.backend.capabilities\n (import \"./numeric.mjs\" backend-fail)\n\n ;; A capability is declared only when a typed operation actually needs it.\n ;; Scalar and pure managed programs keep the original import-free ABI.\n (defun host-capability-definition (name node)\n (cond\n ((or (= name \"console-log\") (= name \"console-log-capture\") (= name \"source-operation\"))\n (js-object :name name :module \"eliscript.host\" :arity 2 :abi \"managed-host-call-v1\"))\n (t (backend-fail node (str \"unknown host capability: \" name)))))\n\n (defun collect-host-capabilities (node names &optional completed)\n (unless (and completed (js-call completed :has node))\n (when (= (get node :kind) \"host-call\")\n (let ((name (get node :value)) (children (get node :children)))\n (host-capability-definition name node)\n (unless (and (= (get node :type) \"u32\") (Array/isArray children) (= (js-length children) 2))\n (backend-fail node \"host calls require exactly heap and argument-list word operands\"))\n (let ((index 0))\n (while (< index 2)\n (unless (or (= (get (js-nth index children) :type) \"u32\")\n (= (get (js-nth index children) :type) \"i32\"))\n (backend-fail node \"host call operands must be memory32 words\"))\n (setq index (1+ index))))\n (unless (js-call names :includes name) (js-call names :push name))))\n (let ((children (get node :children)) (index 0))\n (unless (Array/isArray children) (backend-fail node \"typed capability scan requires a children array\"))\n (while (< index (js-length children))\n (collect-host-capabilities (js-nth index children) names completed)\n (setq index (1+ index))))\n ;; Only the source-lowering handoff supplies a memo. A completed subtree\n ;; has already declared its capabilities in their first DFS order.\n (when completed (js-call completed :set node t))))\n\n (defun prepare-host-capabilities-core (program fresh)\n (let ((names (js-array)) (functions (get program :functions)) (index 0) (result (js-array)))\n (unless (Array/isArray functions) (backend-fail program \"typed capability scan requires declared functions\"))\n (while (< index (js-length functions))\n (collect-host-capabilities (get (js-nth index functions) :body) names\n (when fresh (new globalThis.WeakMap)))\n (setq index (1+ index)))\n (when (and (> (js-length names) 0) (/= (get program :abi) \"memory-u32\"))\n (backend-fail program \"host capabilities require memory-u32 input\"))\n (setq index 0)\n (while (< index (js-length names))\n (js-call result :push (host-capability-definition (js-nth index names) program))\n (setq index (1+ index)))\n (let ((declared (get program :hostCapabilities nil)))\n (unless (nil? declared)\n (unless (and (Array/isArray declared) (= (js-length declared) (js-length result)))\n (backend-fail program \"host capability declarations differ from actual typed calls\"))\n (setq index 0)\n (while (< index (js-length result))\n (let ((expected (js-nth index result)) (actual (js-nth index declared)))\n (unless (and (= (get actual :name) (get expected :name))\n (= (get actual :module) (get expected :module))\n (= (get actual :arity) 2) (= (get actual :abi) \"managed-host-call-v1\"))\n (backend-fail program \"invalid host capability declaration\")))\n (setq index (1+ index)))))\n result))\n\n (defun prepare-host-capabilities (program)\n (prepare-host-capabilities-core program nil))\n (defun prepare-fresh-host-capabilities (program)\n (prepare-host-capabilities-core program t))\n\n (defun host-capability-index (capabilities node)\n (let ((index 0) (name (get node :value)))\n (while (and (< index (js-length capabilities)) (/= name (get (js-nth index capabilities) :name)))\n (setq index (1+ index)))\n (when (= index (js-length capabilities)) (backend-fail node \"host capability was not declared\"))\n index))\n\n (export prepare-host-capabilities host-capability-index prepare-fresh-host-capabilities))\n"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"backends/capabilities.mjs","sources":["bootstrap/backends/capabilities.eli"],"sourcesContent":["(module eliscript.backend.capabilities\n (import \"./numeric.mjs\" backend-fail)\n\n ;; A capability is declared only when a typed operation actually needs it.\n ;; Scalar and pure managed programs keep the original import-free ABI.\n (defun host-capability-definition (name node)\n (cond\n ((or (= name \"console-log\") (= name \"console-log-capture\") (= name \"source-operation\"))\n (js-object :name name :module \"eliscript.host\" :arity 2 :abi \"managed-host-call-v1\"))\n (t (backend-fail node (str \"unknown host capability: \" name)))))\n\n (defun collect-host-capabilities (node names &optional completed)\n (unless (and completed (js-call completed :has node))\n (when (= (get node :kind) \"host-call\")\n (let ((name (get node :value)) (children (get node :children)))\n (host-capability-definition name node)\n (unless (and (= (get node :type) \"u32\") (Array/isArray children) (= (js-length children) 2))\n (backend-fail node \"host calls require exactly heap and argument-list word operands\"))\n (let ((index 0))\n (while (< index 2)\n (unless (or (= (get (js-nth index children) :type) \"u32\")\n (= (get (js-nth index children) :type) \"i32\"))\n (backend-fail node \"host call operands must be memory32 words\"))\n (setq index (1+ index))))\n (unless (js-call names :includes name) (js-call names :push name))))\n (let ((children (get node :children)) (index 0))\n (unless (Array/isArray children) (backend-fail node \"typed capability scan requires a children array\"))\n (while (< index (js-length children))\n (collect-host-capabilities (js-nth index children) names completed)\n (setq index (1+ index))))\n ;; Only the source-lowering handoff supplies a memo. A completed subtree\n ;; has already declared its capabilities in their first DFS order.\n (when completed (js-call completed :set node t))))\n\n (defun prepare-host-capabilities-core (program fresh)\n (let ((names (js-array)) (functions (get program :functions)) (index 0) (result (js-array)))\n (unless (Array/isArray functions) (backend-fail program \"typed capability scan requires declared functions\"))\n (while (< index (js-length functions))\n (collect-host-capabilities (get (js-nth index functions) :body) names\n (when fresh (new globalThis.WeakMap)))\n (setq index (1+ index)))\n (when (and (> (js-length names) 0) (/= (get program :abi) \"memory-u32\"))\n (backend-fail program \"host capabilities require memory-u32 input\"))\n (setq index 0)\n (while (< index (js-length names))\n (js-call result :push (host-capability-definition (js-nth index names) program))\n (setq index (1+ index)))\n (let ((declared (get program :hostCapabilities nil)))\n (unless (nil? declared)\n (unless (and (Array/isArray declared) (= (js-length declared) (js-length result)))\n (backend-fail program \"host capability declarations differ from actual typed calls\"))\n (setq index 0)\n (while (< index (js-length result))\n (let ((expected (js-nth index result)) (actual (js-nth index declared)))\n (unless (and (= (get actual :name) (get expected :name))\n (= (get actual :module) (get expected :module))\n (= (get actual :arity) 2) (= (get actual :abi) \"managed-host-call-v1\"))\n (backend-fail program \"invalid host capability declaration\")))\n (setq index (1+ index)))))\n result))\n\n (defun prepare-host-capabilities (program)\n (prepare-host-capabilities-core program nil))\n (defun prepare-fresh-host-capabilities (program)\n (prepare-host-capabilities-core program t))\n\n (defun host-capability-index (capabilities node)\n (let ((index 0) (name (get node :value)))\n (while (and (< index (js-length capabilities)) (/= name (get (js-nth index capabilities) :name)))\n (setq index (1+ index)))\n (when (= index (js-length capabilities)) (backend-fail node \"host capability was not declared\"))\n index))\n\n (export prepare-host-capabilities host-capability-index prepare-fresh-host-capabilities))\n"],"names":[],"mappings":";;;;;AACE,QAAwB;AAIxB,oCAAmC,MAAK;EAEpC,IAAC,CAAI,CAAG,SAAK,kBAAe,CAAG,SAAK,0BAAuB,CAAG,SAAK;IAClE,OAAA,EAAW,QAAM,MAAK,UAAQ,kBAAiB,SAAO,GAAE,OAAK;;IAC3D,OAAC,aAAa,MAAK,QAAK,sCAA4B;;;AAE3D,mCAAkC,MAAK,OAAgB;EACrD,yBAAQ,qEAAe,CAAS,WAAU,OAAK,8BAAlC;IACb,IAAM,CAAG,CAAK,MAAK,YAAO;MACxB;oCAAY,CAAK,MAAK;oCAAmB,CAAK,MAAK;;cAA7C;cAAyB;UAC5B,2BAA2B,MAAK;UACjC,yBAAQ,0IAAyD,CAAG,EAAW,4BAAU,2BAAhD,cAAc,mCAA1C,CAAG,CAAK,MAAK,YAAO;YAC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,kCAAG,OAAM,EAAW;cACzB;6CAAgB,IAAc,eAAN;6CAAuB,IAAc,iBAAN;;sBAAjD;sBAAiC;kBACrC,MAAQ,CAAK,CAAG,CAAK,QAAO,YAAO,CAAK,UAAS,YACpC,CAAG,CAAK,QAAO,cAAS,CAAK,UAAS,cACtC,CAAG,CAAK,QAAO,aAAQ,MAAG,CAAG,CAAK,QAAO,WAAM;oBACzD,aAAa,SAAQ;;;;cAC1B,CAAM,CAAA,QAAM,CAAI;;;;;MACtB,OAAA;;;;AAEJ,mCAAkC;EAChC,OAAC,+BAA+B,SAAQ;;AAC1C,yCAAwC;EACtC,OAAC,+BAA+B,SAAQ;;AAE1C,+BAA8B,cAAa;EACzC;iCAAa;iCAAS,CAAK,MAAK;;UAA1B;UAAU;MACd,OAAO,CAAK,kCAAG,OAAM,EAAW,gCAAe,kGAAI,MAAK,CAAK,IAAc,qBAAN,kBAAoB;QACvF,CAAM,CAAA,QAAM,CAAI;;MAClB,IAAM,CAAG,UAAM,EAAW;QAAgB,aAAa,MAAK;;MAC5D,OAAA;;;;AAEJ,QAAQ,2BAA0B,uBAAsB"}
|
package/dist/backends/elf.mjs
CHANGED
|
@@ -1,97 +1,8 @@
|
|
|
1
1
|
// Generated by Eliscript. Do not edit.
|
|
2
2
|
import "eliscript/runtime/unicode-case.mjs";
|
|
3
3
|
import "eliscript/runtime/math.mjs";
|
|
4
|
+
import { __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";
|
|
4
5
|
const __eliscript_truthy = (value) => value !== false && value != null;
|
|
5
|
-
const __eliscript_number_intrinsic = globalThis.Number;
|
|
6
|
-
const __eliscript_bigint_intrinsic = globalThis.BigInt;
|
|
7
|
-
const __eliscript_numeric_apply = globalThis.Reflect.apply;
|
|
8
|
-
const __eliscript_numeric_symbol = globalThis.Symbol.toPrimitive;
|
|
9
|
-
const __eliscript_numeric_error = globalThis.TypeError;
|
|
10
|
-
const __eliscript_numeric_trim = globalThis.String.prototype.trim;
|
|
11
|
-
const __eliscript_numeric_slice = globalThis.String.prototype.slice;
|
|
12
|
-
const __eliscript_numeric_exec = globalThis.RegExp.prototype.exec;
|
|
13
|
-
const __eliscript_numeric_radix = /^(?:0[xX][0-9a-fA-F]+|0[oO][0-7]+|0[bB][01]+)$/;
|
|
14
|
-
const __eliscript_numeric_object = (value) => value !== null && (typeof value === "object" || typeof value === "function" || (typeof value === "undefined" && value !== void 0));
|
|
15
|
-
const __eliscript_numeric_primitive = (value) => {
|
|
16
|
-
if (!__eliscript_numeric_object(value)) return value;
|
|
17
|
-
const exotic = value[__eliscript_numeric_symbol];
|
|
18
|
-
if (exotic !== void 0 && exotic !== null) {
|
|
19
|
-
const result = __eliscript_numeric_apply(exotic, value, ["number"]);
|
|
20
|
-
if (!__eliscript_numeric_object(result)) return result;
|
|
21
|
-
throw new __eliscript_numeric_error("Cannot convert object to primitive value");
|
|
22
|
-
}
|
|
23
|
-
for (let index = 0; index < 2; index++) {
|
|
24
|
-
const method = value[index === 0 ? "valueOf" : "toString"];
|
|
25
|
-
if (typeof method === "function" || (typeof method === "undefined" && method !== void 0)) {
|
|
26
|
-
const result = __eliscript_numeric_apply(method, value, []);
|
|
27
|
-
if (!__eliscript_numeric_object(result)) return result;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
throw new __eliscript_numeric_error("Cannot convert object to primitive value");
|
|
31
|
-
};
|
|
32
|
-
const __eliscript_to_number = (value) => {
|
|
33
|
-
const primitive = __eliscript_numeric_primitive(value);
|
|
34
|
-
if (typeof primitive === "string") {
|
|
35
|
-
const text = __eliscript_numeric_apply(__eliscript_numeric_trim, primitive, []);
|
|
36
|
-
if (__eliscript_numeric_apply(__eliscript_numeric_exec, __eliscript_numeric_radix, [text]) !== null) {
|
|
37
|
-
let first = 2;
|
|
38
|
-
while (first < text.length && text[first] === "0") first++;
|
|
39
|
-
if (first === text.length) return 0;
|
|
40
|
-
const prefix = text[1];
|
|
41
|
-
const limit = prefix === "x" || prefix === "X" ? 256 : prefix === "b" || prefix === "B" ? 1024 : 342;
|
|
42
|
-
if (text.length - first > limit) return 1 / 0;
|
|
43
|
-
const token = __eliscript_numeric_apply(__eliscript_numeric_slice, text, [0, 2]) + __eliscript_numeric_apply(__eliscript_numeric_slice, text, [first]);
|
|
44
|
-
return __eliscript_number_intrinsic(__eliscript_bigint_intrinsic(token));
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return __eliscript_number_intrinsic(primitive);
|
|
48
|
-
};
|
|
49
|
-
const __eliscript_numeric = (value) => {
|
|
50
|
-
if (typeof value === "number" || typeof value === "bigint") return value;
|
|
51
|
-
const primitive = __eliscript_numeric_primitive(value);
|
|
52
|
-
if (typeof primitive === "number" || typeof primitive === "bigint") return primitive;
|
|
53
|
-
return typeof primitive === "string" ? __eliscript_to_number(primitive) : +primitive;
|
|
54
|
-
};
|
|
55
|
-
const __eliscript_implicit_number = (value) => {
|
|
56
|
-
if (typeof value === "number") return value;
|
|
57
|
-
const primitive = __eliscript_numeric_primitive(value);
|
|
58
|
-
if (typeof primitive === "bigint") throw new __eliscript_numeric_error("Cannot convert a BigInt value to a number");
|
|
59
|
-
return typeof primitive === "string" ? __eliscript_to_number(primitive) : +primitive;
|
|
60
|
-
};
|
|
61
|
-
const __eliscript_numeric_decrement = (value) => __eliscript_implicit_number(value) - 1;
|
|
62
|
-
const __eliscript_numeric_sub = (a, b) => { if (typeof a === "number" && typeof b === "number") return a - b; return __eliscript_numeric(a) - __eliscript_numeric(b); };
|
|
63
|
-
const __eliscript_numeric_mul = (a, b) => { if (typeof a === "number" && typeof b === "number") return a * b; return __eliscript_numeric(a) * __eliscript_numeric(b); };
|
|
64
|
-
const __eliscript_numeric_div = (a, b) => { if (typeof a === "number" && typeof b === "number") return a / b; return __eliscript_numeric(a) / __eliscript_numeric(b); };
|
|
65
|
-
const __eliscript_numeric_rem = (a, b) => { if (typeof a === "number" && typeof b === "number") return a % b; return __eliscript_numeric(a) % __eliscript_numeric(b); };
|
|
66
|
-
const __eliscript_numeric_and = (a, b) => { if (typeof a === "number" && typeof b === "number") return a & b; return __eliscript_numeric(a) & __eliscript_numeric(b); };
|
|
67
|
-
const __eliscript_numeric_or = (a, b) => { if (typeof a === "number" && typeof b === "number") return a | b; return __eliscript_numeric(a) | __eliscript_numeric(b); };
|
|
68
|
-
const __eliscript_numeric_xor = (a, b) => { if (typeof a === "number" && typeof b === "number") return a ^ b; return __eliscript_numeric(a) ^ __eliscript_numeric(b); };
|
|
69
|
-
const __eliscript_numeric_shl = (a, b) => { if (typeof a === "number" && typeof b === "number") return a << b; return __eliscript_numeric(a) << __eliscript_numeric(b); };
|
|
70
|
-
const __eliscript_numeric_shr = (a, b) => { if (typeof a === "number" && typeof b === "number") return a >> b; return __eliscript_numeric(a) >> __eliscript_numeric(b); };
|
|
71
|
-
const __eliscript_numeric_ushr = (a, b) => { if (typeof a === "number" && typeof b === "number") return a >>> b; return __eliscript_numeric(a) >>> __eliscript_numeric(b); };
|
|
72
|
-
const __eliscript_numeric_neg = (a) => typeof a === "number" ? -a : -__eliscript_numeric(a);
|
|
73
|
-
const __eliscript_numeric_int32 = (a) => typeof a === "number" ? a | 0 : __eliscript_numeric(a) | 0;
|
|
74
|
-
const __eliscript_numeric_uint32 = (a) => typeof a === "number" ? a >>> 0 : __eliscript_numeric(a) >>> 0;
|
|
75
|
-
const __eliscript_numeric_not = (a) => typeof a === "number" ? ~a : ~__eliscript_numeric(a);
|
|
76
|
-
const __eliscript_numeric_relation = (operator, left, right) => {
|
|
77
|
-
if (typeof left === "number" && typeof right === "number") {
|
|
78
|
-
if (operator === "<") return left < right;
|
|
79
|
-
if (operator === "<=") return left <= right;
|
|
80
|
-
if (operator === ">") return left > right;
|
|
81
|
-
return left >= right;
|
|
82
|
-
}
|
|
83
|
-
let a = __eliscript_numeric_primitive(left);
|
|
84
|
-
let b = __eliscript_numeric_primitive(right);
|
|
85
|
-
const x = typeof a, y = typeof b;
|
|
86
|
-
if (!((x === "string" && y === "string") || (x === "bigint" && y === "string") || (x === "string" && y === "bigint"))) {
|
|
87
|
-
a = __eliscript_numeric(a);
|
|
88
|
-
b = __eliscript_numeric(b);
|
|
89
|
-
}
|
|
90
|
-
if (operator === "<") return a < b;
|
|
91
|
-
if (operator === "<=") return a <= b;
|
|
92
|
-
if (operator === ">") return a > b;
|
|
93
|
-
return a >= b;
|
|
94
|
-
};
|
|
95
6
|
|
|
96
7
|
import {backend_fail} from "./numeric.mjs";
|
|
97
8
|
import {binary_output, binary_byte, binary_u32, binary_append, binary_finish} from "./binary.mjs";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"backends/elf.mjs","sources":["bootstrap/backends/elf.eli"],"sourcesContent":["(module eliscript.backend.elf\n (import \"./numeric.mjs\" backend-fail)\n (import \"./binary.mjs\" binary-output binary-byte binary-u32 binary-append binary-finish)\n\n (defun align (value boundary)\n (* (js-call globalThis.Math :ceil (/ value boundary)) boundary))\n\n (defun byte (output value) (binary-byte output value))\n (defun half (output value)\n (byte output value) (byte output (unsigned-bit-shift-right value 8)))\n (defun word (output value)\n (binary-u32 output value))\n (defun quad (output value)\n (unless (and (Number/isSafeInteger value) (>= value 0))\n (backend-fail nil \"ELF address exceeds the exact integer range\"))\n (word output (uint32 value)) (word output (uint32 (/ value 4294967296))))\n (defun pad (output count)\n (while (< (js-length output) count) (byte output 0)))\n (defun append (output input)\n (binary-append output input))\n\n (defun string-entry (output value)\n (let ((start (js-length output)) (i 0))\n (while (< i (js-length value))\n (let ((code (string-code-unit-at value i)))\n (when (= code 0) (backend-fail nil \"ELF symbol contains NUL\"))\n (when (and (>= code 55296) (<= code 56319))\n (let ((next (if (< (1+ i) (js-length value)) (string-code-unit-at value (1+ i)) 0)))\n (unless (and (>= next 56320) (<= next 57343))\n (backend-fail nil \"ELF symbol contains an unpaired surrogate\"))\n (setq code (+ 65536 (* (- code 55296) 1024) (- next 56320)))\n (setq i (1+ i))))\n (when (and (>= code 56320) (<= code 57343))\n (backend-fail nil \"ELF symbol contains an unpaired surrogate\"))\n (cond\n ((< code 128) (byte output code))\n ((< code 2048)\n (byte output (bit-or 192 (unsigned-bit-shift-right code 6)))\n (byte output (bit-or 128 (bit-and code 63))))\n ((< code 65536)\n (byte output (bit-or 224 (unsigned-bit-shift-right code 12)))\n (byte output (bit-or 128 (bit-and (unsigned-bit-shift-right code 6) 63)))\n (byte output (bit-or 128 (bit-and code 63))))\n (t\n (byte output (bit-or 240 (unsigned-bit-shift-right code 18)))\n (byte output (bit-or 128 (bit-and (unsigned-bit-shift-right code 12) 63)))\n (byte output (bit-or 128 (bit-and (unsigned-bit-shift-right code 6) 63)))\n (byte output (bit-or 128 (bit-and code 63))))))\n (setq i (1+ i)))\n (byte output 0) start))\n\n (defun section (name type flags alignment entry-size link info data)\n (js-object :name name :type type :flags flags :align alignment\n :entrySize entry-size :link link :info info :data data :address 0 :offset 0))\n\n (defun symbols (program code public-only text-address)\n (let* ((functions (get program :functions)) (offsets (get code :offsets))\n (exports (get program :exports)) (strings (js-array 0))\n (output (js-array)) (indices (js-array)) (names (js-array)) (i 0) (local-count 1))\n (pad output 24)\n ;; ELF requires every local symbol to precede the first non-local symbol.\n (unless public-only\n (while (< i (js-length functions))\n (unless (js-call exports :includes (get (js-nth i functions) :name))\n (js-call indices :push i) (setq local-count (1+ local-count)))\n (setq i (1+ i))))\n (setq i 0)\n (while (< i (js-length functions))\n (when (js-call exports :includes (get (js-nth i functions) :name)) (js-call indices :push i))\n (setq i (1+ i)))\n (setq i 0)\n (while (< i (js-length indices))\n (let* ((index (js-nth i indices)) (function (js-nth index functions))\n (name (get function :name)) (start (js-nth index offsets))\n (end (if (< (1+ index) (js-length offsets)) (js-nth (1+ index) offsets)\n (* (js-length (get code :words)) 4)))\n (name-offset (string-entry strings name)))\n (js-call names :push name-offset)\n (word output name-offset)\n (byte output (if (js-call exports :includes name) 18 2))\n (byte output 0) (half output 1)\n (quad output (+ text-address start)) (quad output (- end start)))\n (setq i (1+ i)))\n (js-object :bytes output :strings strings :names names :localCount local-count)))\n\n (defun sysv-hash (strings start)\n (let ((hash 0) (i start) (value (js-nth start strings)))\n (while (/= value 0)\n (setq hash (uint32 (+ (* hash 16) value)))\n (let ((high (bit-and hash 4026531840)))\n (when (/= high 0) (setq hash (bit-xor hash (unsigned-bit-shift-right high 24))))\n (setq hash (uint32 (bit-and hash (bit-not high)))))\n (setq i (1+ i)) (setq value (js-nth i strings)))\n hash))\n\n (defun hash-table (symbols)\n (let* ((names (get symbols :names)) (strings (get symbols :strings))\n (count (1+ (js-length names))) (buckets (js-array)) (chains (js-array))\n (bucket-count (if (> count 1) count 1)) (output (js-array)) (i 0))\n (while (< i bucket-count) (js-call buckets :push 0) (setq i (1+ i)))\n (setq i 0)\n (while (< i count) (js-call chains :push 0) (setq i (1+ i)))\n (setq i 1)\n (while (< i count)\n (let* ((hash (sysv-hash strings (js-nth (1- i) names)))\n (bucket (% hash bucket-count)) (previous (js-nth bucket buckets)))\n (js-call chains :splice i 1 previous) (js-call buckets :splice bucket 1 i))\n (setq i (1+ i)))\n (word output bucket-count) (word output count)\n (setq i 0)\n (while (< i bucket-count) (word output (js-nth i buckets)) (setq i (1+ i)))\n (setq i 0)\n (while (< i count) (word output (js-nth i chains)) (setq i (1+ i)))\n output))\n\n (defun header (output kind program-offset section-offset program-count section-count names-index)\n (append output (js-array 127 69 76 70 2 1 1 0 0 0 0 0 0 0 0 0))\n (half output kind) (half output 183) (word output 1)\n (quad output 0) (quad output program-offset) (quad output section-offset)\n (word output 0) (half output 64) (half output (if (> program-count 0) 56 0))\n (half output program-count) (half output 64) (half output section-count) (half output names-index))\n\n (defun segment (output type flags offset address file-size memory-size alignment)\n (word output type) (word output flags) (quad output offset)\n (quad output address) (quad output address)\n (quad output file-size) (quad output memory-size) (quad output alignment))\n\n (defun section-headers (output sections)\n (let ((i 0))\n (while (< i (js-length sections))\n (let ((entry (js-nth i sections)))\n (word output (get entry :nameIndex 0)) (word output (get entry :type))\n (quad output (get entry :flags)) (quad output (get entry :address))\n (quad output (get entry :offset)) (quad output (js-length (get entry :data)))\n (word output (get entry :link)) (word output (get entry :info))\n (quad output (get entry :align)) (quad output (get entry :entrySize)))\n (setq i (1+ i)))))\n\n (defun layout (sections first-offset)\n (let ((offset first-offset) (i 1))\n (while (< i (js-length sections))\n (let ((entry (js-nth i sections)))\n (setq offset (align offset (get entry :align)))\n (put entry :offset offset)\n (when (/= (bit-and (get entry :flags) 2) 0) (put entry :address offset))\n (setq offset (+ offset (js-length (get entry :data)))))\n (setq i (1+ i)))\n (align offset 8)))\n\n (defun section-names (sections)\n (let ((strings (js-array 0)) (i 1))\n (while (< i (js-length sections))\n (put (js-nth i sections) :nameIndex (string-entry strings (get (js-nth i sections) :name)))\n (setq i (1+ i)))\n strings))\n\n (defun write-sections (output sections)\n (let ((i 1))\n (while (< i (js-length sections))\n (let ((entry (js-nth i sections)))\n (pad output (get entry :offset))\n (let ((data (get entry :data)))\n (if (Array/isArray data) (append output data)\n (let ((words (get data :wordSource)) (reader (get data :wordReader nil)) (j 0))\n (while (< j (js-length words))\n (word output (if reader (funcall reader words j) (js-nth j words))) (setq j (1+ j)))))))\n (setq i (1+ i)))))\n\n (defun text-bytes (code &optional options)\n (let ((output (js-array)) (words (get code :words)) (reader (get code :wordReader nil)) (i 0))\n (if (= (get (or options (js-object)) :binaryEncoding undefined) \"u16le-chunks\")\n (js-object :length (* 4 (js-length words)) :wordSource words :wordReader reader)\n (progn\n (while (< i (js-length words))\n (word output (if reader (funcall reader words i) (js-nth i words))) (setq i (1+ i)))\n output))))\n\n (defun emit-elf-object (program code &optional options)\n (let* ((sym (symbols program code nil 0))\n (sections (js-array\n (section \"\" 0 0 0 0 0 0 (js-array))\n (section \".text\" 1 6 16 0 0 0 (text-bytes code options))\n (section \".symtab\" 2 0 8 24 3 (get sym :localCount) (get sym :bytes))\n (section \".strtab\" 3 0 1 0 0 0 (get sym :strings))\n (section \".shstrtab\" 3 0 1 0 0 0 (js-array))\n (section \".note.GNU-stack\" 1 0 1 0 0 0 (js-array))))\n (output (binary-output options)))\n (put (js-nth 4 sections) :data (section-names sections))\n (let ((section-offset (layout sections 64)))\n ;; ET_REL values are section-relative, rather than load addresses.\n (put (js-nth 1 sections) :address 0)\n (header output 1 0 section-offset 0 (js-length sections) 4)\n (write-sections output sections) (pad output section-offset)\n (section-headers output sections)\n (put code :section (js-object :name \".text\" :fileOffset (get (js-nth 1 sections) :offset)\n :virtualAddress 0 :size (js-length (get (js-nth 1 sections) :data)))))\n (binary-finish output)))\n\n (defun dynamic-entry (output tag value) (quad output tag) (quad output value))\n\n (defun emit-elf-library (program code &optional options)\n (let* ((program-count 5) (text-offset (align (+ 64 (* program-count 56)) 16))\n (dyn (symbols program code t text-offset)) (sym (symbols program code nil text-offset))\n (soname (string-entry (get dyn :strings) \"eliscript.so\"))\n (sections (js-array\n (section \"\" 0 0 0 0 0 0 (js-array))\n (section \".text\" 1 6 16 0 0 0 (text-bytes code options))\n (section \".dynsym\" 11 2 8 24 3 1 (get dyn :bytes))\n (section \".dynstr\" 3 2 1 0 0 0 (get dyn :strings))\n (section \".hash\" 5 2 8 4 2 0 (hash-table dyn))\n (section \".rela.dyn\" 4 2 8 24 2 0 (js-array))\n (section \".dynamic\" 6 3 65536 16 3 0 (js-array))\n (section \".symtab\" 2 0 8 24 8 (get sym :localCount) (get sym :bytes))\n (section \".strtab\" 3 0 1 0 0 0 (get sym :strings))\n (section \".shstrtab\" 3 0 1 0 0 0 (js-array))))\n (dynamic (get (js-nth 6 sections) :data)) (output (binary-output options)))\n ;; Reserve the exact dynamic table before laying out subsequent sections.\n (pad dynamic (* 11 16))\n (put (js-nth 9 sections) :data (section-names sections))\n (let* ((section-offset (layout sections text-offset))\n (dynamic-offset (get (js-nth 6 sections) :offset)))\n (setq dynamic (js-array))\n (dynamic-entry dynamic 4 (get (js-nth 4 sections) :address))\n (dynamic-entry dynamic 5 (get (js-nth 3 sections) :address))\n (dynamic-entry dynamic 6 (get (js-nth 2 sections) :address))\n (dynamic-entry dynamic 10 (js-length (get dyn :strings)))\n (dynamic-entry dynamic 11 24) (dynamic-entry dynamic 14 soname)\n ;; All calls/table entries are resolved relative to this image. There\n ;; are no external symbols or absolute pointers requiring relocation.\n (dynamic-entry dynamic 7 (get (js-nth 5 sections) :address))\n (dynamic-entry dynamic 8 0) (dynamic-entry dynamic 9 24)\n (dynamic-entry dynamic 30 8) (dynamic-entry dynamic 0 0)\n (put (js-nth 6 sections) :data dynamic)\n (header output 3 64 section-offset program-count (js-length sections) 9)\n (segment output 6 4 64 64 (* program-count 56) (* program-count 56) 8)\n (segment output 1 5 0 0 dynamic-offset dynamic-offset 65536)\n (segment output 1 6 dynamic-offset dynamic-offset (js-length dynamic) (js-length dynamic) 65536)\n (segment output 2 6 dynamic-offset dynamic-offset (js-length dynamic) (js-length dynamic) 8)\n (segment output 1685382481 6 0 0 0 0 16)\n (write-sections output sections) (pad output section-offset)\n (section-headers output sections)\n (put code :section (js-object :name \".text\" :fileOffset text-offset :virtualAddress text-offset\n :size (js-length (get (js-nth 1 sections) :data)))))\n (binary-finish output)))\n\n (export emit-elf-object emit-elf-library))\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACE,QAAwB;AACxB,QAAuB,eAAc,aAAY,YAAW,eAAc;AAE1E,eAAc,OAAM;EAClB,OAAA,wBAAG,CAAS,iBAAgB,QAAM,wBAAG,OAAM,YAAW;;AAExD,cAAa,QAAO;EAAO,OAAC,Y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EAAK,MAAK,aAAS,EAAW,QAAM,SAAQ,cAAY,aAAY,kBAAgB,aAClF,QAAM,EAAW,CAAK,IAAU,iBAAF,cAAY;;IAC9C,OAAC,cAAc;;;AAEnB,QAAQ,iBAAgB"}
|
|
1
|
+
{"version":3,"file":"backends/elf.mjs","sources":["bootstrap/backends/elf.eli"],"sourcesContent":["(module eliscript.backend.elf\n (import \"./numeric.mjs\" backend-fail)\n (import \"./binary.mjs\" binary-output binary-byte binary-u32 binary-append binary-finish)\n\n (defun align (value boundary)\n (* (js-call globalThis.Math :ceil (/ value boundary)) boundary))\n\n (defun byte (output value) (binary-byte output value))\n (defun half (output value)\n (byte output value) (byte output (unsigned-bit-shift-right value 8)))\n (defun word (output value)\n (binary-u32 output value))\n (defun quad (output value)\n (unless (and (Number/isSafeInteger value) (>= value 0))\n (backend-fail nil \"ELF address exceeds the exact integer range\"))\n (word output (uint32 value)) (word output (uint32 (/ value 4294967296))))\n (defun pad (output count)\n (while (< (js-length output) count) (byte output 0)))\n (defun append (output input)\n (binary-append output input))\n\n (defun string-entry (output value)\n (let ((start (js-length output)) (i 0))\n (while (< i (js-length value))\n (let ((code (string-code-unit-at value i)))\n (when (= code 0) (backend-fail nil \"ELF symbol contains NUL\"))\n (when (and (>= code 55296) (<= code 56319))\n (let ((next (if (< (1+ i) (js-length value)) (string-code-unit-at value (1+ i)) 0)))\n (unless (and (>= next 56320) (<= next 57343))\n (backend-fail nil \"ELF symbol contains an unpaired surrogate\"))\n (setq code (+ 65536 (* (- code 55296) 1024) (- next 56320)))\n (setq i (1+ i))))\n (when (and (>= code 56320) (<= code 57343))\n (backend-fail nil \"ELF symbol contains an unpaired surrogate\"))\n (cond\n ((< code 128) (byte output code))\n ((< code 2048)\n (byte output (bit-or 192 (unsigned-bit-shift-right code 6)))\n (byte output (bit-or 128 (bit-and code 63))))\n ((< code 65536)\n (byte output (bit-or 224 (unsigned-bit-shift-right code 12)))\n (byte output (bit-or 128 (bit-and (unsigned-bit-shift-right code 6) 63)))\n (byte output (bit-or 128 (bit-and code 63))))\n (t\n (byte output (bit-or 240 (unsigned-bit-shift-right code 18)))\n (byte output (bit-or 128 (bit-and (unsigned-bit-shift-right code 12) 63)))\n (byte output (bit-or 128 (bit-and (unsigned-bit-shift-right code 6) 63)))\n (byte output (bit-or 128 (bit-and code 63))))))\n (setq i (1+ i)))\n (byte output 0) start))\n\n (defun section (name type flags alignment entry-size link info data)\n (js-object :name name :type type :flags flags :align alignment\n :entrySize entry-size :link link :info info :data data :address 0 :offset 0))\n\n (defun symbols (program code public-only text-address)\n (let* ((functions (get program :functions)) (offsets (get code :offsets))\n (exports (get program :exports)) (strings (js-array 0))\n (output (js-array)) (indices (js-array)) (names (js-array)) (i 0) (local-count 1))\n (pad output 24)\n ;; ELF requires every local symbol to precede the first non-local symbol.\n (unless public-only\n (while (< i (js-length functions))\n (unless (js-call exports :includes (get (js-nth i functions) :name))\n (js-call indices :push i) (setq local-count (1+ local-count)))\n (setq i (1+ i))))\n (setq i 0)\n (while (< i (js-length functions))\n (when (js-call exports :includes (get (js-nth i functions) :name)) (js-call indices :push i))\n (setq i (1+ i)))\n (setq i 0)\n (while (< i (js-length indices))\n (let* ((index (js-nth i indices)) (function (js-nth index functions))\n (name (get function :name)) (start (js-nth index offsets))\n (end (if (< (1+ index) (js-length offsets)) (js-nth (1+ index) offsets)\n (* (js-length (get code :words)) 4)))\n (name-offset (string-entry strings name)))\n (js-call names :push name-offset)\n (word output name-offset)\n (byte output (if (js-call exports :includes name) 18 2))\n (byte output 0) (half output 1)\n (quad output (+ text-address start)) (quad output (- end start)))\n (setq i (1+ i)))\n (js-object :bytes output :strings strings :names names :localCount local-count)))\n\n (defun sysv-hash (strings start)\n (let ((hash 0) (i start) (value (js-nth start strings)))\n (while (/= value 0)\n (setq hash (uint32 (+ (* hash 16) value)))\n (let ((high (bit-and hash 4026531840)))\n (when (/= high 0) (setq hash (bit-xor hash (unsigned-bit-shift-right high 24))))\n (setq hash (uint32 (bit-and hash (bit-not high)))))\n (setq i (1+ i)) (setq value (js-nth i strings)))\n hash))\n\n (defun hash-table (symbols)\n (let* ((names (get symbols :names)) (strings (get symbols :strings))\n (count (1+ (js-length names))) (buckets (js-array)) (chains (js-array))\n (bucket-count (if (> count 1) count 1)) (output (js-array)) (i 0))\n (while (< i bucket-count) (js-call buckets :push 0) (setq i (1+ i)))\n (setq i 0)\n (while (< i count) (js-call chains :push 0) (setq i (1+ i)))\n (setq i 1)\n (while (< i count)\n (let* ((hash (sysv-hash strings (js-nth (1- i) names)))\n (bucket (% hash bucket-count)) (previous (js-nth bucket buckets)))\n (js-call chains :splice i 1 previous) (js-call buckets :splice bucket 1 i))\n (setq i (1+ i)))\n (word output bucket-count) (word output count)\n (setq i 0)\n (while (< i bucket-count) (word output (js-nth i buckets)) (setq i (1+ i)))\n (setq i 0)\n (while (< i count) (word output (js-nth i chains)) (setq i (1+ i)))\n output))\n\n (defun header (output kind program-offset section-offset program-count section-count names-index)\n (append output (js-array 127 69 76 70 2 1 1 0 0 0 0 0 0 0 0 0))\n (half output kind) (half output 183) (word output 1)\n (quad output 0) (quad output program-offset) (quad output section-offset)\n (word output 0) (half output 64) (half output (if (> program-count 0) 56 0))\n (half output program-count) (half output 64) (half output section-count) (half output names-index))\n\n (defun segment (output type flags offset address file-size memory-size alignment)\n (word output type) (word output flags) (quad output offset)\n (quad output address) (quad output address)\n (quad output file-size) (quad output memory-size) (quad output alignment))\n\n (defun section-headers (output sections)\n (let ((i 0))\n (while (< i (js-length sections))\n (let ((entry (js-nth i sections)))\n (word output (get entry :nameIndex 0)) (word output (get entry :type))\n (quad output (get entry :flags)) (quad output (get entry :address))\n (quad output (get entry :offset)) (quad output (js-length (get entry :data)))\n (word output (get entry :link)) (word output (get entry :info))\n (quad output (get entry :align)) (quad output (get entry :entrySize)))\n (setq i (1+ i)))))\n\n (defun layout (sections first-offset)\n (let ((offset first-offset) (i 1))\n (while (< i (js-length sections))\n (let ((entry (js-nth i sections)))\n (setq offset (align offset (get entry :align)))\n (put entry :offset offset)\n (when (/= (bit-and (get entry :flags) 2) 0) (put entry :address offset))\n (setq offset (+ offset (js-length (get entry :data)))))\n (setq i (1+ i)))\n (align offset 8)))\n\n (defun section-names (sections)\n (let ((strings (js-array 0)) (i 1))\n (while (< i (js-length sections))\n (put (js-nth i sections) :nameIndex (string-entry strings (get (js-nth i sections) :name)))\n (setq i (1+ i)))\n strings))\n\n (defun write-sections (output sections)\n (let ((i 1))\n (while (< i (js-length sections))\n (let ((entry (js-nth i sections)))\n (pad output (get entry :offset))\n (let ((data (get entry :data)))\n (if (Array/isArray data) (append output data)\n (let ((words (get data :wordSource)) (reader (get data :wordReader nil)) (j 0))\n (while (< j (js-length words))\n (word output (if reader (funcall reader words j) (js-nth j words))) (setq j (1+ j)))))))\n (setq i (1+ i)))))\n\n (defun text-bytes (code &optional options)\n (let ((output (js-array)) (words (get code :words)) (reader (get code :wordReader nil)) (i 0))\n (if (= (get (or options (js-object)) :binaryEncoding undefined) \"u16le-chunks\")\n (js-object :length (* 4 (js-length words)) :wordSource words :wordReader reader)\n (progn\n (while (< i (js-length words))\n (word output (if reader (funcall reader words i) (js-nth i words))) (setq i (1+ i)))\n output))))\n\n (defun emit-elf-object (program code &optional options)\n (let* ((sym (symbols program code nil 0))\n (sections (js-array\n (section \"\" 0 0 0 0 0 0 (js-array))\n (section \".text\" 1 6 16 0 0 0 (text-bytes code options))\n (section \".symtab\" 2 0 8 24 3 (get sym :localCount) (get sym :bytes))\n (section \".strtab\" 3 0 1 0 0 0 (get sym :strings))\n (section \".shstrtab\" 3 0 1 0 0 0 (js-array))\n (section \".note.GNU-stack\" 1 0 1 0 0 0 (js-array))))\n (output (binary-output options)))\n (put (js-nth 4 sections) :data (section-names sections))\n (let ((section-offset (layout sections 64)))\n ;; ET_REL values are section-relative, rather than load addresses.\n (put (js-nth 1 sections) :address 0)\n (header output 1 0 section-offset 0 (js-length sections) 4)\n (write-sections output sections) (pad output section-offset)\n (section-headers output sections)\n (put code :section (js-object :name \".text\" :fileOffset (get (js-nth 1 sections) :offset)\n :virtualAddress 0 :size (js-length (get (js-nth 1 sections) :data)))))\n (binary-finish output)))\n\n (defun dynamic-entry (output tag value) (quad output tag) (quad output value))\n\n (defun emit-elf-library (program code &optional options)\n (let* ((program-count 5) (text-offset (align (+ 64 (* program-count 56)) 16))\n (dyn (symbols program code t text-offset)) (sym (symbols program code nil text-offset))\n (soname (string-entry (get dyn :strings) \"eliscript.so\"))\n (sections (js-array\n (section \"\" 0 0 0 0 0 0 (js-array))\n (section \".text\" 1 6 16 0 0 0 (text-bytes code options))\n (section \".dynsym\" 11 2 8 24 3 1 (get dyn :bytes))\n (section \".dynstr\" 3 2 1 0 0 0 (get dyn :strings))\n (section \".hash\" 5 2 8 4 2 0 (hash-table dyn))\n (section \".rela.dyn\" 4 2 8 24 2 0 (js-array))\n (section \".dynamic\" 6 3 65536 16 3 0 (js-array))\n (section \".symtab\" 2 0 8 24 8 (get sym :localCount) (get sym :bytes))\n (section \".strtab\" 3 0 1 0 0 0 (get sym :strings))\n (section \".shstrtab\" 3 0 1 0 0 0 (js-array))))\n (dynamic (get (js-nth 6 sections) :data)) (output (binary-output options)))\n ;; Reserve the exact dynamic table before laying out subsequent sections.\n (pad dynamic (* 11 16))\n (put (js-nth 9 sections) :data (section-names sections))\n (let* ((section-offset (layout sections text-offset))\n (dynamic-offset (get (js-nth 6 sections) :offset)))\n (setq dynamic (js-array))\n (dynamic-entry dynamic 4 (get (js-nth 4 sections) :address))\n (dynamic-entry dynamic 5 (get (js-nth 3 sections) :address))\n (dynamic-entry dynamic 6 (get (js-nth 2 sections) :address))\n (dynamic-entry dynamic 10 (js-length (get dyn :strings)))\n (dynamic-entry dynamic 11 24) (dynamic-entry dynamic 14 soname)\n ;; All calls/table entries are resolved relative to this image. There\n ;; are no external symbols or absolute pointers requiring relocation.\n (dynamic-entry dynamic 7 (get (js-nth 5 sections) :address))\n (dynamic-entry dynamic 8 0) (dynamic-entry dynamic 9 24)\n (dynamic-entry dynamic 30 8) (dynamic-entry dynamic 0 0)\n (put (js-nth 6 sections) :data dynamic)\n (header output 3 64 section-offset program-count (js-length sections) 9)\n (segment output 6 4 64 64 (* program-count 56) (* program-count 56) 8)\n (segment output 1 5 0 0 dynamic-offset dynamic-offset 65536)\n (segment output 1 6 dynamic-offset dynamic-offset (js-length dynamic) (js-length dynamic) 65536)\n (segment output 2 6 dynamic-offset dynamic-offset (js-length dynamic) (js-length dynamic) 8)\n (segment output 1685382481 6 0 0 0 0 16)\n (write-sections output sections) (pad output section-offset)\n (section-headers output sections)\n (put code :section (js-object :name \".text\" :fileOffset text-offset :virtualAddress text-offset\n :size (js-length (get (js-nth 1 sections) :data)))))\n (binary-finish output)))\n\n (export emit-elf-object emit-elf-library))\n"],"names":[],"mappings":";;;;;;AACE,QAAwB;AACxB,QAAuB,eAAc,aAAY,YAAW,eAAc;AAE1E,eAAc,OAAM;EAClB,OAAA,wBAAG,CAAS,iBAAgB,QAAM,wBAAG,OAAM,YAAW;;AAExD,cAAa,QAAO;EAAO,OAAC,YAAY,QAAO;;AAC/C,cAAa,QAAO;EACjB,KAAK,QAAO;EAAO,OAAC,KAAK,QAAO,yBAA0B,OAAM;;AACnE,cAAa,QAAO;EAClB,OAAC,WAAW,QAAO;;AACrB,cAAa,QAAO;EAClB,yBAAQ,qEAAkC,mCAAI,OAAM,2BAAtC,qBAAqB;IAChC,aAAa,MAAI;;EACnB,KAAK,QAAO,2BAAQ;EAAQ,OAAC,KAAK,QAAO,2BAAQ,wBAAG,OAAM;;AAC7D,aAAY,QAAO;EACjB,OAAO,kCAAG,EAAW,uBAAQ;IAAQ,KAAK,QAAO;;;;AACnD,gBAAe,QAAO;EACpB,OAAC,cAAc,QAAO;;AAExB,sBAAqB,QAAO;EAC1B;gCAAa,EAAW;gCAAY;;UAA9B;UAA2B;MAC/B,OAAO,kCAAG,GAAE,EAAW;QACrB;sCAAY,CAAqB,kBAAM;;gBAAjC;YACJ,IAAM,CA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gdmFyaWFibGUuIik7IH0K";
|
|
3
3
|
var __eliscript_tdz_ready_0;
|
|
4
4
|
function __eliscript_tdz_read_0() { if (__eliscript_tdz_ready_0 !== true) __eliscript_tdz_error("literal_brand_registries"); return literal_brand_registries; }
|
|
5
|
-
function __eliscript_tdz_write_0(__eliscript_tdz_value_0) { if (__eliscript_tdz_ready_0 !== true) __eliscript_tdz_error("literal_brand_registries"); 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("literal_role_registry"); return literal_role_registry; }
|
|
8
|
-
function __eliscript_tdz_write_1(__eliscript_tdz_value_1) { if (__eliscript_tdz_ready_1 !== true) __eliscript_tdz_error("literal_role_registry"); 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("canonical_string_hash_admissions"); return canonical_string_hash_admissions; }
|
|
11
|
-
function __eliscript_tdz_write_2(__eliscript_tdz_value_2) { if (__eliscript_tdz_ready_2 !== true) __eliscript_tdz_error("canonical_string_hash_admissions"); 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("canonical_string_hash_templates"); return canonical_string_hash_templates; }
|
|
14
11
|
function __eliscript_tdz_write_3(__eliscript_tdz_value_3) { if (__eliscript_tdz_ready_3 !== true) __eliscript_tdz_error("canonical_string_hash_templates"); return (canonical_string_hash_templates = __eliscript_tdz_value_3); }
|
|
15
12
|
import "eliscript/runtime/unicode-case.mjs";
|
|
16
13
|
import "eliscript/runtime/math.mjs";
|
|
17
|
-
import {
|
|
14
|
+
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";
|
|
18
15
|
const __eliscript_truthy = (value) => value !== false && value != null;
|
|
19
|
-
const __eliscript_number_intrinsic = globalThis.Number;
|
|
20
|
-
const __eliscript_bigint_intrinsic = globalThis.BigInt;
|
|
21
|
-
const __eliscript_numeric_apply = globalThis.Reflect.apply;
|
|
22
|
-
const __eliscript_numeric_symbol = globalThis.Symbol.toPrimitive;
|
|
23
|
-
const __eliscript_numeric_error = globalThis.TypeError;
|
|
24
|
-
const __eliscript_numeric_trim = globalThis.String.prototype.trim;
|
|
25
|
-
const __eliscript_numeric_slice = globalThis.String.prototype.slice;
|
|
26
|
-
const __eliscript_numeric_exec = globalThis.RegExp.prototype.exec;
|
|
27
|
-
const __eliscript_numeric_radix = /^(?:0[xX][0-9a-fA-F]+|0[oO][0-7]+|0[bB][01]+)$/;
|
|
28
|
-
const __eliscript_numeric_object = (value) => value !== null && (typeof value === "object" || typeof value === "function" || (typeof value === "undefined" && value !== void 0));
|
|
29
|
-
const __eliscript_numeric_primitive = (value) => {
|
|
30
|
-
if (!__eliscript_numeric_object(value)) return value;
|
|
31
|
-
const exotic = value[__eliscript_numeric_symbol];
|
|
32
|
-
if (exotic !== void 0 && exotic !== null) {
|
|
33
|
-
const result = __eliscript_numeric_apply(exotic, value, ["number"]);
|
|
34
|
-
if (!__eliscript_numeric_object(result)) return result;
|
|
35
|
-
throw new __eliscript_numeric_error("Cannot convert object to primitive value");
|
|
36
|
-
}
|
|
37
|
-
for (let index = 0; index < 2; index++) {
|
|
38
|
-
const method = value[index === 0 ? "valueOf" : "toString"];
|
|
39
|
-
if (typeof method === "function" || (typeof method === "undefined" && method !== void 0)) {
|
|
40
|
-
const result = __eliscript_numeric_apply(method, value, []);
|
|
41
|
-
if (!__eliscript_numeric_object(result)) return result;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
throw new __eliscript_numeric_error("Cannot convert object to primitive value");
|
|
45
|
-
};
|
|
46
|
-
const __eliscript_to_number = (value) => {
|
|
47
|
-
const primitive = __eliscript_numeric_primitive(value);
|
|
48
|
-
if (typeof primitive === "string") {
|
|
49
|
-
const text = __eliscript_numeric_apply(__eliscript_numeric_trim, primitive, []);
|
|
50
|
-
if (__eliscript_numeric_apply(__eliscript_numeric_exec, __eliscript_numeric_radix, [text]) !== null) {
|
|
51
|
-
let first = 2;
|
|
52
|
-
while (first < text.length && text[first] === "0") first++;
|
|
53
|
-
if (first === text.length) return 0;
|
|
54
|
-
const prefix = text[1];
|
|
55
|
-
const limit = prefix === "x" || prefix === "X" ? 256 : prefix === "b" || prefix === "B" ? 1024 : 342;
|
|
56
|
-
if (text.length - first > limit) return 1 / 0;
|
|
57
|
-
const token = __eliscript_numeric_apply(__eliscript_numeric_slice, text, [0, 2]) + __eliscript_numeric_apply(__eliscript_numeric_slice, text, [first]);
|
|
58
|
-
return __eliscript_number_intrinsic(__eliscript_bigint_intrinsic(token));
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return __eliscript_number_intrinsic(primitive);
|
|
62
|
-
};
|
|
63
|
-
const __eliscript_numeric = (value) => {
|
|
64
|
-
if (typeof value === "number" || typeof value === "bigint") return value;
|
|
65
|
-
const primitive = __eliscript_numeric_primitive(value);
|
|
66
|
-
if (typeof primitive === "number" || typeof primitive === "bigint") return primitive;
|
|
67
|
-
return typeof primitive === "string" ? __eliscript_to_number(primitive) : +primitive;
|
|
68
|
-
};
|
|
69
|
-
const __eliscript_implicit_number = (value) => {
|
|
70
|
-
if (typeof value === "number") return value;
|
|
71
|
-
const primitive = __eliscript_numeric_primitive(value);
|
|
72
|
-
if (typeof primitive === "bigint") throw new __eliscript_numeric_error("Cannot convert a BigInt value to a number");
|
|
73
|
-
return typeof primitive === "string" ? __eliscript_to_number(primitive) : +primitive;
|
|
74
|
-
};
|
|
75
|
-
const __eliscript_numeric_decrement = (value) => __eliscript_implicit_number(value) - 1;
|
|
76
|
-
const __eliscript_numeric_sub = (a, b) => { if (typeof a === "number" && typeof b === "number") return a - b; return __eliscript_numeric(a) - __eliscript_numeric(b); };
|
|
77
|
-
const __eliscript_numeric_mul = (a, b) => { if (typeof a === "number" && typeof b === "number") return a * b; return __eliscript_numeric(a) * __eliscript_numeric(b); };
|
|
78
|
-
const __eliscript_numeric_div = (a, b) => { if (typeof a === "number" && typeof b === "number") return a / b; return __eliscript_numeric(a) / __eliscript_numeric(b); };
|
|
79
|
-
const __eliscript_numeric_rem = (a, b) => { if (typeof a === "number" && typeof b === "number") return a % b; return __eliscript_numeric(a) % __eliscript_numeric(b); };
|
|
80
|
-
const __eliscript_numeric_and = (a, b) => { if (typeof a === "number" && typeof b === "number") return a & b; return __eliscript_numeric(a) & __eliscript_numeric(b); };
|
|
81
|
-
const __eliscript_numeric_or = (a, b) => { if (typeof a === "number" && typeof b === "number") return a | b; return __eliscript_numeric(a) | __eliscript_numeric(b); };
|
|
82
|
-
const __eliscript_numeric_xor = (a, b) => { if (typeof a === "number" && typeof b === "number") return a ^ b; return __eliscript_numeric(a) ^ __eliscript_numeric(b); };
|
|
83
|
-
const __eliscript_numeric_shl = (a, b) => { if (typeof a === "number" && typeof b === "number") return a << b; return __eliscript_numeric(a) << __eliscript_numeric(b); };
|
|
84
|
-
const __eliscript_numeric_shr = (a, b) => { if (typeof a === "number" && typeof b === "number") return a >> b; return __eliscript_numeric(a) >> __eliscript_numeric(b); };
|
|
85
|
-
const __eliscript_numeric_ushr = (a, b) => { if (typeof a === "number" && typeof b === "number") return a >>> b; return __eliscript_numeric(a) >>> __eliscript_numeric(b); };
|
|
86
|
-
const __eliscript_numeric_neg = (a) => typeof a === "number" ? -a : -__eliscript_numeric(a);
|
|
87
|
-
const __eliscript_numeric_int32 = (a) => typeof a === "number" ? a | 0 : __eliscript_numeric(a) | 0;
|
|
88
|
-
const __eliscript_numeric_uint32 = (a) => typeof a === "number" ? a >>> 0 : __eliscript_numeric(a) >>> 0;
|
|
89
|
-
const __eliscript_numeric_not = (a) => typeof a === "number" ? ~a : ~__eliscript_numeric(a);
|
|
90
|
-
const __eliscript_numeric_relation = (operator, left, right) => {
|
|
91
|
-
if (typeof left === "number" && typeof right === "number") {
|
|
92
|
-
if (operator === "<") return left < right;
|
|
93
|
-
if (operator === "<=") return left <= right;
|
|
94
|
-
if (operator === ">") return left > right;
|
|
95
|
-
return left >= right;
|
|
96
|
-
}
|
|
97
|
-
let a = __eliscript_numeric_primitive(left);
|
|
98
|
-
let b = __eliscript_numeric_primitive(right);
|
|
99
|
-
const x = typeof a, y = typeof b;
|
|
100
|
-
if (!((x === "string" && y === "string") || (x === "bigint" && y === "string") || (x === "string" && y === "bigint"))) {
|
|
101
|
-
a = __eliscript_numeric(a);
|
|
102
|
-
b = __eliscript_numeric(b);
|
|
103
|
-
}
|
|
104
|
-
if (operator === "<") return a < b;
|
|
105
|
-
if (operator === "<=") return a <= b;
|
|
106
|
-
if (operator === ">") return a > b;
|
|
107
|
-
return a >= b;
|
|
108
|
-
};
|
|
109
16
|
|
|
110
17
|
import {backend_fail, find_function} from "./numeric.mjs";
|
|
111
18
|
import {lower_async_program} from "./async.mjs";
|