From 506ba35e8bf7a4263d823cb46397647b1f4d7e65 Mon Sep 17 00:00:00 2001 From: Leorize Date: Thu, 11 Jul 2024 17:36:50 -0500 Subject: [PATCH] scanner: disable printing for WASM WASM builds does not expose symbols for printing. As such, settle for simply crashing. Also add WASM build step to CI to verify that it can be built. --- .github/workflows/ci.yml | 22 ++++++++++++++++++++++ .gitignore | 1 + src/scanner.c | 22 +++++++++++++++------- 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0315c84..253d623 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -93,12 +93,34 @@ jobs: with: command: build + wasm: + needs: [generate] + runs-on: ubuntu-latest + name: Run WASM test build + steps: + - uses: actions/checkout@v4 + - name: Download generated parser + uses: actions/download-artifact@v4 + with: + name: parser + path: src/ + - name: Setup NodeJS + uses: actions/setup-node@v4 + with: + cache: "npm" + node-version: "20" + - name: Install dependencies + run: npm ci + - name: Run test build + run: npx tree-sitter build --wasm + success: needs: - compare-parser - generate - tests - rust + - wasm if: always() runs-on: ubuntu-latest name: "All checks passed" diff --git a/.gitignore b/.gitignore index 44d832c..2a18333 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ target/ *.so *.pc *.a +*.wasm diff --git a/src/scanner.c b/src/scanner.c index fd32197..3a3d9b0 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -47,13 +47,21 @@ static bool debug_mode = false; /* NOLINT(*-global-variables) */ static const bool debug_mode = false; #endif -#define RUNTIME_ASSERT(cond) \ - if (!(cond)) { \ - (void)fprintf( \ - stderr, "lex_nim: %s():%d: Assertion `%s' failed.\n", __func__, \ - __LINE__, #cond); \ - abort(); \ - } +#ifndef __wasm__ +# define RUNTIME_ASSERT(cond) \ + if (!(cond)) { \ + (void)fprintf( \ + stderr, "lex_nim: %s():%d: Assertion `%s' failed.\n", __func__, \ + __LINE__, #cond); \ + abort(); \ + } +#else +// WASM doesn't have printing enabled +# define RUNTIME_ASSERT(cond) \ + if (!(cond)) { \ + abort(); \ + } +#endif #define MIN(left, right) ((left) > (right) ? (right) : (left)) #define MAX(left, right) ((left) < (right) ? (right) : (left))