Skip to content

Commit 473e89e

Browse files
authored
Integrate WebAssembly counters and enhanced COCOMO estimates (#79)
- Compile SLOCCount C programs to WebAssembly using Emscripten v4.0.17 - c_count.wasm: Main C/C++/JavaScript/Java counter - php_count.wasm, ml_count.wasm, pig_count.wasm, lexcount1.wasm - Implement hybrid Perl + WASM counter routing - Perl scripts for Python, Ruby, Perl, SQL - WASM binaries for JavaScript, C, C++, Java, PHP - Uses original SLOCCount algorithms without modification - Add enhanced COCOMO cost estimation features - Year preset toggle: 2000 (original) vs 2025 (updated) - All COCOMO parameters now editable (effort coefficient, salary, overhead) - Prominent warning about estimate accuracy - Footnote links from cost displays to detailed explanation - Update documentation - Add WASM compilation process to lib/README.md - Include Emscripten build commands and configuration - Add comprehensive tests - Test COCOMO year preset switching - Test footnote link navigation - Test WASM JavaScript counter integration - All 18 tests passing This completes the integration of the original SLOCCount tool to run entirely in the browser via WebAssembly, supporting both Perl and C language counters. Claude Code transcript: https://gistpreview.github.io/?79ca231e801fe1188268a54d30aa67ed
1 parent 6113051 commit 473e89e

File tree

13 files changed

+24056
-173
lines changed

13 files changed

+24056
-173
lines changed

lib/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,59 @@ SLOCCount is licensed under the **GNU General Public License version 2** (GPL-2.
5353

5454
The zip file includes various language-specific counting scripts (e.g., `python_count`, `c_count`, `perl_count`) and supporting utilities.
5555

56+
### WebAssembly Compilation of C Programs
57+
58+
Many of the original SLOCCount language counters are C programs that need to be compiled. To run these in the browser, they have been compiled to WebAssembly using Emscripten.
59+
60+
**Compiled Programs** (in `lib/wasm/`):
61+
- `c_count.js` / `c_count.wasm` - Main C/C++/JavaScript/Java counter
62+
- `php_count.js` / `php_count.wasm` - PHP counter
63+
- `ml_count.js` / `ml_count.wasm` - ML/OCaml counter
64+
- `pig_count.js` / `pig_count.wasm` - Pig Latin counter
65+
- `lexcount1.js` / `lexcount1.wasm` - Lex counter
66+
67+
**Compilation Process:**
68+
69+
The C source files were extracted from the SLOCCount repository and compiled using Emscripten v4.0.17:
70+
71+
```bash
72+
# Extract C source files from the repository
73+
unzip -j lib/sloccount-perl.zip "*.c" -d sloccount-c/
74+
75+
# Compile each C program to WebAssembly
76+
cd sloccount-c
77+
emcc c_count.c -o c_count.js \
78+
-s WASM=1 \
79+
-s EXPORTED_RUNTIME_METHODS='["callMain","FS"]' \
80+
-s ALLOW_MEMORY_GROWTH=1 \
81+
-s FORCE_FILESYSTEM=1 \
82+
-s MODULARIZE=1 \
83+
-s EXPORT_NAME=createCCountModule
84+
85+
# Repeat for other C programs (php_count, ml_count, pig_count, lexcount1)
86+
```
87+
88+
**Configuration Options:**
89+
- `EXPORTED_RUNTIME_METHODS` - Allows calling main() and accessing the virtual filesystem
90+
- `ALLOW_MEMORY_GROWTH` - Enables dynamic memory allocation
91+
- `FORCE_FILESYSTEM` - Includes filesystem support for reading files
92+
- `MODULARIZE` - Creates a module factory function
93+
- `EXPORT_NAME` - Sets the module constructor name
94+
95+
The WASM modules are loaded dynamically and configured to:
96+
- Write input files to the virtual filesystem at `/tmp/`
97+
- Execute via `callMain()` with file paths as arguments
98+
- Capture output via custom print handlers
99+
- Disable stdin prompts to prevent browser dialogs
100+
101+
**Usage in Application:**
102+
103+
The main application detects file extensions and routes them to either:
104+
- **Perl counter scripts** (for Python, Ruby, Perl, SQL, etc.) - run via WebPerl eval
105+
- **WASM counters** (for JavaScript, C, C++, Java, PHP, etc.) - run via compiled binaries
106+
107+
This hybrid approach uses the original SLOCCount algorithms without modification, running both Perl and C programs entirely in the browser via WebAssembly.
108+
56109
---
57110

58111
## Attribution

0 commit comments

Comments
 (0)