This document covers the command-line development tools and utilities provided by OwnLang for code analysis, optimization, debugging, and development workflow support. These tools are integrated into the main OwnLang executable and provide various modes for analyzing, formatting, and optimizing OwnLang programs.
For information about the interactive REPL environment, see Interactive REPL. For package management and project utilities, see Package Manager.
The OwnLang CLI provides a unified interface for accessing various development tools through command-line flags and options. The main entry point processes arguments and routes execution to the appropriate tool or execution mode.
The CLI argument parsing supports both short and long form options, with intelligent defaults and mode detection.
Sources: ownlang-desktop/src/main/java/com/annimon/ownlang/Main.java26-130
The beautifier tool reformats OwnLang source code according to consistent style guidelines. It processes the source through the lexical and parsing stages, then applies formatting rules to produce clean, readable code output.
Usage:
-b, --beautify
: Format and output the beautified source codeThe beautifier operates as a separate execution mode that bypasses normal program execution, instead outputting the formatted source code to standard output.
Implementation Flow:
Sources: ownlang-desktop/src/main/java/com/annimon/ownlang/Main.java40-128
The linter performs static analysis to identify potential bugs, style violations, and semantic issues in OwnLang code. It supports multiple analysis levels with different depths of checking.
Usage:
-l, --lint <mode>
: Run linting with specified mode none
: Disable lintingsemantic
: Perform semantic analysis (default)full
: Comprehensive analysis including style checksLinter Modes:
Mode | Description | Analysis Level |
---|---|---|
NONE | No linting performed | None |
SEMANTIC | Semantic validation and basic checks | Medium |
FULL | Comprehensive analysis with style validation | High |
The linter integrates into the standard execution pipeline as an optional stage, running after optimization but before execution.
Sources: ownlang-desktop/src/main/java/com/annimon/ownlang/Main.java74-84 ownlang-desktop/src/main/java/com/annimon/ownlang/RunOptions.java32-34
These diagnostic tools provide visibility into the internal representation of parsed OwnLang programs.
AST Viewer (-a, --showast
):
Token Viewer (-t, --showtokens
):
Both tools output their information after program execution completes, making them suitable for post-execution analysis.
Sources: ownlang-desktop/src/main/java/com/annimon/ownlang/Main.java36-199
The optimization system provides configurable code optimization with multiple passes and detailed reporting capabilities. The optimizer applies various transformation techniques to improve program performance.
Usage:
-o, --optimize N
: Enable optimization with N passes (0-9) 0
: No optimization1-8
: Fixed number of optimization passes9
: Run until convergence (no further optimizations possible)The optimization stage implements several transformation techniques:
Technique | Description | Implementation |
---|---|---|
Constant Folding | Evaluate constant expressions at compile time | ConstantFolding |
Constant Propagation | Replace variable references with known constant values | ConstantPropagation |
Dead Code Elimination | Remove unreachable or unused code sections | DeadCodeElimination |
Expression Simplification | Simplify complex expressions to equivalent simpler forms | ExpressionSimplification |
Instruction Combining | Merge adjacent instructions where possible | InstructionCombining |
The optimization process runs iteratively until either the maximum number of passes is reached or no further optimizations are possible.
Sources: ownlang-desktop/src/main/java/com/annimon/ownlang/Main.java55-67 ownlang-parser/src/main/java/com/annimon/ownlang/parser/optimization/OptimizationStage.java16-56
The timing measurement utility provides detailed performance analysis of each stage in the OwnLang processing pipeline.
Usage:
-m, --showtime
: Display elapsed time for parsing and execution stagesThe measurement system uses TimeMeasurement
with ScopedStageFactory
to automatically track the duration of each processing stage, providing insights into performance bottlenecks.
Measurement Output:
Sources: ownlang-desktop/src/main/java/com/annimon/ownlang/Main.java51-203
The sandbox provides an isolated execution environment for testing and experimentation with OwnLang programs.
Usage:
--sandbox
: Launch OwnLang in sandbox modeThe sandbox mode delegates to Sandbox.main()
with forwarded command-line arguments, providing a controlled environment for program execution with restricted system access.
Sources: ownlang-desktop/src/main/java/com/annimon/ownlang/Main.java95-97
The CLI provides built-in script execution capabilities for common development tasks.
Usage:
run <scriptName>
: Execute named script from the scripts resource directoryrun
(without arguments): List available scriptsScripts are loaded from the /scripts/
resource directory with automatic .own
extension resolution. This feature enables quick access to utility and example programs bundled with the OwnLang distribution.
Sources: ownlang-desktop/src/main/java/com/annimon/ownlang/Main.java99-112 ownlang-desktop/src/main/java/com/annimon/ownlang/RunOptions.java25-30
The CLI tools integrate seamlessly into the OwnLang execution pipeline through the stage-based architecture. Each tool operates as either a separate execution mode or as an optional stage in the main pipeline.
Pipeline Integration:
The scoped stage factory (ScopedStageFactory
) provides automatic timing measurement for each stage when the timing option is enabled, creating a transparent performance monitoring layer throughout the execution pipeline.
Sources: ownlang-desktop/src/main/java/com/annimon/ownlang/Main.java160-205