How killme2008/aviatorscript works
Project Type and Purpose
• AviatorScript is an open-source, JVM-hosted scripting language implementation (interpreter + compiler) written in Java.
• Its core purpose is to parse, compile (via ASM), interpret, and execute user scripts, expose a javax.script API, and offer a CLI for ad hoc evaluation.
Key Architectural Layers
a. CLI / Shell Layer
• bin/aviator shell script
• Downloads or locates the aviator-{version}.jar in ~/.aviatorscript
• Invokes java com.googlecode.aviator.Main [options]
b. Core Engine (JAR)
1. Frontend (Lexing & Parsing)
• lexer/ExpressionLexer
• parser/ExpressionParser → produces AST / CompileType info
2. Intermediate Representation (IR)
• code/interpreter/ir/*IR classes model an instruction stream
3. Compiler / Code Generation
• ASM-based bytecode generator (code/asm/ASMCodeGenerator + code/CodeGenerator variants)
• Dynamic class definition via ClassDefiner
4. Interpreter (fallback)
• InterpretExpression + InterpretCodeGenerator + InterpretContext
5. Evaluator API
• AviatorEvaluator / AviatorEvaluatorInstance — entry points for evaluate/compile/execute
• Options: EvalMode toggles ASM vs. interpretation, timeout, sandbox settings
6. Runtime Environment
• runtime package: context, function dispatch, bindings, Java reflection fallback
• runtime/function/* and runtime/function/math|seq|string|system/* – built-in functions
• runtime/type/* – Aviator data types (AviatorNumber, AviatorString, AviatorObject…)
• runtime/module/* – module loaders (IoModule, etc.)
7. Annotation-driven Extension
• annotation/@Function, FunctionLoader, ClassPathConfigFunctionLoader, SpringContextFunctionLoader
8. Serialization & ScriptEngine
• serialize/AviatorObjectInputStream / OutputStream for script caching
• script/AviatorScriptEngineFactory / AviatorScriptEngine for JSR-223 integration
c. Testing & Examples
• examples/*.av, tests/ – unit tests demonstrating features, quality gating via GitHub Actions/Maven.
Component Relationships & Data Flow
• CLI passes script or expression to Main → selects mode (compile/interpret) → calls AviatorEvaluatorInstance.
• EvaluatorInstance:
→ Lexer → Parser → AST
→ either pass AST to CodeGenerator (ASM) or to InterpretCodeGenerator
→ produced bytecode class is loaded, then invoked, returning AviatorObject
→ Runtime handles function dispatch, type conversion, error handling
• ScriptEngine API wraps Evaluator, exposes javax.script.* interfaces for host integration.
• Serialization layer can snapshot compiled bytecode for reuse.
Architectural Patterns & Principles
• Pluggable function loader via annotations (inversion of control)
• Strategy pattern for code generation (multiple CodeGenerator implementations)
• Interpreter pattern for IR execution
• Builder/factory for AviatorEvaluatorInstance configuration (EvalMode, sandbox)
• Separation of concerns: lexer, parser, IR, compiler, runtime, API layers.
Technologies & Frameworks
• Java 8+
• ASM bytecode framework (com.googlecode.aviator.asm)
• javax.script API (JSR-223)
• Maven build, GitHub Actions / Travis CI for CI
• Optional Spring integration via spring/* loaders.