A Python-inspired interpreter with profiling, optimization analysis, and scoring
Project description
OptiLang
A Python-inspired interpreter with built-in profiling, optimization analysis, and scoring.
OptiLang 1.0.0 is the first stable release of the project. It ships the full source-to-insight pipeline:
source -> tokens -> AST -> semantic checks -> execution -> profiling -> optimization suggestions -> score
Release Highlights
- Python-like language core with variables, control flow, functions, recursion, lists, dictionaries, and exception handling
- Runtime execution with line-level and function-level profiling
- Ten optimization detectors for performance and maintainability issues
- Four-dimension scoring system with a final
0-100score, grade, and narrative explanation - End-to-end Python API for execution, analysis, and scoring
Quick Start
Install From Source
git clone https://github.com/Sthamanik/optilang.git
cd optilang
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install -e .
End-to-End Example
from optilang import analyze, calculate_score, execute
from optilang.lexer import tokenize
from optilang.parser import parse
source = """
total = 0
for i in range(10):
total += i
print(total)
"""
result = execute(source)
ast = parse(tokenize(source))
report = analyze(ast, result.profiling, result.symbol_table)
score = calculate_score(
profiling_data=result.profiling.to_dict() if result.profiling else None,
optimizer_report=report,
source_lines=source.count("\n") + 1,
errors=result.errors,
)
print(result.output) # 45
print(score.grade, score.score) # e.g. Excellent 95.0
print(score.complexity_class) # e.g. O(n)
for suggestion in report.suggestions:
print(f"{suggestion.pattern}: {suggestion.description}")
If you only need optimization suggestions from source text, use analyze_source(source) from optilang or optilang.optimizer.
๐๏ธ Architecture
โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ
โ Lexer โ -> โ Parser โ -> โ Semantic โ -> โ Executor โ -> โ Profiler โ
โ (Tokens) โ โ (AST) โ โ (Annot AST) โ โ (Runtime)โ โ (Metrics)โ
โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ
โ โ
v v
โโโโโโโโโโโโ โโโโโโโโโโโโ
โOptimizer โ โ Scorer โ
โ(Patterns)โ โ (0-100) โ
โโโโโโโโโโโโ โโโโโโโโโโโโ
What OptiLang Supports
Language Features
- Numbers, strings, booleans, and
None - Arithmetic, comparison, logical, unary, and augmented assignment operators
- Variables and lexical scoping
if/elif/elsewhileandfor ... in ...break,continue, andpass- Function definitions, calls, parameters, returns, and recursion
- Lists, dictionaries, and index access
try/except/finally
Built-In Functions and Types
printrangelenstrintfloatboollistdict
Analysis Features
Profiling
Execution returns ExecutionResult, which can include:
- Captured program output
- Execution time
- Line execution counts and timings
- Function call counts and recursion depth
- Peak memory estimate
- Heuristic complexity estimate
- Final symbol table
Optimization Detectors
OptiLang 1.0.0 ships with ten detectors:
unused_varsdead_codeconstant_foldingearly_returnloop_invariantstring_concat_loopnested_loopshot_looprepeated_computationexpensive_calls
Scoring
calculate_score(...) returns a ScoreReport with:
- Final score from
0to100 - Grade label such as
Excellent,Good, orFair - Complexity class
- Dimension breakdown for correctness, efficiency/complexity, quality, and maintainability
- Beginner-friendly narrative summary
Project Layout
optilang/
lexer.py
parser.py
semantic_analyzer.py
executor.py
profiler.py
optimizer.py
scoring.py
models.py
tests/
docs/
Documentation
Development
python3 -m pip install -e ".[dev]"
python3 -m pytest
black optilang tests
mypy optilang
flake8 optilang
Contributing
See CONTRIBUTING.md for workflow, quality checks, and documentation expectations.
License
This project is licensed under the MIT License. See LICENSE for details.
Team
Contact
- Email: shresthamanik1820@gmail.com
- Issues: GitHub Issues
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file optilang-1.0.0.tar.gz.
File metadata
- Download URL: optilang-1.0.0.tar.gz
- Upload date:
- Size: 94.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
38a70e8803e8278ea2dd075b500277540cd31d1bd6518e34a17b8232bc7adb76
|
|
| MD5 |
36c1b157658093dc1dae4836f87ab9d3
|
|
| BLAKE2b-256 |
f81efc1f4c3d18a9cad3ad2e7c8b106632e83711fb6c48f0fd2c72afa002f107
|
File details
Details for the file optilang-1.0.0-py3-none-any.whl.
File metadata
- Download URL: optilang-1.0.0-py3-none-any.whl
- Upload date:
- Size: 53.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ffb76a81847934270d952d4dc299c47b71d45bc3fabddf2d650a3342a23c42fa
|
|
| MD5 |
6764606041fe0dedfb278544dff049f7
|
|
| BLAKE2b-256 |
778ed99cef007336be480d941b3a4ec64b40034cf081603a0965b25cc73085bb
|