@scriptc/runtime 0.0.0 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/package.json +16 -6
- package/src/scr_array.c +488 -0
- package/src/scr_assert.c +1393 -0
- package/src/scr_async.c +2593 -0
- package/src/scr_async_dyn.c +607 -0
- package/src/scr_bytes.c +1425 -0
- package/src/scr_bytes_io.c +161 -0
- package/src/scr_child.c +3587 -0
- package/src/scr_closure.c +214 -0
- package/src/scr_console.c +143 -0
- package/src/scr_cycle.c +218 -0
- package/src/scr_dc.c +805 -0
- package/src/scr_dgram.c +1007 -0
- package/src/scr_dyn_handle.c +154 -0
- package/src/scr_dyn_invoke.c +644 -0
- package/src/scr_error.c +332 -0
- package/src/scr_events.c +714 -0
- package/src/scr_events_emitter.c +699 -0
- package/src/scr_exception.c +242 -0
- package/src/scr_fetch.c +1130 -0
- package/src/scr_fetch_curl.c +654 -0
- package/src/scr_http.c +3482 -0
- package/src/scr_http2.c +3030 -0
- package/src/scr_inspect.c +803 -0
- package/src/scr_inspect_island.c +51 -0
- package/src/scr_island.c +9363 -0
- package/src/scr_json.c +2151 -0
- package/src/scr_lib.c +3612 -0
- package/src/scr_loop_epoll.c +241 -0
- package/src/scr_loop_kqueue.c +121 -0
- package/src/scr_loop_wsapoll.c +208 -0
- package/src/scr_map.c +591 -0
- package/src/scr_net.c +3017 -0
- package/src/scr_net_island.c +458 -0
- package/src/scr_number.c +115 -0
- package/src/scr_object.c +25 -0
- package/src/scr_path.c +1266 -0
- package/src/scr_platform.h +119 -0
- package/src/scr_readline.c +287 -0
- package/src/scr_regex.c +1080 -0
- package/src/scr_runtime.h +5046 -0
- package/src/scr_stream.c +2877 -0
- package/src/scr_string.c +1264 -0
- package/src/scr_symbol.c +132 -0
- package/src/scr_test.c +662 -0
- package/src/scr_tls.c +1520 -0
- package/src/scr_union.c +105 -0
- package/src/scr_url.c +911 -0
- package/src/scr_url_internal.h +29 -0
- package/src/scr_url_params.c +561 -0
- package/src/scr_watch.c +568 -0
- package/src/scr_web.c +1778 -0
- package/src/scr_win.c +76 -0
- package/src/scr_zlib.c +197 -0
- package/src/scr_zlib_island.c +15 -0
- package/vendor/README.md +52 -0
- package/vendor/curl/COPYRIGHT +534 -0
- package/vendor/curl/include/curl/curl.h +3214 -0
- package/vendor/curl/include/curl/curlver.h +79 -0
- package/vendor/curl/include/curl/easy.h +125 -0
- package/vendor/curl/include/curl/header.h +74 -0
- package/vendor/curl/include/curl/mprintf.h +52 -0
- package/vendor/curl/include/curl/multi.h +460 -0
- package/vendor/curl/include/curl/options.h +70 -0
- package/vendor/curl/include/curl/stdcheaders.h +35 -0
- package/vendor/curl/include/curl/system.h +508 -0
- package/vendor/curl/include/curl/typecheck-gcc.h +716 -0
- package/vendor/curl/include/curl/urlapi.h +149 -0
- package/vendor/curl/include/curl/websockets.h +84 -0
- package/vendor/mbedtls/LICENSE +553 -0
- package/vendor/mbedtls/include/CMakeLists.txt +22 -0
- package/vendor/mbedtls/include/mbedtls/aes.h +631 -0
- package/vendor/mbedtls/include/mbedtls/aria.h +343 -0
- package/vendor/mbedtls/include/mbedtls/asn1.h +642 -0
- package/vendor/mbedtls/include/mbedtls/asn1write.h +390 -0
- package/vendor/mbedtls/include/mbedtls/base64.h +82 -0
- package/vendor/mbedtls/include/mbedtls/bignum.h +1088 -0
- package/vendor/mbedtls/include/mbedtls/block_cipher.h +76 -0
- package/vendor/mbedtls/include/mbedtls/build_info.h +194 -0
- package/vendor/mbedtls/include/mbedtls/camellia.h +305 -0
- package/vendor/mbedtls/include/mbedtls/ccm.h +526 -0
- package/vendor/mbedtls/include/mbedtls/chacha20.h +209 -0
- package/vendor/mbedtls/include/mbedtls/chachapoly.h +351 -0
- package/vendor/mbedtls/include/mbedtls/check_config.h +1149 -0
- package/vendor/mbedtls/include/mbedtls/cipher.h +1250 -0
- package/vendor/mbedtls/include/mbedtls/cmac.h +246 -0
- package/vendor/mbedtls/include/mbedtls/compat-2.x.h +46 -0
- package/vendor/mbedtls/include/mbedtls/config_adjust_legacy_crypto.h +578 -0
- package/vendor/mbedtls/include/mbedtls/config_adjust_legacy_from_psa.h +873 -0
- package/vendor/mbedtls/include/mbedtls/config_adjust_psa_from_legacy.h +359 -0
- package/vendor/mbedtls/include/mbedtls/config_adjust_psa_superset_legacy.h +145 -0
- package/vendor/mbedtls/include/mbedtls/config_adjust_ssl.h +91 -0
- package/vendor/mbedtls/include/mbedtls/config_adjust_x509.h +35 -0
- package/vendor/mbedtls/include/mbedtls/config_psa.h +61 -0
- package/vendor/mbedtls/include/mbedtls/constant_time.h +36 -0
- package/vendor/mbedtls/include/mbedtls/ctr_drbg.h +596 -0
- package/vendor/mbedtls/include/mbedtls/debug.h +156 -0
- package/vendor/mbedtls/include/mbedtls/des.h +385 -0
- package/vendor/mbedtls/include/mbedtls/dhm.h +972 -0
- package/vendor/mbedtls/include/mbedtls/ecdh.h +455 -0
- package/vendor/mbedtls/include/mbedtls/ecdsa.h +674 -0
- package/vendor/mbedtls/include/mbedtls/ecjpake.h +298 -0
- package/vendor/mbedtls/include/mbedtls/ecp.h +1517 -0
- package/vendor/mbedtls/include/mbedtls/entropy.h +274 -0
- package/vendor/mbedtls/include/mbedtls/error.h +201 -0
- package/vendor/mbedtls/include/mbedtls/gcm.h +387 -0
- package/vendor/mbedtls/include/mbedtls/hkdf.h +124 -0
- package/vendor/mbedtls/include/mbedtls/hmac_drbg.h +434 -0
- package/vendor/mbedtls/include/mbedtls/lms.h +440 -0
- package/vendor/mbedtls/include/mbedtls/mbedtls_config.h +4446 -0
- package/vendor/mbedtls/include/mbedtls/md.h +526 -0
- package/vendor/mbedtls/include/mbedtls/md5.h +190 -0
- package/vendor/mbedtls/include/mbedtls/memory_buffer_alloc.h +142 -0
- package/vendor/mbedtls/include/mbedtls/net_sockets.h +299 -0
- package/vendor/mbedtls/include/mbedtls/nist_kw.h +166 -0
- package/vendor/mbedtls/include/mbedtls/oid.h +727 -0
- package/vendor/mbedtls/include/mbedtls/pem.h +160 -0
- package/vendor/mbedtls/include/mbedtls/pk.h +1303 -0
- package/vendor/mbedtls/include/mbedtls/pkcs12.h +186 -0
- package/vendor/mbedtls/include/mbedtls/pkcs5.h +198 -0
- package/vendor/mbedtls/include/mbedtls/pkcs7.h +252 -0
- package/vendor/mbedtls/include/mbedtls/platform.h +516 -0
- package/vendor/mbedtls/include/mbedtls/platform_time.h +79 -0
- package/vendor/mbedtls/include/mbedtls/platform_util.h +247 -0
- package/vendor/mbedtls/include/mbedtls/poly1305.h +168 -0
- package/vendor/mbedtls/include/mbedtls/private_access.h +20 -0
- package/vendor/mbedtls/include/mbedtls/psa_util.h +207 -0
- package/vendor/mbedtls/include/mbedtls/ripemd160.h +136 -0
- package/vendor/mbedtls/include/mbedtls/rsa.h +1170 -0
- package/vendor/mbedtls/include/mbedtls/sha1.h +219 -0
- package/vendor/mbedtls/include/mbedtls/sha256.h +200 -0
- package/vendor/mbedtls/include/mbedtls/sha3.h +172 -0
- package/vendor/mbedtls/include/mbedtls/sha512.h +208 -0
- package/vendor/mbedtls/include/mbedtls/ssl.h +5887 -0
- package/vendor/mbedtls/include/mbedtls/ssl_cache.h +187 -0
- package/vendor/mbedtls/include/mbedtls/ssl_ciphersuites.h +482 -0
- package/vendor/mbedtls/include/mbedtls/ssl_cookie.h +106 -0
- package/vendor/mbedtls/include/mbedtls/ssl_ticket.h +199 -0
- package/vendor/mbedtls/include/mbedtls/threading.h +167 -0
- package/vendor/mbedtls/include/mbedtls/timing.h +94 -0
- package/vendor/mbedtls/include/mbedtls/version.h +78 -0
- package/vendor/mbedtls/include/mbedtls/x509.h +500 -0
- package/vendor/mbedtls/include/mbedtls/x509_crl.h +184 -0
- package/vendor/mbedtls/include/mbedtls/x509_crt.h +1208 -0
- package/vendor/mbedtls/include/mbedtls/x509_csr.h +382 -0
- package/vendor/mbedtls/include/psa/build_info.h +20 -0
- package/vendor/mbedtls/include/psa/crypto.h +4998 -0
- package/vendor/mbedtls/include/psa/crypto_adjust_auto_enabled.h +31 -0
- package/vendor/mbedtls/include/psa/crypto_adjust_config_dependencies.h +51 -0
- package/vendor/mbedtls/include/psa/crypto_adjust_config_key_pair_types.h +101 -0
- package/vendor/mbedtls/include/psa/crypto_adjust_config_synonyms.h +49 -0
- package/vendor/mbedtls/include/psa/crypto_builtin_composites.h +214 -0
- package/vendor/mbedtls/include/psa/crypto_builtin_key_derivation.h +118 -0
- package/vendor/mbedtls/include/psa/crypto_builtin_primitives.h +114 -0
- package/vendor/mbedtls/include/psa/crypto_compat.h +230 -0
- package/vendor/mbedtls/include/psa/crypto_config.h +145 -0
- package/vendor/mbedtls/include/psa/crypto_driver_common.h +44 -0
- package/vendor/mbedtls/include/psa/crypto_driver_contexts_composites.h +151 -0
- package/vendor/mbedtls/include/psa/crypto_driver_contexts_key_derivation.h +52 -0
- package/vendor/mbedtls/include/psa/crypto_driver_contexts_primitives.h +105 -0
- package/vendor/mbedtls/include/psa/crypto_extra.h +2145 -0
- package/vendor/mbedtls/include/psa/crypto_legacy.h +88 -0
- package/vendor/mbedtls/include/psa/crypto_platform.h +102 -0
- package/vendor/mbedtls/include/psa/crypto_se_driver.h +1383 -0
- package/vendor/mbedtls/include/psa/crypto_sizes.h +1319 -0
- package/vendor/mbedtls/include/psa/crypto_struct.h +527 -0
- package/vendor/mbedtls/include/psa/crypto_types.h +508 -0
- package/vendor/mbedtls/include/psa/crypto_values.h +2782 -0
- package/vendor/mbedtls/library/aes.c +2294 -0
- package/vendor/mbedtls/library/aesce.c +624 -0
- package/vendor/mbedtls/library/aesce.h +136 -0
- package/vendor/mbedtls/library/aesni.c +846 -0
- package/vendor/mbedtls/library/aesni.h +162 -0
- package/vendor/mbedtls/library/alignment.h +704 -0
- package/vendor/mbedtls/library/aria.c +969 -0
- package/vendor/mbedtls/library/asn1parse.c +468 -0
- package/vendor/mbedtls/library/asn1write.c +440 -0
- package/vendor/mbedtls/library/base64.c +322 -0
- package/vendor/mbedtls/library/base64_internal.h +45 -0
- package/vendor/mbedtls/library/bignum.c +2583 -0
- package/vendor/mbedtls/library/bignum_core.c +1240 -0
- package/vendor/mbedtls/library/bignum_core.h +872 -0
- package/vendor/mbedtls/library/bignum_core_invasive.h +38 -0
- package/vendor/mbedtls/library/bignum_internal.h +122 -0
- package/vendor/mbedtls/library/bignum_mod.c +394 -0
- package/vendor/mbedtls/library/bignum_mod.h +452 -0
- package/vendor/mbedtls/library/bignum_mod_raw.c +276 -0
- package/vendor/mbedtls/library/bignum_mod_raw.h +416 -0
- package/vendor/mbedtls/library/bignum_mod_raw_invasive.h +34 -0
- package/vendor/mbedtls/library/block_cipher.c +207 -0
- package/vendor/mbedtls/library/block_cipher_internal.h +99 -0
- package/vendor/mbedtls/library/bn_mul.h +1094 -0
- package/vendor/mbedtls/library/camellia.c +1058 -0
- package/vendor/mbedtls/library/ccm.c +777 -0
- package/vendor/mbedtls/library/chacha20.c +563 -0
- package/vendor/mbedtls/library/chacha20_internal.h +23 -0
- package/vendor/mbedtls/library/chachapoly.c +487 -0
- package/vendor/mbedtls/library/check_crypto_config.h +136 -0
- package/vendor/mbedtls/library/cipher.c +1712 -0
- package/vendor/mbedtls/library/cipher_invasive.h +28 -0
- package/vendor/mbedtls/library/cipher_wrap.c +2482 -0
- package/vendor/mbedtls/library/cipher_wrap.h +178 -0
- package/vendor/mbedtls/library/cmac.c +1067 -0
- package/vendor/mbedtls/library/common.h +487 -0
- package/vendor/mbedtls/library/constant_time.c +247 -0
- package/vendor/mbedtls/library/constant_time_impl.h +541 -0
- package/vendor/mbedtls/library/constant_time_internal.h +579 -0
- package/vendor/mbedtls/library/ctr.h +35 -0
- package/vendor/mbedtls/library/ctr_drbg.c +1016 -0
- package/vendor/mbedtls/library/debug.c +475 -0
- package/vendor/mbedtls/library/debug_internal.h +185 -0
- package/vendor/mbedtls/library/des.c +1042 -0
- package/vendor/mbedtls/library/dhm.c +700 -0
- package/vendor/mbedtls/library/ecdh.c +696 -0
- package/vendor/mbedtls/library/ecdsa.c +858 -0
- package/vendor/mbedtls/library/ecjpake.c +1216 -0
- package/vendor/mbedtls/library/ecp.c +3674 -0
- package/vendor/mbedtls/library/ecp_curves.c +6125 -0
- package/vendor/mbedtls/library/ecp_curves_new.c +9 -0
- package/vendor/mbedtls/library/ecp_internal_alt.h +287 -0
- package/vendor/mbedtls/library/ecp_invasive.h +305 -0
- package/vendor/mbedtls/library/entropy.c +680 -0
- package/vendor/mbedtls/library/entropy_poll.c +233 -0
- package/vendor/mbedtls/library/entropy_poll.h +64 -0
- package/vendor/mbedtls/library/error.c +878 -0
- package/vendor/mbedtls/library/gcm.c +1330 -0
- package/vendor/mbedtls/library/hkdf.c +161 -0
- package/vendor/mbedtls/library/hmac_drbg.c +633 -0
- package/vendor/mbedtls/library/lmots.c +789 -0
- package/vendor/mbedtls/library/lmots.h +288 -0
- package/vendor/mbedtls/library/lms.c +778 -0
- package/vendor/mbedtls/library/md.c +1108 -0
- package/vendor/mbedtls/library/md5.c +426 -0
- package/vendor/mbedtls/library/md_psa.h +26 -0
- package/vendor/mbedtls/library/md_wrap.h +46 -0
- package/vendor/mbedtls/library/memory_buffer_alloc.c +751 -0
- package/vendor/mbedtls/library/mps_common.h +181 -0
- package/vendor/mbedtls/library/mps_error.h +89 -0
- package/vendor/mbedtls/library/mps_reader.c +538 -0
- package/vendor/mbedtls/library/mps_reader.h +366 -0
- package/vendor/mbedtls/library/mps_trace.c +112 -0
- package/vendor/mbedtls/library/mps_trace.h +154 -0
- package/vendor/mbedtls/library/net_sockets.c +694 -0
- package/vendor/mbedtls/library/nist_kw.c +729 -0
- package/vendor/mbedtls/library/oid.c +1166 -0
- package/vendor/mbedtls/library/padlock.c +157 -0
- package/vendor/mbedtls/library/padlock.h +111 -0
- package/vendor/mbedtls/library/pem.c +554 -0
- package/vendor/mbedtls/library/pk.c +1602 -0
- package/vendor/mbedtls/library/pk_ecc.c +261 -0
- package/vendor/mbedtls/library/pk_internal.h +241 -0
- package/vendor/mbedtls/library/pk_wrap.c +1618 -0
- package/vendor/mbedtls/library/pk_wrap.h +138 -0
- package/vendor/mbedtls/library/pkcs12.c +437 -0
- package/vendor/mbedtls/library/pkcs5.c +500 -0
- package/vendor/mbedtls/library/pkcs7.c +787 -0
- package/vendor/mbedtls/library/pkparse.c +1392 -0
- package/vendor/mbedtls/library/pkwrite.c +631 -0
- package/vendor/mbedtls/library/pkwrite.h +121 -0
- package/vendor/mbedtls/library/platform.c +402 -0
- package/vendor/mbedtls/library/platform_util.c +258 -0
- package/vendor/mbedtls/library/poly1305.c +492 -0
- package/vendor/mbedtls/library/psa_crypto.c +9532 -0
- package/vendor/mbedtls/library/psa_crypto_aead.c +646 -0
- package/vendor/mbedtls/library/psa_crypto_aead.h +499 -0
- package/vendor/mbedtls/library/psa_crypto_cipher.c +747 -0
- package/vendor/mbedtls/library/psa_crypto_cipher.h +316 -0
- package/vendor/mbedtls/library/psa_crypto_client.c +22 -0
- package/vendor/mbedtls/library/psa_crypto_core.h +983 -0
- package/vendor/mbedtls/library/psa_crypto_core_common.h +52 -0
- package/vendor/mbedtls/library/psa_crypto_driver_wrappers.h +2896 -0
- package/vendor/mbedtls/library/psa_crypto_driver_wrappers_no_static.c +256 -0
- package/vendor/mbedtls/library/psa_crypto_driver_wrappers_no_static.h +31 -0
- package/vendor/mbedtls/library/psa_crypto_ecp.c +594 -0
- package/vendor/mbedtls/library/psa_crypto_ecp.h +267 -0
- package/vendor/mbedtls/library/psa_crypto_ffdh.c +361 -0
- package/vendor/mbedtls/library/psa_crypto_ffdh.h +131 -0
- package/vendor/mbedtls/library/psa_crypto_hash.c +470 -0
- package/vendor/mbedtls/library/psa_crypto_hash.h +211 -0
- package/vendor/mbedtls/library/psa_crypto_invasive.h +92 -0
- package/vendor/mbedtls/library/psa_crypto_its.h +131 -0
- package/vendor/mbedtls/library/psa_crypto_mac.c +505 -0
- package/vendor/mbedtls/library/psa_crypto_mac.h +264 -0
- package/vendor/mbedtls/library/psa_crypto_pake.c +571 -0
- package/vendor/mbedtls/library/psa_crypto_pake.h +159 -0
- package/vendor/mbedtls/library/psa_crypto_random.c +181 -0
- package/vendor/mbedtls/library/psa_crypto_random.h +72 -0
- package/vendor/mbedtls/library/psa_crypto_random_impl.h +200 -0
- package/vendor/mbedtls/library/psa_crypto_rsa.c +714 -0
- package/vendor/mbedtls/library/psa_crypto_rsa.h +321 -0
- package/vendor/mbedtls/library/psa_crypto_se.c +373 -0
- package/vendor/mbedtls/library/psa_crypto_se.h +192 -0
- package/vendor/mbedtls/library/psa_crypto_slot_management.c +1137 -0
- package/vendor/mbedtls/library/psa_crypto_slot_management.h +344 -0
- package/vendor/mbedtls/library/psa_crypto_storage.c +481 -0
- package/vendor/mbedtls/library/psa_crypto_storage.h +392 -0
- package/vendor/mbedtls/library/psa_its_file.c +254 -0
- package/vendor/mbedtls/library/psa_util.c +614 -0
- package/vendor/mbedtls/library/psa_util_internal.h +100 -0
- package/vendor/mbedtls/library/ripemd160.c +490 -0
- package/vendor/mbedtls/library/rsa.c +3121 -0
- package/vendor/mbedtls/library/rsa_alt_helpers.c +455 -0
- package/vendor/mbedtls/library/rsa_alt_helpers.h +209 -0
- package/vendor/mbedtls/library/rsa_internal.h +188 -0
- package/vendor/mbedtls/library/sha1.c +480 -0
- package/vendor/mbedtls/library/sha256.c +983 -0
- package/vendor/mbedtls/library/sha3.c +721 -0
- package/vendor/mbedtls/library/sha512.c +1115 -0
- package/vendor/mbedtls/library/ssl_cache.c +410 -0
- package/vendor/mbedtls/library/ssl_ciphersuites.c +2050 -0
- package/vendor/mbedtls/library/ssl_ciphersuites_internal.h +154 -0
- package/vendor/mbedtls/library/ssl_client.c +1023 -0
- package/vendor/mbedtls/library/ssl_client.h +22 -0
- package/vendor/mbedtls/library/ssl_cookie.c +384 -0
- package/vendor/mbedtls/library/ssl_debug_helpers.h +85 -0
- package/vendor/mbedtls/library/ssl_debug_helpers_generated.c +251 -0
- package/vendor/mbedtls/library/ssl_misc.h +3198 -0
- package/vendor/mbedtls/library/ssl_msg.c +6619 -0
- package/vendor/mbedtls/library/ssl_ticket.c +556 -0
- package/vendor/mbedtls/library/ssl_tls.c +10234 -0
- package/vendor/mbedtls/library/ssl_tls12_client.c +3688 -0
- package/vendor/mbedtls/library/ssl_tls12_server.c +4311 -0
- package/vendor/mbedtls/library/ssl_tls13_client.c +3208 -0
- package/vendor/mbedtls/library/ssl_tls13_generic.c +1793 -0
- package/vendor/mbedtls/library/ssl_tls13_invasive.h +23 -0
- package/vendor/mbedtls/library/ssl_tls13_keys.c +1918 -0
- package/vendor/mbedtls/library/ssl_tls13_keys.h +668 -0
- package/vendor/mbedtls/library/ssl_tls13_server.c +3624 -0
- package/vendor/mbedtls/library/threading.c +193 -0
- package/vendor/mbedtls/library/threading_internal.h +28 -0
- package/vendor/mbedtls/library/timing.c +152 -0
- package/vendor/mbedtls/library/version.c +32 -0
- package/vendor/mbedtls/library/version_features.c +856 -0
- package/vendor/mbedtls/library/x509.c +1776 -0
- package/vendor/mbedtls/library/x509_create.c +570 -0
- package/vendor/mbedtls/library/x509_crl.c +708 -0
- package/vendor/mbedtls/library/x509_crt.c +3311 -0
- package/vendor/mbedtls/library/x509_csr.c +648 -0
- package/vendor/mbedtls/library/x509_internal.h +101 -0
- package/vendor/mbedtls/library/x509write.c +174 -0
- package/vendor/mbedtls/library/x509write_crt.c +688 -0
- package/vendor/mbedtls/library/x509write_csr.c +336 -0
- package/vendor/quickjs-ng/CMakeLists.txt +566 -0
- package/vendor/quickjs-ng/LICENSE +24 -0
- package/vendor/quickjs-ng/README.md +24 -0
- package/vendor/quickjs-ng/api-test.c +1195 -0
- package/vendor/quickjs-ng/builtin-array-fromasync.h +119 -0
- package/vendor/quickjs-ng/builtin-iterator-zip-keyed.h +332 -0
- package/vendor/quickjs-ng/builtin-iterator-zip.h +337 -0
- package/vendor/quickjs-ng/cutils.h +1998 -0
- package/vendor/quickjs-ng/dtoa.c +1619 -0
- package/vendor/quickjs-ng/dtoa.h +87 -0
- package/vendor/quickjs-ng/gen/function_source.c +81 -0
- package/vendor/quickjs-ng/gen/hello.c +53 -0
- package/vendor/quickjs-ng/gen/hello_module.c +106 -0
- package/vendor/quickjs-ng/gen/repl.c +3036 -0
- package/vendor/quickjs-ng/gen/standalone.c +323 -0
- package/vendor/quickjs-ng/gen/test_fib.c +81 -0
- package/vendor/quickjs-ng/libregexp-opcode.h +73 -0
- package/vendor/quickjs-ng/libregexp.c +3474 -0
- package/vendor/quickjs-ng/libregexp.h +101 -0
- package/vendor/quickjs-ng/libunicode-table.h +5173 -0
- package/vendor/quickjs-ng/libunicode.c +2069 -0
- package/vendor/quickjs-ng/libunicode.h +172 -0
- package/vendor/quickjs-ng/list.h +107 -0
- package/vendor/quickjs-ng/lre-test.c +52 -0
- package/vendor/quickjs-ng/qjs.c +762 -0
- package/vendor/quickjs-ng/qjsc.c +673 -0
- package/vendor/quickjs-ng/quickjs-atom.h +280 -0
- package/vendor/quickjs-ng/quickjs-c-atomics.h +54 -0
- package/vendor/quickjs-ng/quickjs-libc.c +5037 -0
- package/vendor/quickjs-ng/quickjs-libc.h +87 -0
- package/vendor/quickjs-ng/quickjs-opcode.h +377 -0
- package/vendor/quickjs-ng/quickjs.c +64041 -0
- package/vendor/quickjs-ng/quickjs.h +1447 -0
- package/vendor/quickjs-ng/run-test262.c +2374 -0
- package/vendor/quickjs-ng/unicode_gen.c +3121 -0
- package/vendor/quickjs-ng/unicode_gen_def.h +310 -0
- package/vendor/ryu/LICENSE-Boost +23 -0
- package/vendor/ryu/common.h +114 -0
- package/vendor/ryu/d2s.c +509 -0
- package/vendor/ryu/d2s_full_table.h +367 -0
- package/vendor/ryu/d2s_intrinsics.h +357 -0
- package/vendor/ryu/d2s_small_table.h +186 -0
- package/vendor/ryu/digit_table.h +35 -0
- package/vendor/ryu/ryu.h +46 -0
- package/vendor/zlib/LICENSE +22 -0
- package/vendor/zlib/adler32.c +164 -0
- package/vendor/zlib/compress.c +75 -0
- package/vendor/zlib/crc32.c +1049 -0
- package/vendor/zlib/crc32.h +9446 -0
- package/vendor/zlib/deflate.c +2139 -0
- package/vendor/zlib/deflate.h +377 -0
- package/vendor/zlib/gzclose.c +23 -0
- package/vendor/zlib/gzguts.h +214 -0
- package/vendor/zlib/gzlib.c +582 -0
- package/vendor/zlib/gzread.c +602 -0
- package/vendor/zlib/gzwrite.c +631 -0
- package/vendor/zlib/infback.c +628 -0
- package/vendor/zlib/inffast.c +320 -0
- package/vendor/zlib/inffast.h +11 -0
- package/vendor/zlib/inffixed.h +94 -0
- package/vendor/zlib/inflate.c +1526 -0
- package/vendor/zlib/inflate.h +126 -0
- package/vendor/zlib/inftrees.c +299 -0
- package/vendor/zlib/inftrees.h +62 -0
- package/vendor/zlib/trees.c +1117 -0
- package/vendor/zlib/trees.h +128 -0
- package/vendor/zlib/uncompr.c +85 -0
- package/vendor/zlib/zconf.h +543 -0
- package/vendor/zlib/zlib.h +1938 -0
- package/vendor/zlib/zutil.c +299 -0
- package/vendor/zlib/zutil.h +254 -0
- package/README.md +0 -3
- package/index.js +0 -2
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/* The platform readiness contract — ONE interface both event backends
|
|
2
|
+
* implement (kqueue on macOS/BSD, epoll on Linux), designed from how
|
|
3
|
+
* scr_net.c / scr_dgram.c / scr_child.c use kqueue TODAY. Design notes and
|
|
4
|
+
* the full macOS-ism audit live in docs/linux-port.md.
|
|
5
|
+
*
|
|
6
|
+
* Scope, deliberately: the loop CORE (scr_async.c) is already portable —
|
|
7
|
+
* its idle sleep is poll(2)/nanosleep over fds the optional units hand it
|
|
8
|
+
* via the pending/dispatch/pollfd hook triple, and that hook contract is
|
|
9
|
+
* platform-neutral (an epoll fd polls readable while events pend, exactly
|
|
10
|
+
* like a kqueue fd). What is NOT portable is the plumbing INSIDE each
|
|
11
|
+
* unit: kqueue creation, filter add/remove, the idle-timer filter, the
|
|
12
|
+
* child-exit filter, and the zero-timeout drains. This header names that
|
|
13
|
+
* plumbing so each unit can call one spelling and link either backend.
|
|
14
|
+
*
|
|
15
|
+
* STATUS: LIVE. scr_net.c and scr_dgram.c call this contract; cc.ts
|
|
16
|
+
* links BOTH backends whenever either unit compiles (scr_loop_kqueue.c —
|
|
17
|
+
* a stateless spelling of the units' historical inline syscall
|
|
18
|
+
* sequences, byte-identical on macOS by construction — and
|
|
19
|
+
* scr_loop_epoll.c; each TU is empty off its platform). The mapping each
|
|
20
|
+
* backend owes:
|
|
21
|
+
*
|
|
22
|
+
* contract kqueue backend epoll backend
|
|
23
|
+
* ------------------ --------------------------- -------------------------------
|
|
24
|
+
* poller fd the kqueue() fd the epoll_create1() fd
|
|
25
|
+
* watch read on/off EVFILT_READ EV_ADD/EV_DELETE EPOLLIN via ADD/MOD/DEL + fd table
|
|
26
|
+
* watch write on/off EVFILT_WRITE EV_ADD/EV_DELETE EPOLLOUT via ADD/MOD/DEL + fd table
|
|
27
|
+
* one-shot timer(key) EVFILT_TIMER ident=key, one timerfd_create per armed key,
|
|
28
|
+
* EV_ONESHOT, NOTE_* default ms TFD_NONBLOCK, registered EPOLLIN
|
|
29
|
+
* drain (zero timeout) kevent(evs, N, {0,0}) epoll_wait(evs, N, 0)
|
|
30
|
+
* EOF/error delivery EV_EOF on the read filter EPOLLHUP/EPOLLERR/EPOLLRDHUP
|
|
31
|
+
* reported as READABLE (+WRITABLE
|
|
32
|
+
* when write interest is armed) —
|
|
33
|
+
* units learn the truth from
|
|
34
|
+
* read()==0 / errno, as today
|
|
35
|
+
*
|
|
36
|
+
* (Child-exit wakeups live inline in scr_child.c — see the note at the
|
|
37
|
+
* bottom of this header.)
|
|
38
|
+
*
|
|
39
|
+
* Two epoll-only obligations the kqueue side never had, called out so the
|
|
40
|
+
* extraction cannot fudge them: (1) epoll keys interest by fd with
|
|
41
|
+
* ONE mask, so read+write interest on the same fd must merge into a MOD —
|
|
42
|
+
* the backend keeps a private fd -> (mask, udata) table; kqueue's separate
|
|
43
|
+
* filters need no such state. (2) closing an fd does NOT reliably remove
|
|
44
|
+
* it from an epoll set while dup'd references exist — units must call
|
|
45
|
+
* scrp_forget BEFORE close(2). kqueue drops filters on close, so today's
|
|
46
|
+
* units don't always bother; the extraction adds the forget calls (a
|
|
47
|
+
* no-op wrapper on the kqueue side keeps macOS byte-identical in
|
|
48
|
+
* behavior; the corpus proves it). */
|
|
49
|
+
#ifndef SCR_PLATFORM_H
|
|
50
|
+
#define SCR_PLATFORM_H
|
|
51
|
+
|
|
52
|
+
#include <stdbool.h>
|
|
53
|
+
#include <stddef.h>
|
|
54
|
+
|
|
55
|
+
/* ── the fd/timer poller (scr_net.c's and scr_dgram.c's unit kqueues) ── */
|
|
56
|
+
|
|
57
|
+
typedef struct ScrPoller ScrPoller;
|
|
58
|
+
|
|
59
|
+
enum {
|
|
60
|
+
SCRP_READABLE = 1u << 0,
|
|
61
|
+
SCRP_WRITABLE = 1u << 1,
|
|
62
|
+
SCRP_TIMER = 1u << 2,
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
typedef struct {
|
|
66
|
+
void *udata; /* the pointer registered at watch/arm time; routing is
|
|
67
|
+
* the caller's business (scr_net routes on a leading
|
|
68
|
+
* `kind` int, exactly as its kevent udata does today) */
|
|
69
|
+
unsigned events; /* SCRP_* bits OR'd */
|
|
70
|
+
} ScrPollerEvent;
|
|
71
|
+
|
|
72
|
+
/* NULL on resource exhaustion — callers report and disable the unit, the
|
|
73
|
+
* historical kqueue() failure path. */
|
|
74
|
+
ScrPoller *scrp_poller_new(void);
|
|
75
|
+
void scrp_poller_free(ScrPoller *p);
|
|
76
|
+
|
|
77
|
+
/* The fd the LOOP sleeps on (poll(2), POLLIN): readable while any event
|
|
78
|
+
* pends, the property both kqueue and epoll fds share. Owned by the
|
|
79
|
+
* poller — never closed or drained by the caller. */
|
|
80
|
+
int scrp_poller_fd(const ScrPoller *p);
|
|
81
|
+
|
|
82
|
+
/* Watch/unwatch one direction on an fd. `udata` tags every delivery for
|
|
83
|
+
* this fd (the LAST registration wins across both directions — matching
|
|
84
|
+
* how the units pass the same socket pointer to both filters today).
|
|
85
|
+
* Unwatching a direction that isn't armed is a no-op, like EV_DELETE on a
|
|
86
|
+
* missing filter is ignored by today's code. */
|
|
87
|
+
bool scrp_watch_read(ScrPoller *p, int fd, void *udata, bool on);
|
|
88
|
+
bool scrp_watch_write(ScrPoller *p, int fd, void *udata, bool on);
|
|
89
|
+
|
|
90
|
+
/* Drop every registration for fd. MUST precede close(2) of a watched fd
|
|
91
|
+
* (see the epoll obligation above); safe on unwatched fds. */
|
|
92
|
+
void scrp_forget(ScrPoller *p, int fd);
|
|
93
|
+
|
|
94
|
+
/* One-shot timer keyed by an arbitrary pointer (scr_net's idle timers:
|
|
95
|
+
* ident = the socket pointer). Re-arming an armed key replaces its
|
|
96
|
+
* deadline; delivery reports SCRP_TIMER with udata = key. Cancel of an
|
|
97
|
+
* unarmed/already-fired key is a no-op (the timer "may already have
|
|
98
|
+
* fired" comment in scr_net.c today). */
|
|
99
|
+
bool scrp_timer_arm(ScrPoller *p, void *key, double ms, void *udata);
|
|
100
|
+
void scrp_timer_cancel(ScrPoller *p, void *key);
|
|
101
|
+
|
|
102
|
+
/* Zero-timeout drain of everything pending, at most `max` events (the
|
|
103
|
+
* units' dispatch-top drains: kevent/epoll_wait with a zero timeout).
|
|
104
|
+
* Returns the count; EINTR reads as 0 (a spurious pass, as today). */
|
|
105
|
+
int scrp_drain(ScrPoller *p, ScrPollerEvent *out, int max);
|
|
106
|
+
|
|
107
|
+
/* ── child-exit wakeups: NOT here, deliberately ───────────────────────
|
|
108
|
+
* scr_child.c keeps its narrow seam INLINE (scr_child_watch /
|
|
109
|
+
* scr_children_wait / scr_children_wake_fd, plus the stream read-fd
|
|
110
|
+
* arm/dearm): kqueue EVFILT_PROC NOTE_EXIT + EVFILT_READ on BSD,
|
|
111
|
+
* pidfd_open + a dedicated epoll on Linux, and the portable
|
|
112
|
+
* waitpid(WNOHANG)-under-a-~1ms-cap fallback everywhere else. That unit
|
|
113
|
+
* links into EVERY binary, so routing it through this contract would put
|
|
114
|
+
* both backends on every link line; its plumbing (wakeups-only, events
|
|
115
|
+
* discarded, the unit's own unwatched-children accounting) also never
|
|
116
|
+
* matched the fd/timer poller shape above. Reaping stays the WNOHANG
|
|
117
|
+
* sweep on every platform — exit events are wakeups only. */
|
|
118
|
+
|
|
119
|
+
#endif /* SCR_PLATFORM_H */
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
/* node:readline — the question/close slice over the stdin unit
|
|
2
|
+
* (scr_events.c), linked exactly when the program uses it (the events
|
|
3
|
+
* gating; rl.* libCalls imply events).
|
|
4
|
+
*
|
|
5
|
+
* Model, pinned against Node under pipes (SEMANTICS.md + corpus 1475):
|
|
6
|
+
* - createInterface({ input: process.stdin, output: process.stdout })
|
|
7
|
+
* registers this unit's ONE shared stdin data listener (a consumer: the
|
|
8
|
+
* loop watches fd 0 and the process stays alive while any interface is
|
|
9
|
+
* open, exactly Node's un-closed readline) and a global 'end' listener.
|
|
10
|
+
* - Lines split on \n and \r\n (and a bare \r followed by more input);
|
|
11
|
+
* a trailing \r holds until the next chunk decides \r\n vs \r.
|
|
12
|
+
* - question(query, cb) writes the query to stdout (Node writes it under
|
|
13
|
+
* pipes too) and delivers the NEXT line's text; a line arriving with no
|
|
14
|
+
* pending question is DROPPED (Node emits 'line' that nobody hears).
|
|
15
|
+
* - close() removes the consumer (the loop stops waiting on fd 0), drops
|
|
16
|
+
* a pending question (its callback never fires), and fires the 'close'
|
|
17
|
+
* listeners SYNCHRONOUSLY — Node's close() emits inline, which is why
|
|
18
|
+
* the portless prompt's close-listener resolve wins over the question
|
|
19
|
+
* callback's (oracle-pinned).
|
|
20
|
+
* - stdin EOF closes every open interface the same way: the buffered
|
|
21
|
+
* partial line is DISCARDED (Node), then 'close' fires.
|
|
22
|
+
* - question() after close() throws Node's ERR_USE_AFTER_CLOSE message.
|
|
23
|
+
* - An interface created AFTER stdin ended is DEAD (pinned against
|
|
24
|
+
* Node): a question still writes its prompt, but nothing ever answers
|
|
25
|
+
* and 'close' never fires — Node's process exits with the question
|
|
26
|
+
* pending, and the loop exhausts the same way here. */
|
|
27
|
+
#include "scr_runtime.h"
|
|
28
|
+
|
|
29
|
+
#include <stdio.h>
|
|
30
|
+
#include <stdlib.h>
|
|
31
|
+
#include <string.h>
|
|
32
|
+
|
|
33
|
+
static void scr_rl_oom(void) {
|
|
34
|
+
fputs("scriptc: out of memory\n", stderr);
|
|
35
|
+
abort();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
typedef struct ScrRl {
|
|
39
|
+
double id;
|
|
40
|
+
bool closed;
|
|
41
|
+
bool dead; /* created after stdin ended: close fires at question() */
|
|
42
|
+
ScrClosure *q_cb; /* pending question's callback (owned), or NULL */
|
|
43
|
+
void (*q_fn)(ScrClosure *, ScrStr *);
|
|
44
|
+
ScrClosure **close_cbs; /* owned zero-arg listeners */
|
|
45
|
+
size_t n_close, cap_close;
|
|
46
|
+
char *buf; /* undelivered stdin bytes */
|
|
47
|
+
size_t len, cap;
|
|
48
|
+
struct ScrRl *next;
|
|
49
|
+
} ScrRl;
|
|
50
|
+
|
|
51
|
+
static ScrRl *scr_rls = NULL;
|
|
52
|
+
static double scr_rl_next_id = 1;
|
|
53
|
+
static size_t scr_rl_open = 0; /* un-closed, un-dead interfaces */
|
|
54
|
+
static ScrClosure *scr_rl_data_cb = NULL; /* the shared consumer (borrowed
|
|
55
|
+
* mirror; the registry owns) */
|
|
56
|
+
static bool scr_rl_end_registered = false;
|
|
57
|
+
|
|
58
|
+
static ScrRl *scr_rl_find(double id) {
|
|
59
|
+
for (ScrRl *rl = scr_rls; rl; rl = rl->next) {
|
|
60
|
+
if (rl->id == id) return rl;
|
|
61
|
+
}
|
|
62
|
+
return NULL;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/* Fires the close listeners (snapshot; synchronous, like Node's emit) and
|
|
66
|
+
* releases everything the interface holds. */
|
|
67
|
+
static void scr_rl_settle_close(ScrRl *rl) {
|
|
68
|
+
if (rl->closed) return;
|
|
69
|
+
rl->closed = true;
|
|
70
|
+
if (!rl->dead && scr_rl_open > 0) scr_rl_open--;
|
|
71
|
+
if (rl->q_cb) {
|
|
72
|
+
scr_closure_release(rl->q_cb); /* a pending question never answers */
|
|
73
|
+
rl->q_cb = NULL;
|
|
74
|
+
}
|
|
75
|
+
/* The last open interface leaving detaches the shared consumer so the
|
|
76
|
+
* loop stops waiting on fd 0 (Node's pause-on-close). */
|
|
77
|
+
if (scr_rl_open == 0 && scr_rl_data_cb != NULL) {
|
|
78
|
+
scr_stdin_remove_data(scr_rl_data_cb);
|
|
79
|
+
scr_rl_data_cb = NULL;
|
|
80
|
+
}
|
|
81
|
+
size_t n = rl->n_close;
|
|
82
|
+
ScrClosure **snap = rl->close_cbs;
|
|
83
|
+
rl->close_cbs = NULL;
|
|
84
|
+
rl->n_close = rl->cap_close = 0;
|
|
85
|
+
for (size_t i = 0; i < n; i++) {
|
|
86
|
+
if (!scr_exc_pending()) {
|
|
87
|
+
((void (*)(ScrClosure *))snap[i]->fn)(snap[i]);
|
|
88
|
+
}
|
|
89
|
+
scr_closure_release(snap[i]);
|
|
90
|
+
}
|
|
91
|
+
free(snap);
|
|
92
|
+
free(rl->buf);
|
|
93
|
+
rl->buf = NULL;
|
|
94
|
+
rl->len = rl->cap = 0;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/* One complete line off the front of the buffer: *adv is the byte count
|
|
98
|
+
* consumed (terminator included), *line_len the line's length. False when
|
|
99
|
+
* no complete line is buffered (a trailing \r holds for the \r\n
|
|
100
|
+
* decision). */
|
|
101
|
+
static bool scr_rl_scan(const ScrRl *rl, size_t *line_len, size_t *adv) {
|
|
102
|
+
for (size_t i = 0; i < rl->len; i++) {
|
|
103
|
+
char c = rl->buf[i];
|
|
104
|
+
if (c == '\n') {
|
|
105
|
+
*line_len = i;
|
|
106
|
+
*adv = i + 1;
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
if (c == '\r') {
|
|
110
|
+
if (i + 1 >= rl->len) return false; /* hold: \r\n may straddle chunks */
|
|
111
|
+
*line_len = i;
|
|
112
|
+
*adv = rl->buf[i + 1] == '\n' ? i + 2 : i + 1;
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
static void scr_rl_drain(ScrRl *rl) {
|
|
120
|
+
size_t line_len, adv;
|
|
121
|
+
while (!rl->closed && scr_rl_scan(rl, &line_len, &adv)) {
|
|
122
|
+
ScrStr *line = NULL;
|
|
123
|
+
ScrClosure *cb = rl->q_cb;
|
|
124
|
+
void (*fn)(ScrClosure *, ScrStr *) = rl->q_fn;
|
|
125
|
+
if (cb) line = scr_str_new(rl->buf, line_len);
|
|
126
|
+
memmove(rl->buf, rl->buf + adv, rl->len - adv);
|
|
127
|
+
rl->len -= adv;
|
|
128
|
+
if (cb) {
|
|
129
|
+
rl->q_cb = NULL; /* consumed BEFORE the callback runs (once) */
|
|
130
|
+
fn(cb, line); /* the adapter owns the +1 line */
|
|
131
|
+
scr_closure_release(cb);
|
|
132
|
+
if (scr_exc_pending()) return;
|
|
133
|
+
}
|
|
134
|
+
/* No pending question: the line drops, exactly Node's unheard 'line'. */
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/* The shared stdin data consumer: appends and drains every open
|
|
139
|
+
* interface (chunks broadcast, like any stdin listener set). */
|
|
140
|
+
static void scr_rl_data_adapter(ScrClosure *cb, ScrBytes *chunk) {
|
|
141
|
+
(void)cb;
|
|
142
|
+
for (ScrRl *rl = scr_rls; rl; rl = rl->next) {
|
|
143
|
+
if (rl->closed || rl->dead) continue;
|
|
144
|
+
if (rl->len + chunk->len > rl->cap) {
|
|
145
|
+
rl->cap = (rl->len + chunk->len) * 2 + 64;
|
|
146
|
+
rl->buf = realloc(rl->buf, rl->cap);
|
|
147
|
+
if (!rl->buf) scr_rl_oom();
|
|
148
|
+
}
|
|
149
|
+
memcpy(rl->buf + rl->len, chunk->data, chunk->len);
|
|
150
|
+
rl->len += chunk->len;
|
|
151
|
+
scr_rl_drain(rl);
|
|
152
|
+
if (scr_exc_pending()) return;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/* stdin EOF: every open interface closes — the buffered partial line is
|
|
157
|
+
* DISCARDED (Node; a trailing held \r still terminates its line first). */
|
|
158
|
+
static void scr_rl_end_thunk(ScrClosure *cb) {
|
|
159
|
+
(void)cb;
|
|
160
|
+
scr_rl_data_cb = NULL; /* the stdin unit dropped its listeners itself */
|
|
161
|
+
for (ScrRl *rl = scr_rls; rl; rl = rl->next) {
|
|
162
|
+
if (rl->closed || rl->dead) continue;
|
|
163
|
+
if (rl->len > 0 && rl->buf[rl->len - 1] == '\r' && rl->q_cb) {
|
|
164
|
+
/* "a\r" then EOF: the \r terminates the line (Node's crlfDelay
|
|
165
|
+
* expiry collapsed to EOF time). */
|
|
166
|
+
ScrStr *line = scr_str_new(rl->buf, rl->len - 1);
|
|
167
|
+
ScrClosure *qcb = rl->q_cb;
|
|
168
|
+
void (*fn)(ScrClosure *, ScrStr *) = rl->q_fn;
|
|
169
|
+
rl->q_cb = NULL;
|
|
170
|
+
rl->len = 0;
|
|
171
|
+
fn(qcb, line);
|
|
172
|
+
scr_closure_release(qcb);
|
|
173
|
+
if (scr_exc_pending()) return;
|
|
174
|
+
}
|
|
175
|
+
scr_rl_settle_close(rl);
|
|
176
|
+
if (scr_exc_pending()) return;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/* Exit-time cleanup (the events-unit precedent, before the RC audit):
|
|
181
|
+
* whatever an interface still holds — a parked question, close listeners
|
|
182
|
+
* on a dead interface that never asked — releases here. */
|
|
183
|
+
static void scr_rl_cleanup_atexit(void) {
|
|
184
|
+
for (ScrRl *rl = scr_rls; rl; rl = rl->next) {
|
|
185
|
+
if (rl->q_cb) {
|
|
186
|
+
scr_closure_release(rl->q_cb);
|
|
187
|
+
rl->q_cb = NULL;
|
|
188
|
+
}
|
|
189
|
+
for (size_t i = 0; i < rl->n_close; i++) scr_closure_release(rl->close_cbs[i]);
|
|
190
|
+
free(rl->close_cbs);
|
|
191
|
+
rl->close_cbs = NULL;
|
|
192
|
+
rl->n_close = rl->cap_close = 0;
|
|
193
|
+
free(rl->buf);
|
|
194
|
+
rl->buf = NULL;
|
|
195
|
+
rl->len = rl->cap = 0;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
double scr_rl_create(void) {
|
|
200
|
+
static bool cleanup_registered = false;
|
|
201
|
+
if (!cleanup_registered) {
|
|
202
|
+
cleanup_registered = true;
|
|
203
|
+
atexit(scr_rl_cleanup_atexit);
|
|
204
|
+
}
|
|
205
|
+
ScrRl *rl = calloc(1, sizeof *rl);
|
|
206
|
+
if (!rl) scr_rl_oom();
|
|
207
|
+
rl->id = scr_rl_next_id++;
|
|
208
|
+
rl->next = scr_rls;
|
|
209
|
+
scr_rls = rl;
|
|
210
|
+
if (scr_stdin_ended()) {
|
|
211
|
+
rl->dead = true; /* close fires when a question is asked */
|
|
212
|
+
return rl->id;
|
|
213
|
+
}
|
|
214
|
+
scr_rl_open++;
|
|
215
|
+
if (scr_rl_data_cb == NULL) {
|
|
216
|
+
/* One shared consumer + one global end hook. The closures carry no
|
|
217
|
+
* captures; their fn slots are never invoked directly for the data
|
|
218
|
+
* one (the registered adapter is), and the end one IS its thunk. */
|
|
219
|
+
scr_rl_data_cb = scr_closure_new((void *)&scr_rl_data_adapter, 0);
|
|
220
|
+
scr_stdin_on_data(scr_rl_data_cb, &scr_rl_data_adapter, false);
|
|
221
|
+
}
|
|
222
|
+
if (!scr_rl_end_registered) {
|
|
223
|
+
scr_rl_end_registered = true;
|
|
224
|
+
scr_stdin_on_end(scr_closure_new((void *)&scr_rl_end_thunk, 0), false);
|
|
225
|
+
}
|
|
226
|
+
return rl->id;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
void scr_rl_question(double id, const ScrStr *query, ScrClosure *cb /*moves*/,
|
|
230
|
+
void (*fn)(ScrClosure *, ScrStr *)) {
|
|
231
|
+
ScrRl *rl = scr_rl_find(id);
|
|
232
|
+
if (!rl || rl->closed) {
|
|
233
|
+
scr_closure_release(cb);
|
|
234
|
+
/* Node's ERR_USE_AFTER_CLOSE. */
|
|
235
|
+
scr_throw_error_msg(SCR_ERR_ERROR, "readline was closed", 19);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
/* The prompt writes to stdout under pipes too (Node's question does);
|
|
239
|
+
* same stream and buffer as console.log, so ordering holds. */
|
|
240
|
+
fwrite(query->data, 1, query->len, stdout);
|
|
241
|
+
if (rl->dead) {
|
|
242
|
+
/* Created after stdin ended: pinned against Node — the prompt still
|
|
243
|
+
* writes, but the DESTROYED stream delivers nothing and 'close'
|
|
244
|
+
* never fires (Node's process exits with the question pending; the
|
|
245
|
+
* loop exhausts the same way here). The callback releases now. */
|
|
246
|
+
scr_closure_release(cb);
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
if (rl->q_cb) scr_closure_release(rl->q_cb); /* re-ask replaces (Node) */
|
|
250
|
+
rl->q_cb = cb;
|
|
251
|
+
rl->q_fn = fn;
|
|
252
|
+
scr_rl_drain(rl); /* an already-buffered line answers immediately */
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
void scr_rl_close(double id) {
|
|
256
|
+
ScrRl *rl = scr_rl_find(id);
|
|
257
|
+
if (!rl) return;
|
|
258
|
+
scr_rl_settle_close(rl); /* twice is a no-op, like Node */
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
void scr_rl_on_close(double id, ScrClosure *cb /*moves*/) {
|
|
262
|
+
ScrRl *rl = scr_rl_find(id);
|
|
263
|
+
if (!rl || rl->closed) {
|
|
264
|
+
scr_closure_release(cb); /* after 'close' emitted: never fires */
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (rl->n_close == rl->cap_close) {
|
|
268
|
+
rl->cap_close = rl->cap_close ? rl->cap_close * 2 : 2;
|
|
269
|
+
rl->close_cbs = realloc(rl->close_cbs, rl->cap_close * sizeof *rl->close_cbs);
|
|
270
|
+
if (!rl->close_cbs) scr_rl_oom();
|
|
271
|
+
}
|
|
272
|
+
rl->close_cbs[rl->n_close++] = cb;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/* ── the runtime-provided answer adapters ────────────────────────────── */
|
|
276
|
+
|
|
277
|
+
/* A zero-param question callback: the answer is ignored. */
|
|
278
|
+
void scr_rl_answer_thunk0(ScrClosure *cb, ScrStr *answer) {
|
|
279
|
+
scr_str_release(answer);
|
|
280
|
+
((void (*)(ScrClosure *))cb->fn)(cb);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/* An (answer: string) callback — owns the +1 answer per the universal
|
|
284
|
+
* convention. */
|
|
285
|
+
void scr_rl_answer_thunk_str(ScrClosure *cb, ScrStr *answer) {
|
|
286
|
+
((void (*)(ScrClosure *, ScrStr *))cb->fn)(cb, answer);
|
|
287
|
+
}
|