How noreplydev/ego works
Main Components
• Command-Line Interface (CLI) Module:
• Located in src/commands (e.g. new.rs, run.rs, logo.rs).
• Acts as the entry point when executing “ego” commands.
• Lexer & Parser:
• Found in src/ast (lexer.rs, parser.rs, and the nodes directory under src/ast/nodes).
• The lexer processes the source code into tokens using defined lexer types.
• The parser then consumes these tokens to build an Abstract Syntax Tree (AST) from the different nodes (e.g. binary_expression, function_declaration, if_statement, etc.)
• AST and Semantic Analysis:
• The AST, represented through a variety of node types in src/ast/nodes, forms the structural foundation of the source code.
• Compiler:
• Resides in src/compiler (including bytecode.rs and associated handlers).
• Converts the AST into an intermediate representation (bytecode) and applies handlers for operations such as printing.
• Core Functionality:
• Located in src/core, this includes error handling (error module), runtime types (runtypes), logs, and type handling.
• The "runtypes" submodule (with types such as number, string, boolean, vector, nothing, and trait definitions) encapsulates the types used during execution.
• Runtime (Interpreter):
• Found in src/runtime, particularly in interpreter.rs and scope.rs.
• This part executes the code (or bytecode) using the dynamically built scope and runtime values.
• Optional WASM Integration:
• The presence of src/wasm.rs suggests an alternate runtime or compilation target (possibly for WebAssembly execution).
• Supporting Files & Build Tools:
• Cargo.toml, Cargo.lock are used for managing dependencies and builds.
• Documentation (docs folder) and examples (examples folder) assist with development and usage.
Relationships and Interactions
• User Interaction:
• The process begins with a developer using the CLI to create or run a project (e.g., “ego new” or “ego run”) which routes into the commands module.
• Source Code Processing:
• The CLI sends source code to the interpreter.
• The Lexer processes the code, converting it to a stream of tokens.
• The Parser takes these tokens and builds an AST using the nodes defined under src/ast/nodes.
• Code Transformation:
• From the AST, the Compiler module translates the structure into bytecode or another intermediate representation.
• The compilation process involves various handlers (like print.rs in the compiler/handlers directory) to process specific constructs.
• Execution:
• The Interpreter in the Runtime module executes the generated bytecode/intermediate form in a managed scope.
• The Core module plays a role here by managing types, errors, and logging.
• Alternative Execution Paths:
• When using the “-vm” flag, there might be alternative execution or a self-contained virtual machine path.
• WASM integration is available though likely experimental and optional.
Architectural Patterns and Key Technologies
• Pipeline Pattern for Language Processing:
• The processing pipeline is clearly split into multiple stages (Lexer → Parser → AST → Compiler → Interpreter).
• Modularity and Separation of Concerns:
• Directories like ast, compiler, core, and runtime show a clear separation between different functionalities.
• Error Handling and Logging:
• The core/error and core/logs modules indicate that runtime robustness and debugging are important.
• CLI-Driven Workflow:
• The commands module is designed to encapsulate various user actions, showing an architecture around command routing.