@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,673 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* QuickJS command line compiler
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2018-2026 Fabrice Bellard
|
|
5
|
+
* Copyright (c) 2023-2026 Ben Noordhuis
|
|
6
|
+
* Copyright (c) 2023-2026 Saúl Ibarra Corretgé
|
|
7
|
+
*
|
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
* furnished to do so, subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in
|
|
16
|
+
* all copies or substantial portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
21
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
24
|
+
* THE SOFTWARE.
|
|
25
|
+
*/
|
|
26
|
+
#include <stdlib.h>
|
|
27
|
+
#include <stdio.h>
|
|
28
|
+
#include <stdarg.h>
|
|
29
|
+
#include <inttypes.h>
|
|
30
|
+
#include <string.h>
|
|
31
|
+
#include <assert.h>
|
|
32
|
+
#include <errno.h>
|
|
33
|
+
|
|
34
|
+
#include "cutils.h"
|
|
35
|
+
#include "quickjs-libc.h"
|
|
36
|
+
|
|
37
|
+
typedef enum {
|
|
38
|
+
OUTPUT_C,
|
|
39
|
+
OUTPUT_C_MAIN,
|
|
40
|
+
OUTPUT_RAW,
|
|
41
|
+
} OutputTypeEnum;
|
|
42
|
+
|
|
43
|
+
typedef struct {
|
|
44
|
+
char *name;
|
|
45
|
+
char *short_name;
|
|
46
|
+
int flags;
|
|
47
|
+
} namelist_entry_t;
|
|
48
|
+
|
|
49
|
+
typedef struct namelist_t {
|
|
50
|
+
namelist_entry_t *array;
|
|
51
|
+
int count;
|
|
52
|
+
int size;
|
|
53
|
+
} namelist_t;
|
|
54
|
+
|
|
55
|
+
static namelist_t cname_list;
|
|
56
|
+
static namelist_t cmodule_list;
|
|
57
|
+
static namelist_t init_module_list;
|
|
58
|
+
static OutputTypeEnum output_type;
|
|
59
|
+
static FILE *outfile;
|
|
60
|
+
static const char *c_ident_prefix = "qjsc_";
|
|
61
|
+
static int strip;
|
|
62
|
+
|
|
63
|
+
void namelist_add(namelist_t *lp, const char *name, const char *short_name,
|
|
64
|
+
int flags)
|
|
65
|
+
{
|
|
66
|
+
namelist_entry_t *e;
|
|
67
|
+
if (lp->count == lp->size) {
|
|
68
|
+
size_t newsize = lp->size + (lp->size >> 1) + 4;
|
|
69
|
+
namelist_entry_t *a =
|
|
70
|
+
realloc(lp->array, sizeof(lp->array[0]) * newsize);
|
|
71
|
+
/* XXX: check for realloc failure */
|
|
72
|
+
lp->array = a;
|
|
73
|
+
lp->size = newsize;
|
|
74
|
+
}
|
|
75
|
+
e = &lp->array[lp->count++];
|
|
76
|
+
e->name = strdup(name);
|
|
77
|
+
if (short_name)
|
|
78
|
+
e->short_name = strdup(short_name);
|
|
79
|
+
else
|
|
80
|
+
e->short_name = NULL;
|
|
81
|
+
e->flags = flags;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
void namelist_free(namelist_t *lp)
|
|
85
|
+
{
|
|
86
|
+
while (lp->count > 0) {
|
|
87
|
+
namelist_entry_t *e = &lp->array[--lp->count];
|
|
88
|
+
free(e->name);
|
|
89
|
+
free(e->short_name);
|
|
90
|
+
}
|
|
91
|
+
free(lp->array);
|
|
92
|
+
lp->array = NULL;
|
|
93
|
+
lp->size = 0;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
namelist_entry_t *namelist_find(namelist_t *lp, const char *name)
|
|
97
|
+
{
|
|
98
|
+
int i;
|
|
99
|
+
for(i = 0; i < lp->count; i++) {
|
|
100
|
+
namelist_entry_t *e = &lp->array[i];
|
|
101
|
+
if (!strcmp(e->name, name))
|
|
102
|
+
return e;
|
|
103
|
+
}
|
|
104
|
+
return NULL;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
static void get_c_name(char *buf, size_t buf_size, const char *file)
|
|
108
|
+
{
|
|
109
|
+
const char *p, *r;
|
|
110
|
+
size_t len, i;
|
|
111
|
+
int c;
|
|
112
|
+
char *q;
|
|
113
|
+
|
|
114
|
+
p = strrchr(file, '/');
|
|
115
|
+
if (!p)
|
|
116
|
+
p = file;
|
|
117
|
+
else
|
|
118
|
+
p++;
|
|
119
|
+
r = strrchr(p, '.');
|
|
120
|
+
if (!r)
|
|
121
|
+
len = strlen(p);
|
|
122
|
+
else
|
|
123
|
+
len = r - p;
|
|
124
|
+
js__pstrcpy(buf, buf_size, c_ident_prefix);
|
|
125
|
+
q = buf + strlen(buf);
|
|
126
|
+
for(i = 0; i < len; i++) {
|
|
127
|
+
c = p[i];
|
|
128
|
+
if (!((c >= '0' && c <= '9') ||
|
|
129
|
+
(c >= 'A' && c <= 'Z') ||
|
|
130
|
+
(c >= 'a' && c <= 'z'))) {
|
|
131
|
+
c = '_';
|
|
132
|
+
}
|
|
133
|
+
if ((q - buf) < buf_size - 1)
|
|
134
|
+
*q++ = c;
|
|
135
|
+
}
|
|
136
|
+
*q = '\0';
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
static void dump_hex(FILE *f, const uint8_t *buf, size_t len)
|
|
140
|
+
{
|
|
141
|
+
size_t i, col;
|
|
142
|
+
col = 0;
|
|
143
|
+
for(i = 0; i < len; i++) {
|
|
144
|
+
fprintf(f, " 0x%02x,", buf[i]);
|
|
145
|
+
if (++col == 8) {
|
|
146
|
+
fprintf(f, "\n");
|
|
147
|
+
col = 0;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (col != 0)
|
|
151
|
+
fprintf(f, "\n");
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
static void output_object_code(JSContext *ctx,
|
|
155
|
+
FILE *fo, JSValue obj, const char *c_name,
|
|
156
|
+
bool load_only)
|
|
157
|
+
{
|
|
158
|
+
uint8_t *out_buf;
|
|
159
|
+
size_t out_buf_len;
|
|
160
|
+
int flags = JS_WRITE_OBJ_BYTECODE;
|
|
161
|
+
|
|
162
|
+
if (strip) {
|
|
163
|
+
flags |= JS_WRITE_OBJ_STRIP_SOURCE;
|
|
164
|
+
if (strip > 1)
|
|
165
|
+
flags |= JS_WRITE_OBJ_STRIP_DEBUG;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
out_buf = JS_WriteObject(ctx, &out_buf_len, obj, flags);
|
|
169
|
+
if (!out_buf) {
|
|
170
|
+
js_std_dump_error(ctx);
|
|
171
|
+
exit(1);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
namelist_add(&cname_list, c_name, NULL, load_only);
|
|
175
|
+
|
|
176
|
+
if (output_type == OUTPUT_RAW) {
|
|
177
|
+
fwrite(out_buf, 1, out_buf_len, fo);
|
|
178
|
+
} else {
|
|
179
|
+
fprintf(fo, "const uint32_t %s_size = %u;\n\n",
|
|
180
|
+
c_name, (unsigned int)out_buf_len);
|
|
181
|
+
fprintf(fo, "const uint8_t %s[%u] = {\n",
|
|
182
|
+
c_name, (unsigned int)out_buf_len);
|
|
183
|
+
dump_hex(fo, out_buf, out_buf_len);
|
|
184
|
+
fprintf(fo, "};\n\n");
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
js_free(ctx, out_buf);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
static int js_module_dummy_init(JSContext *ctx, JSModuleDef *m)
|
|
191
|
+
{
|
|
192
|
+
/* should never be called when compiling JS code */
|
|
193
|
+
abort();
|
|
194
|
+
return -1; // pacify compiler
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
static void find_unique_cname(char *cname, size_t cname_size)
|
|
198
|
+
{
|
|
199
|
+
char cname1[1024];
|
|
200
|
+
int suffix_num;
|
|
201
|
+
size_t len, max_len;
|
|
202
|
+
assert(cname_size >= 32);
|
|
203
|
+
/* find a C name not matching an existing module C name by
|
|
204
|
+
adding a numeric suffix */
|
|
205
|
+
len = strlen(cname);
|
|
206
|
+
max_len = cname_size - 16;
|
|
207
|
+
if (len > max_len)
|
|
208
|
+
cname[max_len] = '\0';
|
|
209
|
+
suffix_num = 1;
|
|
210
|
+
for(;;) {
|
|
211
|
+
snprintf(cname1, sizeof(cname1), "%s_%d", cname, suffix_num);
|
|
212
|
+
if (!namelist_find(&cname_list, cname1))
|
|
213
|
+
break;
|
|
214
|
+
suffix_num++;
|
|
215
|
+
}
|
|
216
|
+
js__pstrcpy(cname, cname_size, cname1);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
JSModuleDef *jsc_module_loader(JSContext *ctx,
|
|
220
|
+
const char *module_name, void *opaque)
|
|
221
|
+
{
|
|
222
|
+
JSModuleDef *m;
|
|
223
|
+
namelist_entry_t *e;
|
|
224
|
+
|
|
225
|
+
/* check if it is a declared C or system module */
|
|
226
|
+
e = namelist_find(&cmodule_list, module_name);
|
|
227
|
+
if (e) {
|
|
228
|
+
/* add in the static init module list */
|
|
229
|
+
namelist_add(&init_module_list, e->name, e->short_name, 0);
|
|
230
|
+
/* create a dummy module */
|
|
231
|
+
m = JS_NewCModule(ctx, module_name, js_module_dummy_init);
|
|
232
|
+
} else if (js__has_suffix(module_name, ".so")) {
|
|
233
|
+
JS_ThrowReferenceError(ctx, "%s: dynamically linking to shared libraries not supported",
|
|
234
|
+
module_name);
|
|
235
|
+
return NULL;
|
|
236
|
+
} else {
|
|
237
|
+
size_t buf_len;
|
|
238
|
+
uint8_t *buf;
|
|
239
|
+
JSValue func_val;
|
|
240
|
+
char cname[1000];
|
|
241
|
+
|
|
242
|
+
buf = js_load_file(ctx, &buf_len, module_name);
|
|
243
|
+
if (!buf) {
|
|
244
|
+
JS_ThrowReferenceError(ctx, "could not load module filename '%s'",
|
|
245
|
+
module_name);
|
|
246
|
+
return NULL;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/* compile the module */
|
|
250
|
+
func_val = JS_Eval(ctx, (char *)buf, buf_len, module_name,
|
|
251
|
+
JS_EVAL_TYPE_MODULE | JS_EVAL_FLAG_COMPILE_ONLY);
|
|
252
|
+
js_free(ctx, buf);
|
|
253
|
+
if (JS_IsException(func_val))
|
|
254
|
+
return NULL;
|
|
255
|
+
get_c_name(cname, sizeof(cname), module_name);
|
|
256
|
+
if (namelist_find(&cname_list, cname)) {
|
|
257
|
+
find_unique_cname(cname, sizeof(cname));
|
|
258
|
+
}
|
|
259
|
+
output_object_code(ctx, outfile, func_val, cname, true);
|
|
260
|
+
|
|
261
|
+
/* the module is already referenced, so we must free it */
|
|
262
|
+
m = JS_VALUE_GET_PTR(func_val);
|
|
263
|
+
JS_FreeValue(ctx, func_val);
|
|
264
|
+
}
|
|
265
|
+
return m;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
static void compile_file(JSContext *ctx, FILE *fo,
|
|
269
|
+
const char *filename,
|
|
270
|
+
const char *script_name,
|
|
271
|
+
const char *c_name1,
|
|
272
|
+
int module)
|
|
273
|
+
{
|
|
274
|
+
uint8_t *buf;
|
|
275
|
+
char c_name[1024];
|
|
276
|
+
int eval_flags;
|
|
277
|
+
JSValue obj;
|
|
278
|
+
size_t buf_len;
|
|
279
|
+
|
|
280
|
+
buf = js_load_file(ctx, &buf_len, filename);
|
|
281
|
+
if (!buf) {
|
|
282
|
+
fprintf(stderr, "Could not load '%s'\n", filename);
|
|
283
|
+
exit(1);
|
|
284
|
+
}
|
|
285
|
+
eval_flags = JS_EVAL_FLAG_COMPILE_ONLY;
|
|
286
|
+
if (module < 0) {
|
|
287
|
+
module = (js__has_suffix(filename, ".mjs") ||
|
|
288
|
+
JS_DetectModule((const char *)buf, buf_len));
|
|
289
|
+
}
|
|
290
|
+
if (module)
|
|
291
|
+
eval_flags |= JS_EVAL_TYPE_MODULE;
|
|
292
|
+
else
|
|
293
|
+
eval_flags |= JS_EVAL_TYPE_GLOBAL;
|
|
294
|
+
obj = JS_Eval(ctx, (const char *)buf, buf_len, script_name ? script_name : filename, eval_flags);
|
|
295
|
+
if (JS_IsException(obj)) {
|
|
296
|
+
js_std_dump_error(ctx);
|
|
297
|
+
exit(1);
|
|
298
|
+
}
|
|
299
|
+
js_free(ctx, buf);
|
|
300
|
+
if (c_name1) {
|
|
301
|
+
js__pstrcpy(c_name, sizeof(c_name), c_name1);
|
|
302
|
+
} else {
|
|
303
|
+
get_c_name(c_name, sizeof(c_name), filename);
|
|
304
|
+
}
|
|
305
|
+
output_object_code(ctx, fo, obj, c_name, false);
|
|
306
|
+
JS_FreeValue(ctx, obj);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
static const char main_c_template1[] =
|
|
310
|
+
"int main(int argc, char **argv)\n"
|
|
311
|
+
"{\n"
|
|
312
|
+
" int r;\n"
|
|
313
|
+
" JSRuntime *rt;\n"
|
|
314
|
+
" JSContext *ctx;\n"
|
|
315
|
+
" r = 0;\n"
|
|
316
|
+
" rt = JS_NewRuntime();\n"
|
|
317
|
+
" js_std_set_worker_new_context_func(JS_NewCustomContext);\n"
|
|
318
|
+
" js_std_init_handlers(rt);\n"
|
|
319
|
+
;
|
|
320
|
+
|
|
321
|
+
static const char main_c_template2[] =
|
|
322
|
+
" r = js_std_loop(ctx);\n"
|
|
323
|
+
" if (r) {\n"
|
|
324
|
+
" js_std_dump_error(ctx);\n"
|
|
325
|
+
" }\n"
|
|
326
|
+
" js_std_free_handlers(rt);\n"
|
|
327
|
+
" JS_FreeContext(ctx);\n"
|
|
328
|
+
" JS_FreeRuntime(rt);\n"
|
|
329
|
+
" return r;\n"
|
|
330
|
+
"}\n";
|
|
331
|
+
|
|
332
|
+
#define PROG_NAME "qjsc"
|
|
333
|
+
|
|
334
|
+
void help(void)
|
|
335
|
+
{
|
|
336
|
+
printf("QuickJS-ng Compiler version %s\n"
|
|
337
|
+
"usage: " PROG_NAME " [options] [files]\n"
|
|
338
|
+
"\n"
|
|
339
|
+
"options are:\n"
|
|
340
|
+
"-b output raw bytecode instead of C code\n"
|
|
341
|
+
"-e output main() and bytecode in a C file\n"
|
|
342
|
+
"-o output set the output filename\n"
|
|
343
|
+
"-n script_name set the script name (as used in stack traces)\n"
|
|
344
|
+
"-N cname set the C name of the generated data\n"
|
|
345
|
+
"-C compile as JS classic script (default=autodetect)\n"
|
|
346
|
+
"-m compile as ES module (default=autodetect)\n"
|
|
347
|
+
"-D module_name compile a dynamically loaded module or worker\n"
|
|
348
|
+
"-M module_name[,cname] add initialization code for an external C module\n"
|
|
349
|
+
"-p prefix set the prefix of the generated C names\n"
|
|
350
|
+
"-P do not add default system modules\n"
|
|
351
|
+
"-s strip the source code, specify twice to also strip debug info\n"
|
|
352
|
+
"-S n set the maximum stack size to 'n' bytes (default=%d)\n",
|
|
353
|
+
JS_GetVersion(),
|
|
354
|
+
JS_DEFAULT_STACK_SIZE);
|
|
355
|
+
exit(1);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// TODO(bnoordhuis) share with qjs.c maybe
|
|
359
|
+
static int64_t parse_limit(const char *arg) {
|
|
360
|
+
char *p;
|
|
361
|
+
unsigned long unit = 1; // bytes for backcompat; qjs defaults to kilobytes
|
|
362
|
+
double d = strtod(arg, &p);
|
|
363
|
+
|
|
364
|
+
if (p == arg) {
|
|
365
|
+
fprintf(stderr, "qjsc: invalid limit: %s\n", arg);
|
|
366
|
+
return -1;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if (*p) {
|
|
370
|
+
switch (*p++) {
|
|
371
|
+
case 'b': case 'B': unit = 1UL << 0; break;
|
|
372
|
+
case 'k': case 'K': unit = 1UL << 10; break; /* IEC kibibytes */
|
|
373
|
+
case 'm': case 'M': unit = 1UL << 20; break; /* IEC mebibytes */
|
|
374
|
+
case 'g': case 'G': unit = 1UL << 30; break; /* IEC gigibytes */
|
|
375
|
+
default:
|
|
376
|
+
fprintf(stderr, "qjsc: invalid limit: %s, unrecognized suffix, only k,m,g are allowed\n", arg);
|
|
377
|
+
return -1;
|
|
378
|
+
}
|
|
379
|
+
if (*p) {
|
|
380
|
+
fprintf(stderr, "qjsc: invalid limit: %s, only one suffix allowed\n", arg);
|
|
381
|
+
return -1;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
return (int64_t)(d * unit);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
static void check_hasarg(int optind, int argc, int opt)
|
|
389
|
+
{
|
|
390
|
+
if (optind >= argc) {
|
|
391
|
+
fprintf(stderr, "qjsc: missing file for -%c\n", opt);
|
|
392
|
+
exit(1);
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
int main(int argc, char **argv)
|
|
397
|
+
{
|
|
398
|
+
int optind = 1;
|
|
399
|
+
int i;
|
|
400
|
+
const char *out_filename, *cname, *script_name;
|
|
401
|
+
char cfilename[1024];
|
|
402
|
+
FILE *fo;
|
|
403
|
+
JSRuntime *rt;
|
|
404
|
+
JSContext *ctx;
|
|
405
|
+
int module;
|
|
406
|
+
size_t stack_size;
|
|
407
|
+
namelist_t dynamic_module_list;
|
|
408
|
+
bool load_system_modules = true;
|
|
409
|
+
|
|
410
|
+
out_filename = NULL;
|
|
411
|
+
script_name = NULL;
|
|
412
|
+
output_type = OUTPUT_C;
|
|
413
|
+
cname = NULL;
|
|
414
|
+
module = -1;
|
|
415
|
+
strip = 0;
|
|
416
|
+
stack_size = 0;
|
|
417
|
+
memset(&dynamic_module_list, 0, sizeof(dynamic_module_list));
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
while (optind < argc && *argv[optind] == '-') {
|
|
421
|
+
char *arg = argv[optind] + 1;
|
|
422
|
+
char *longopt = "";
|
|
423
|
+
char *optarg = NULL;
|
|
424
|
+
/* a single - is not an option, it also stops argument scanning */
|
|
425
|
+
if (!*arg)
|
|
426
|
+
break;
|
|
427
|
+
optind++;
|
|
428
|
+
if (*arg == '-') {
|
|
429
|
+
longopt = arg + 1;
|
|
430
|
+
optarg = strchr(longopt, '=');
|
|
431
|
+
if (optarg)
|
|
432
|
+
*optarg++ = '\0';
|
|
433
|
+
arg += strlen(arg);
|
|
434
|
+
/* -- stops argument scanning */
|
|
435
|
+
if (!*longopt)
|
|
436
|
+
break;
|
|
437
|
+
}
|
|
438
|
+
for (; *arg || *longopt; longopt = "") {
|
|
439
|
+
char opt = *arg;
|
|
440
|
+
if (opt) {
|
|
441
|
+
arg++;
|
|
442
|
+
if (!optarg && *arg)
|
|
443
|
+
optarg = arg;
|
|
444
|
+
}
|
|
445
|
+
if (opt == 'h' || opt == '?' || !strcmp(longopt, "help")) {
|
|
446
|
+
help();
|
|
447
|
+
continue;
|
|
448
|
+
}
|
|
449
|
+
if (opt == 'b') {
|
|
450
|
+
output_type = OUTPUT_RAW;
|
|
451
|
+
continue;
|
|
452
|
+
}
|
|
453
|
+
if (opt == 'o') {
|
|
454
|
+
if (!optarg) {
|
|
455
|
+
check_hasarg(optind, argc, opt);
|
|
456
|
+
optarg = argv[optind++];
|
|
457
|
+
}
|
|
458
|
+
out_filename = optarg;
|
|
459
|
+
continue;
|
|
460
|
+
}
|
|
461
|
+
if (opt == 'e') {
|
|
462
|
+
output_type = OUTPUT_C_MAIN;
|
|
463
|
+
continue;
|
|
464
|
+
}
|
|
465
|
+
if (opt == 'n') {
|
|
466
|
+
if (!optarg) {
|
|
467
|
+
check_hasarg(optind, argc, opt);
|
|
468
|
+
optarg = argv[optind++];
|
|
469
|
+
}
|
|
470
|
+
script_name = optarg;
|
|
471
|
+
continue;
|
|
472
|
+
}
|
|
473
|
+
if (opt == 'N') {
|
|
474
|
+
if (!optarg) {
|
|
475
|
+
check_hasarg(optind, argc, opt);
|
|
476
|
+
optarg = argv[optind++];
|
|
477
|
+
}
|
|
478
|
+
cname = optarg;
|
|
479
|
+
continue;
|
|
480
|
+
}
|
|
481
|
+
if (opt == 'C') {
|
|
482
|
+
module = 0;
|
|
483
|
+
continue;
|
|
484
|
+
}
|
|
485
|
+
if (opt == 'm') {
|
|
486
|
+
module = 1;
|
|
487
|
+
continue;
|
|
488
|
+
}
|
|
489
|
+
if (opt == 'M') {
|
|
490
|
+
char *p;
|
|
491
|
+
char path[1024];
|
|
492
|
+
char cname[1024];
|
|
493
|
+
if (!optarg) {
|
|
494
|
+
check_hasarg(optind, argc, opt);
|
|
495
|
+
optarg = argv[optind++];
|
|
496
|
+
}
|
|
497
|
+
js__pstrcpy(path, sizeof(path), optarg);
|
|
498
|
+
p = strchr(path, ',');
|
|
499
|
+
if (p) {
|
|
500
|
+
*p = '\0';
|
|
501
|
+
js__pstrcpy(cname, sizeof(cname), p + 1);
|
|
502
|
+
} else {
|
|
503
|
+
get_c_name(cname, sizeof(cname), path);
|
|
504
|
+
}
|
|
505
|
+
namelist_add(&cmodule_list, path, cname, 0);
|
|
506
|
+
continue;
|
|
507
|
+
}
|
|
508
|
+
if (opt == 'D') {
|
|
509
|
+
if (!optarg) {
|
|
510
|
+
check_hasarg(optind, argc, opt);
|
|
511
|
+
optarg = argv[optind++];
|
|
512
|
+
}
|
|
513
|
+
namelist_add(&dynamic_module_list, optarg, NULL, 0);
|
|
514
|
+
continue;
|
|
515
|
+
}
|
|
516
|
+
if (opt == 'P') {
|
|
517
|
+
load_system_modules = false;
|
|
518
|
+
continue;
|
|
519
|
+
}
|
|
520
|
+
if (opt == 's') {
|
|
521
|
+
strip++;
|
|
522
|
+
continue;
|
|
523
|
+
}
|
|
524
|
+
if (opt == 'p') {
|
|
525
|
+
if (!optarg) {
|
|
526
|
+
check_hasarg(optind, argc, opt);
|
|
527
|
+
optarg = argv[optind++];
|
|
528
|
+
}
|
|
529
|
+
c_ident_prefix = optarg;
|
|
530
|
+
continue;
|
|
531
|
+
}
|
|
532
|
+
if (opt == 'S') {
|
|
533
|
+
if (!optarg) {
|
|
534
|
+
check_hasarg(optind, argc, opt);
|
|
535
|
+
optarg = argv[optind++];
|
|
536
|
+
}
|
|
537
|
+
stack_size = parse_limit(optarg);
|
|
538
|
+
continue;
|
|
539
|
+
}
|
|
540
|
+
help();
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
if (load_system_modules) {
|
|
545
|
+
/* add system modules */
|
|
546
|
+
namelist_add(&cmodule_list, "qjs:std", "std", 0);
|
|
547
|
+
namelist_add(&cmodule_list, "qjs:os", "os", 0);
|
|
548
|
+
namelist_add(&cmodule_list, "qjs:bjson", "bjson", 0);
|
|
549
|
+
namelist_add(&cmodule_list, "std", "std", 0);
|
|
550
|
+
namelist_add(&cmodule_list, "os", "os", 0);
|
|
551
|
+
namelist_add(&cmodule_list, "bjson", "bjson", 0);
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
if (optind >= argc)
|
|
555
|
+
help();
|
|
556
|
+
|
|
557
|
+
if (!out_filename)
|
|
558
|
+
out_filename = "out.c";
|
|
559
|
+
|
|
560
|
+
js__pstrcpy(cfilename, sizeof(cfilename), out_filename);
|
|
561
|
+
|
|
562
|
+
if (output_type == OUTPUT_RAW)
|
|
563
|
+
fo = fopen(cfilename, "wb");
|
|
564
|
+
else
|
|
565
|
+
fo = fopen(cfilename, "w");
|
|
566
|
+
|
|
567
|
+
if (!fo) {
|
|
568
|
+
perror(cfilename);
|
|
569
|
+
exit(1);
|
|
570
|
+
}
|
|
571
|
+
outfile = fo;
|
|
572
|
+
|
|
573
|
+
rt = JS_NewRuntime();
|
|
574
|
+
ctx = JS_NewContext(rt);
|
|
575
|
+
|
|
576
|
+
/* loader for ES6 modules */
|
|
577
|
+
JS_SetModuleLoaderFunc(rt, NULL, jsc_module_loader, NULL);
|
|
578
|
+
|
|
579
|
+
if (output_type != OUTPUT_RAW) {
|
|
580
|
+
fprintf(fo, "/* File generated automatically by the QuickJS-ng compiler. */\n"
|
|
581
|
+
"\n"
|
|
582
|
+
);
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
if (output_type == OUTPUT_C_MAIN) {
|
|
586
|
+
fprintf(fo, "#include \"quickjs-libc.h\"\n"
|
|
587
|
+
"\n"
|
|
588
|
+
);
|
|
589
|
+
} else if (output_type == OUTPUT_C) {
|
|
590
|
+
fprintf(fo, "#include <inttypes.h>\n"
|
|
591
|
+
"\n"
|
|
592
|
+
);
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
for(i = optind; i < argc; i++) {
|
|
596
|
+
const char *filename = argv[i];
|
|
597
|
+
compile_file(ctx, fo, filename, script_name, cname, module);
|
|
598
|
+
cname = NULL;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
for(i = 0; i < dynamic_module_list.count; i++) {
|
|
602
|
+
if (!jsc_module_loader(ctx, dynamic_module_list.array[i].name, NULL)) {
|
|
603
|
+
fprintf(stderr, "Could not load dynamic module '%s'\n",
|
|
604
|
+
dynamic_module_list.array[i].name);
|
|
605
|
+
exit(1);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
if (output_type == OUTPUT_C_MAIN) {
|
|
610
|
+
fprintf(fo,
|
|
611
|
+
"static JSContext *JS_NewCustomContext(JSRuntime *rt)\n"
|
|
612
|
+
"{\n"
|
|
613
|
+
" JSContext *ctx = JS_NewContext(rt);\n"
|
|
614
|
+
" if (!ctx)\n"
|
|
615
|
+
" return NULL;\n");
|
|
616
|
+
/* add the precompiled modules (XXX: could modify the module
|
|
617
|
+
loader instead) */
|
|
618
|
+
for(i = 0; i < init_module_list.count; i++) {
|
|
619
|
+
namelist_entry_t *e = &init_module_list.array[i];
|
|
620
|
+
/* initialize the static C modules */
|
|
621
|
+
|
|
622
|
+
fprintf(fo,
|
|
623
|
+
" {\n"
|
|
624
|
+
" extern JSModuleDef *js_init_module_%s(JSContext *ctx, const char *name);\n"
|
|
625
|
+
" js_init_module_%s(ctx, \"%s\");\n"
|
|
626
|
+
" }\n",
|
|
627
|
+
e->short_name, e->short_name, e->name);
|
|
628
|
+
}
|
|
629
|
+
for(i = 0; i < cname_list.count; i++) {
|
|
630
|
+
namelist_entry_t *e = &cname_list.array[i];
|
|
631
|
+
if (e->flags) {
|
|
632
|
+
fprintf(fo, " js_std_eval_binary(ctx, %s, %s_size, 1);\n",
|
|
633
|
+
e->name, e->name);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
fprintf(fo,
|
|
637
|
+
" return ctx;\n"
|
|
638
|
+
"}\n\n");
|
|
639
|
+
|
|
640
|
+
fputs(main_c_template1, fo);
|
|
641
|
+
|
|
642
|
+
if (stack_size != 0) {
|
|
643
|
+
fprintf(fo, " JS_SetMaxStackSize(rt, %u);\n",
|
|
644
|
+
(unsigned int)stack_size);
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
/* add the module loader */
|
|
648
|
+
fprintf(fo, " JS_SetModuleLoaderFunc2(rt, NULL, js_module_loader, js_module_check_attributes, NULL);\n");
|
|
649
|
+
|
|
650
|
+
fprintf(fo,
|
|
651
|
+
" ctx = JS_NewCustomContext(rt);\n"
|
|
652
|
+
" js_std_add_helpers(ctx, argc, argv);\n");
|
|
653
|
+
|
|
654
|
+
for(i = 0; i < cname_list.count; i++) {
|
|
655
|
+
namelist_entry_t *e = &cname_list.array[i];
|
|
656
|
+
if (!e->flags) {
|
|
657
|
+
fprintf(fo, " js_std_eval_binary(ctx, %s, %s_size, 0);\n",
|
|
658
|
+
e->name, e->name);
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
fputs(main_c_template2, fo);
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
JS_FreeContext(ctx);
|
|
665
|
+
JS_FreeRuntime(rt);
|
|
666
|
+
|
|
667
|
+
fclose(fo);
|
|
668
|
+
|
|
669
|
+
namelist_free(&cname_list);
|
|
670
|
+
namelist_free(&cmodule_list);
|
|
671
|
+
namelist_free(&init_module_list);
|
|
672
|
+
return 0;
|
|
673
|
+
}
|