From 0172a5ddb938eecc730e4e8942840f61657b83f3 Mon Sep 17 00:00:00 2001 From: David Fiala Date: Wed, 7 Jan 2026 17:26:52 -0800 Subject: [PATCH] cleanup unused and missing includes, add forward decls. generally makes current code happy with clangd as well as gcc. note that I did not add forward decls for the example stdlib as I did not see a clean way to do it. --- dtoa.c | 2 -- dtoa.h | 3 +++ example.c | 4 ---- example_stdlib.c | 1 - libm.c | 9 ++++----- libm.h | 2 ++ mqjs.c | 2 -- mquickjs.h | 1 + mquickjs_build.c | 12 ++++++++++-- readline.h | 2 +- readline_tty.c | 3 --- readline_tty.h | 2 ++ 12 files changed, 23 insertions(+), 20 deletions(-) diff --git a/dtoa.c b/dtoa.c index 604f3f0..a059f3e 100644 --- a/dtoa.c +++ b/dtoa.c @@ -27,10 +27,8 @@ #include #include #include -#include #include #include -#include #include "cutils.h" #include "dtoa.h" diff --git a/dtoa.h b/dtoa.h index 91b025b..cfed382 100644 --- a/dtoa.h +++ b/dtoa.h @@ -24,6 +24,9 @@ //#define JS_DTOA_DUMP_STATS +#include +#include + /* maximum number of digits for fixed and frac formats */ #define JS_DTOA_MAX_DIGITS 101 diff --git a/example.c b/example.c index 5385ede..6b8e845 100644 --- a/example.c +++ b/example.c @@ -22,20 +22,16 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include #include #include #include #include #include #include -#include #include #include -#include #include -#include "cutils.h" #include "mquickjs.h" #define JS_CLASS_RECTANGLE (JS_CLASS_USER + 0) diff --git a/example_stdlib.c b/example_stdlib.c index 82d4943..69dc145 100644 --- a/example_stdlib.c +++ b/example_stdlib.c @@ -1,4 +1,3 @@ -#include #include #include diff --git a/libm.c b/libm.c index bff8ed1..3416082 100644 --- a/libm.c +++ b/libm.c @@ -30,7 +30,6 @@ * is preserved. * ==================================================== */ -#include #include #include #define NDEBUG @@ -433,10 +432,10 @@ double js_scalbn(double x, int n) if (k > 0) /* normal result */ {x = set_high_word(x, (hx&0x800fffff)|(k<<20)); return x;} if (k <= -54) { - if (n > 50000) /* in case integer overflow in n+k */ - return huge*copysign(huge,x); /*overflow*/ - else - return tiny*copysign(tiny,x); /*underflow*/ + if (n > 50000) /* in case integer overflow in n+k */ + return huge * copysign(huge, x); /*overflow*/ + else + return tiny * copysign(tiny, x); /*underflow*/ } k += 54; /* subnormal result */ x = set_high_word(x, (hx&0x800fffff)|(k<<20)); diff --git a/libm.h b/libm.h index 17e94e0..981708c 100644 --- a/libm.h +++ b/libm.h @@ -21,6 +21,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ +#include + double js_scalbn(double x, int n); double js_floor(double x); double js_ceil(double x); diff --git a/mqjs.c b/mqjs.c index 46ad953..d61684e 100644 --- a/mqjs.c +++ b/mqjs.c @@ -22,7 +22,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include #include #include #include @@ -32,7 +31,6 @@ #include #include #include -#include #include #include "cutils.h" diff --git a/mquickjs.h b/mquickjs.h index a1557fe..fe8cdec 100644 --- a/mquickjs.h +++ b/mquickjs.h @@ -26,6 +26,7 @@ #define MQUICKJS_H #include +#include #if defined(__GNUC__) || defined(__clang__) #define __js_printf_like(f, a) __attribute__((format(printf, f, a))) diff --git a/mquickjs_build.c b/mquickjs_build.c index 6173271..b38ac22 100644 --- a/mquickjs_build.c +++ b/mquickjs_build.c @@ -28,8 +28,6 @@ #include #include #include -#include -#include #include "cutils.h" #include "list.h" @@ -897,6 +895,16 @@ int build_atoms(const char *stdlib_name, const JSPropDef *global_obj, printf("/* this file is automatically generated - do not edit */\n\n"); printf("#include \"mquickjs_priv.h\"\n\n"); + + printf("/* standard library functions expected to be provided by the host application */\n"); + printf("JSValue js_date_now(JSContext *ctx, JSValue *this_val, int argc, JSValue *argv);\n"); + printf("JSValue js_print(JSContext *ctx, JSValue *this_val, int argc, JSValue *argv);\n"); + printf("JSValue js_gc(JSContext *ctx, JSValue *this_val, int argc, JSValue *argv);\n"); + printf("JSValue js_date_now(JSContext *ctx, JSValue *this_val, int argc, JSValue *argv);\n"); + printf("JSValue js_performance_now(JSContext *ctx, JSValue *this_val, int argc, JSValue *argv);\n"); + printf("JSValue js_load(JSContext *ctx, JSValue *this_val, int argc, JSValue *argv);\n"); + printf("JSValue js_setTimeout(JSContext *ctx, JSValue *this_val, int argc, JSValue *argv);\n"); + printf("JSValue js_clearTimeout(JSContext *ctx, JSValue *this_val, int argc, JSValue *argv);\n\n"); printf("static const uint%u_t __attribute((aligned(%d))) js_stdlib_table[] = {\n", JSW * 8, ATOM_ALIGN); diff --git a/readline.h b/readline.h index 639750a..fd33b1e 100644 --- a/readline.h +++ b/readline.h @@ -24,7 +24,7 @@ #ifndef READLINE_H #define READLINE_H -#include "cutils.h" +#include typedef struct ReadlineState ReadlineState; diff --git a/readline_tty.c b/readline_tty.c index 9a7e929..6c00da8 100644 --- a/readline_tty.c +++ b/readline_tty.c @@ -21,17 +21,14 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -#include #include #include #include #include #include #include -#include #include #include -#include #include #ifdef _WIN32 #include diff --git a/readline_tty.h b/readline_tty.h index 7ef33cb..be48bc4 100644 --- a/readline_tty.h +++ b/readline_tty.h @@ -21,6 +21,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + +#include "cutils.h" #include "readline.h" int readline_tty_init(void);