$ show marcobambini/gravity
Gravity is an embeddable, dynamically typed scripting language written in portable C99 with no external dependencies beyond the C standard library. The repository implements a full language toolchain: a multi-pass compiler (lexer, Pratt parser, AST, IR, optimizer, bytecode codegen) and a register-based virtual machine with mark-and-sweep garbage collection. It provides a CLI (`gravity` executable) for running scripts and a well-defined C embedding API. The architecture is modular, with clear separation between compiler (`src/compiler`), runtime (`src/runtime`), shared utilities (`src/shared`), and optional modules (Math, File, JSON, ENV). The codebase is extensively tested with unit tests (embedded `#unittest` blocks) and a large fuzzing corpus for crash resistance. Despite some monolithic files (`gravity_core.c` >4000 lines) and heavy macro usage, the implementation demonstrates strong software engineering craftsmanship, especially in the hash table, dynamic array macros, and Pratt parser. The project appears to be under active maintenance (last commit 2026-08-05, 34 open issues, 4.5k stars) but shows some technical drift such as outdated CI configurations, platform-specific ifdefs, and a fuzz corpus from 2017.
The LLM identified 3 files worth highlighting for reuse:
A generic, callback-driven hash table implementation with custom hash, compare, and free functions. Used throughout the compiler and runtime for symbol tables, class members, and maps. It is self-contained, requires only standard C types, and can be extracted into any C project needing a hash table. Demonstrates careful handling of resizing, collision resolution, and iteration safety.
A set of C macros (`marray_*`) that implement type-safe dynamic arrays in pure C. Supports append, pop, insert, remove, sort, and iteration. The macros generate inline functions for a given element type, ensuring type safety without void pointers. This pattern is reusable across any C project that needs resizable arrays without external dependencies. The implementation is compact and production-tested.
A JSON serializer and deserializer that uses a visitor pattern to walk runtime objects. While it is coupled to Gravity's value types (`gravity_value_t`) and memory manager, the core logic for JSON tokenization, parsing, and string generation is cleanly separated and could be adapted to other object models. It includes two-pass parsing, unicode escape handling, and bounds-checked allocation. This file demonstrates robust handling of edge cases and memory safety.