How ak47andrew/bee_hive works
Purpose and Runtime
BEE_HIVE is a Rust command-line compiler. It reads Bee (.bee) source programs and emits NJ, a Brainfuck-like target language, to stdout. The binary is built and distributed through Cargo/crates.io and release artifacts; it is not a web service. Primary entry points are src/main.rs and src/cli.rs.
CLI Boundary
src/main.rs initializes the executable and delegates command handling. src/cli.rs owns the user-facing contract: source-path input plus an optional debug mode. The CLI is the boundary between filesystem input and compiler output, allowing shell redirection such as hive code.bee > output.nj.
Translation Orchestrator
src/translator/mod.rs is the compiler subsystem façade and likely coordinates the translation pipeline. Its responsibility is to move source text through lexical analysis, intermediate representation construction, lowering/code generation, and final cleanup while surfacing compilation/debug information back to the CLI.
Front End: Tokens and Source Semantics
src/translator/tokenizer.rs converts Bee source into tokens for supported language constructs: integer variables, string output, integer printing, and input. src/translator/compiler.rs consumes that representation and compiles Bee statements into target-oriented operations. This is the key language boundary: Bee syntax and semantics are separated from NJ emission.
Intermediate Representation and Lowering
src/translator/intermediate_language.rs defines the compiler’s internal instruction layer between Bee parsing/compilation and textual NJ. It centralizes target operations such as pointer movement, immediate loads, variable storage/loading, and output. src/translator/compiler.rs produces this representation; downstream stages serialize/lower it to NJ-like code.
Stateful Target Concerns
src/translator/memory_manager.rs manages the Brainfuck-style tape model: variable-to-cell allocation and pointer/cell bookkeeping. It is architecturally necessary because generated NJ instructions depend on stable memory locations and explicit pointer positioning. src/translator/func_call.rs handles compilation of built-in language actions such as output and input, translating higher-level calls into the required intermediate/target sequences.
Output Finalization and Delivery
src/translator/cleanup.rs performs final output cleanup, likely removing or normalizing redundant generated instructions before NJ text is returned to stdout. src/translator/intermediate_language.rs and src/translator/cleanup.rs form the last compiler boundary before emitted code. Release packaging is automated by .github/workflows/release.yml; no external runtime service is required beyond the local Rust executable and source file.
Main entry points: compiler.rs Bee compiler · mod.rs Translator façade · intermediate_language.rs Intermediate language · cli.rs Command handling
Components 13
CLI executable
- Bee source (.bee) · User-provided program file.
- Executable entry
src/main.rs - Command handling · Accepts a source path and optional debug mode.
src/cli.rs - NJ code · Emitted to standard output for shell redirection.
Bee front end
- Tokenizer · Converts Bee source text into tokens.
src/translator/tokenizer.rs - Bee compiler · Compiles Bee statements into target-oriented operations.
src/translator/compiler.rs - Built-in calls · Lowers Bee input and output actions.
src/translator/func_call.rs
Translation pipeline
- Translator façade · Coordinates compilation and returns generated NJ.
src/translator/mod.rs - Tape memory manager · Tracks variable cells and target pointer position.
src/translator/memory_manager.rs - Intermediate language · Target operations for movement, loads, storage, and output.
src/translator/intermediate_language.rs - Output cleanup · Normalizes generated target instructions.
src/translator/cleanup.rs
Distribution
- Release workflow · Builds and publishes release artifacts.
.github/workflows/release.yml - Cargo and release artifacts · Delivers the Rust CLI through crates.io and releases.
Connections 15
- Bee source (.bee) → Command handling: source path
- Executable entry → Command handling: delegates
- Command handling → Translator façade: source text + debug
- Translator façade → Tokenizer: lexes
- Tokenizer → Bee compiler: tokens
- Bee compiler → Built-in calls: built-in actions
- Bee compiler → Tape memory manager: variables
- Tape memory manager → Intermediate language: cell locations
- Built-in calls → Intermediate language: lowered operations
- Bee compiler → Intermediate language: IR operations
- Intermediate language → Output cleanup: generated instructions
- Output cleanup → Translator façade: final NJ
- Translator façade → NJ code: writes stdout
- Release workflow → Cargo and release artifacts: builds and publishes
- Cargo and release artifacts → Executable entry: distributes binary