How sharad420/lox works
This repository contains two implementations of the Lox language: jLox, a tree-walk interpreter, and cLox, a bytecode compiler and virtual machine. In jLox, users provide a script or REPL input, which Lox scans, parses, resolves, and interprets; the interpreter supports functions, lambdas, classes, and instances. cLox compiles source to bytecode for VM execution. The graph preserves both runtimes and their major internal stages; some cLox relationships are based on the source index because those source excerpts were not provided.
Main entry points: vm.c Virtual machine · Interpreter.java Tree-walk interpreter · Lox.java CLI and pipeline · Parser.java Parser
Components 24
jLox Front End
- CLI and pipeline
jLox/src/main/java/com/craftinginterpreters/lox/Lox.java - Scanner
jLox/src/main/java/com/craftinginterpreters/lox/Scanner.java - Tokens
jLox/src/main/java/com/craftinginterpreters/lox/Token.java - Parser
jLox/src/main/java/com/craftinginterpreters/lox/Parser.java - AST nodes
jLox/src/main/java/com/craftinginterpreters/lox/Expr.java - Statements
jLox/src/main/java/com/craftinginterpreters/lox/Stmt.java - Static resolver
jLox/src/main/java/com/craftinginterpreters/lox/Resolver.java - AST printer
jLox/src/main/java/com/craftinginterpreters/lox/AstPrinter.java
jLox Runtime
- Tree-walk interpreter
jLox/src/main/java/com/craftinginterpreters/lox/Interpreter.java - Lexical environments
jLox/src/main/java/com/craftinginterpreters/lox/Environment.java - Functions and lambdas
jLox/src/main/java/com/craftinginterpreters/lox/LoxFunction.java - Classes and instances
jLox/src/main/java/com/craftinginterpreters/lox/LoxClass.java - Native input / files
jLox/src/main/java/com/craftinginterpreters/lox/Interpreter.java
cLox Compilation
- CLI entry
cLox/main.c - Scanner
cLox/scanner.c - Bytecode compiler
cLox/compiler.c - Bytecode chunks
cLox/chunk.h - Bytecode disassembly
cLox/debug.c
cLox Runtime
- Virtual machine
cLox/vm.c - Runtime objects
cLox/object.c - Values
cLox/value.c - Hash tables
cLox/table.c - Memory management
cLox/memory.c
Other components
- Script / REPL user
Connections 26
- Script / REPL user → CLI and pipeline: runs input
jLox/src/main/java/com/craftinginterpreters/lox/Lox.java - CLI and pipeline → Scanner: scans source
jLox/src/main/java/com/craftinginterpreters/lox/Lox.java - Scanner → Tokens: produces tokens
jLox/src/main/java/com/craftinginterpreters/lox/Scanner.java - CLI and pipeline → Parser: parses tokens
jLox/src/main/java/com/craftinginterpreters/lox/Lox.java - Parser → AST nodes: builds expressions
jLox/src/main/java/com/craftinginterpreters/lox/Parser.java - Parser → Statements: builds statements
jLox/src/main/java/com/craftinginterpreters/lox/Parser.java - CLI and pipeline → Static resolver: resolves scopes
jLox/src/main/java/com/craftinginterpreters/lox/Lox.java - CLI and pipeline → Tree-walk interpreter: executes statements
jLox/src/main/java/com/craftinginterpreters/lox/Lox.java - Static resolver → Tree-walk interpreter: records scope depths
jLox/src/main/java/com/craftinginterpreters/lox/Resolver.java - Tree-walk interpreter → Lexical environments: reads and assigns
jLox/src/main/java/com/craftinginterpreters/lox/Interpreter.java - Tree-walk interpreter → Functions and lambdas: creates functions
jLox/src/main/java/com/craftinginterpreters/lox/Interpreter.java - Tree-walk interpreter → Classes and instances: creates classes
jLox/src/main/java/com/craftinginterpreters/lox/Interpreter.java - Tree-walk interpreter → Native input / files: provides built-ins
jLox/src/main/java/com/craftinginterpreters/lox/Interpreter.java - AST printer → AST nodes: visits expressions
jLox/src/main/java/com/craftinginterpreters/lox/AstPrinter.java - CLI entry → Virtual machine: invokes runtime
cLox/main.c - Virtual machine → Bytecode compiler: compiles source
cLox/vm.c - Bytecode compiler → Scanner: scans source
cLox/compiler.c - Bytecode compiler → Bytecode chunks: writes bytecode
cLox/compiler.c - Virtual machine → Bytecode chunks: executes bytecode
cLox/vm.c - Bytecode disassembly → Bytecode chunks: disassembles bytecode
cLox/debug.c - Virtual machine → Runtime objects: creates runtime objects
cLox/vm.c - Virtual machine → Hash tables: uses tables
cLox/vm.c - Virtual machine → Values: operates on values
cLox/vm.c - Memory management → Runtime objects: allocates objects
cLox/memory.c - Memory management → Virtual machine: manages VM memory
cLox/memory.c - Hash tables → Values: stores values
cLox/table.c