How pannagaperumal/moxy works
1. What this repo is
- Moxy is a pure-Go scripting language runtime for embedding in Go applications.
- The core architecture is a classic language toolchain: source text → lexer → parser → AST → compiler → bytecode VM, with a separate tree-walk evaluator also present.
2. Primary entry points
- cmd/moxy/main.go is the CLI entry point for running .pb scripts.
- internal/repl/repl.go provides an interactive shell for manual execution.
- The root-level moxy.go and moxy/ artifacts suggest a public embedding surface for Go host applications.
3. Frontend: turning text into a program
- internal/token defines the language’s token types.
- internal/lexer converts raw source into tokens.
- internal/parser builds the program structure, with separate files for expressions, statements, literals, and helpers.
- The ast/ package holds the parsed syntax tree nodes, including special forms like for statements, hash literals, and index expressions.
4. Language model and syntax coverage
- The AST and parser structure indicate support for variables, functions, conditionals, loops, arrays/maps, indexing, and literals.
- The examples and docs show the language is designed around Go-like syntax and 0-based indexing.
5. Compiler path
- internal/compiler translates AST into bytecode.
- internal/code defines the bytecode instruction set and encoding.
- internal/compiler/symbol_table.go handles name resolution for locals, globals, and likely built-in symbols during compilation.
6. Virtual machine runtime
- internal/vm executes compiled bytecode.
- Key runtime pieces are separated into frames, stack, opcode definitions, and operations, which is a typical stack-based VM design.
- This layer is the main high-performance execution path highlighted in the README.
7. Runtime object system
- types/ defines the runtime values the VM and evaluator work with: objects, hashes, closures, compiled functions, and builtins.
- This package is the shared boundary between the language runtime and host-facing values.
8. Alternative interpreter path
- internal/evaluator implements direct AST execution.
- It has separate files for expressions, statements, builtins, and helpers, implying a tree-walking mode used for simpler execution, testing, or debugging alongside the VM pipeline.
9. Embedding and sandbox boundary
- Moxy is intended to be embedded into a Go host, so the key boundary is between host application code and script-exposed runtime values/functions.
- The plugin_host area and examples/plugin_example/host.go show a plugin-style integration model where scripts are treated as controlled extensions rather than full application code.
10. Examples as architecture guides
- examples/standard_examples/ demonstrates core language features and expected runtime behavior.
- examples/plugin_example/ demonstrates the host/plugin interaction path.
- These examples are useful for understanding which subsystems are meant to work together in real deployments.
11. Documentation and design intent
- docs/DESIGN_SPEC.md, docs/VM_ARCHITECTURE.md, and docs/PLUGINS.md indicate the repo is structured around a deliberately specified VM architecture and plugin model.
- docs/Moxy_ROADMAP.md suggests the current focus is the VM/bytecode foundation, with additional standard library and concurrency features planned later.
12. How to draw the architecture
- A good diagram should show two main execution paths:
- Compilation path: source → lexer/parser → AST → compiler → bytecode → VM → runtime objects/results
- Interpretation path: source → lexer/parser → AST → evaluator → runtime objects/results
- Surround these with the CLI, REPL, and host embedding/plugin boundary as the main entry/use cases.
Main entry points: vm.go VM · compiler.go Compiler · lexer.go Lexer · evaluator.go Evaluator
Components 20
Entry points
Ways to run or embed Moxy
Language frontend
Source parsing and AST construction
Runtime core
Compilation, bytecode, and execution
- Compiler · Translates AST into bytecode
internal/compiler/compiler.go - Symbols · Resolves locals, globals, and builtins during compilation
internal/compiler/symbol_table.go - Bytecode · Opcode encoding and instruction definitions
internal/code/code.go - VM · Executes compiled bytecode
internal/vm/vm.go - Frames · Runtime call frame management
internal/vm/frame.go - Stack · VM stack storage and manipulation
internal/vm/stack.go - Evaluator · Direct AST execution path
internal/evaluator/evaluator.go - Runtime Types · Shared objects, functions, closures, hashes, and builtins
types/object.go
Embedding boundary
Host integration and plugin-oriented control
- Plugin Host · Controlled host/plugin execution model
plugin_host
Examples
Scripts and host demos that exercise the architecture
- Std Examples · Core language and runtime examples
examples/standard_examples - Plugin Example · Host application plus script plugin example
examples/plugin_example/host.go
Docs
Architecture and design references
- Design Docs · VM and plugin architecture specifications
docs/VM_ARCHITECTURE.md
Connections 23
- CLI → Lexer: runs · Command-line execution starts the language pipeline
- REPL → Lexer: feeds · Interactive input enters the same frontend pipeline
- Host API → Compiler: embeds · Host applications can compile scripts through the public API
- Host API → Evaluator: embeds · Host applications can also drive tree-walk execution
- Lexer → Tokens: produces · Source text is tokenized
- Lexer → Parser: streams · Tokens flow into parsing
- Tokens → Parser: consumed by · Parser relies on token kinds and literals
- Parser → AST: builds · Parser constructs the syntax tree
- AST → Compiler: compiled by · AST is the compiler input
- AST → Evaluator: executed by · AST is also the interpreter input
- Compiler → Symbols: resolves · Compilation uses symbol resolution
- Compiler → Bytecode: emits · Compiler outputs bytecode instructions
- Bytecode → VM: loads · VM consumes encoded instructions
- Symbols → VM: supports · Resolved names are manifested as runtime operands and globals
- VM → Frames: uses · Execution is organized by frames
- VM → Stack: uses · Stack-based evaluation and operand storage
- VM → Runtime Types: creates · VM produces and manipulates runtime values
- Evaluator → Runtime Types: creates · Tree-walk execution produces the same runtime values
- Plugin Host → Runtime Types: exposes · Plugins interact with host-controlled runtime values
- Plugin Example → Plugin Host: demonstrates · Example host shows the plugin integration path
- Std Examples → Compiler: exercises · Standard examples validate the compiled execution path
- Std Examples → Evaluator: exercises · Examples also reflect interpreter-supported language features
- Design Docs → VM: describes · Architecture docs explain the bytecode runtime design