Skip to content

zinzilulo/BashC

Repository files navigation

BashC

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.

Status

This is an experimental project and comes with no warranty or support.

How it works

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.

Limitations

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.

Building

Bootstrap nob:

gcc nob.c -o nob

Build all targets:

./nob build

Note: 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.bash

Help message:

./nob

Testing

./nob test +autocompile \
  tests/basic.bash \
  tests/by-category/*.bash \
  tests/general/*.bash

Acknowledgements

This 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:

Licensing

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.

About

An interpreter for a Bash-like language.

Resources

License

GPL-3.0, MIT licenses found

Licenses found

GPL-3.0
LICENSE-GPL3
MIT
LICENSE-MIT

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors