BashC is an interpreter for a Bash-like language with a hot-loop JIT for integer arithmetic.
To see what it can do, check out the example programs in the tests/ directories. There is also a Game of Life simulation script that can be run using either BashC or a standard Bash interpreter.
This is an experimental project and comes with no warranty or support.
Bash scripts are parsed using tree-sitter, compiled into block-based bytecode, and executed by the interpreter.
All values (including arrays) are deep-copied. Registers, temporaries, and constants are stored in heap-allocated dynamic arrays.
For performance, the interpreter detects hot integer loops and attempts to JIT-compile them. There is no specialization based on operand types; execution still follows interpreter semantics. The main benefit is reduced dispatch overhead, which turns out to be significant in tight loops.
BashC does not support executing external commands, and several bugs are still expected.
String expansion is only partially implemented, so some printf and echo tests may fail. It should not be expected to behave like a full Bash implementation.
The project was implemented in roughly one week.
Bootstrap nob:
gcc nob.c -o nobBuild all targets:
./nob buildNote: Building works best on Linux using the provided Nix development shell. The build script assumes a specific setup that may not be available elsewhere. You may need to adjust your environment to match the assumptions in
nob.c.
Build and run a target:
./nob run bashc -- tests/gol.bashHelp message:
./nob./nob test +autocompile \
tests/basic.bash \
tests/by-category/*.bash \
tests/general/*.bashThis project was submitted as an extension to the C final project for the 40009 module, and was jointly developed with Deyang Cao, Sapol Sukpraprut, and Zhengqi Yang. The author wishes to remain anonymous. Permission to publish the source code has been obtained from the other contributors.
This project uses:
- nob.h by Alexey Kutepov (MIT)
- stb by Sean Barrett (MIT)
- libgccjit (GPLv3)
- tree-sitter and tree-sitter-bash (MIT)
The source code in this repository is dual-licensed under MIT and GPLv3. You may choose either license when using or redistributing it.
This applies only to the code in this repository and does not extend to third-party dependencies or build outputs.