Skip to main content

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.

Python Version License: MIT Code style: black

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-100 score, 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 / else
  • while and for ... in ...
  • break, continue, and pass
  • Function definitions, calls, parameters, returns, and recursion
  • Lists, dictionaries, and index access
  • try / except / finally

Built-In Functions and Types

  • print
  • range
  • len
  • str
  • int
  • float
  • bool
  • list
  • dict

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:

  1. unused_vars
  2. dead_code
  3. constant_folding
  4. early_return
  5. loop_invariant
  6. string_concat_loop
  7. nested_loops
  8. hot_loop
  9. repeated_computation
  10. expensive_calls

Scoring

calculate_score(...) returns a ScoreReport with:

  • Final score from 0 to 100
  • Grade label such as Excellent, Good, or Fair
  • 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

optilang-1.0.0.tar.gz (94.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

optilang-1.0.0-py3-none-any.whl (53.5 kB view details)

Uploaded Python 3

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

Hashes for optilang-1.0.0.tar.gz
Algorithm Hash digest
SHA256 38a70e8803e8278ea2dd075b500277540cd31d1bd6518e34a17b8232bc7adb76
MD5 36c1b157658093dc1dae4836f87ab9d3
BLAKE2b-256 f81efc1f4c3d18a9cad3ad2e7c8b106632e83711fb6c48f0fd2c72afa002f107

See more details on using hashes here.

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

Hashes for optilang-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ffb76a81847934270d952d4dc299c47b71d45bc3fabddf2d650a3342a23c42fa
MD5 6764606041fe0dedfb278544dff049f7
BLAKE2b-256 778ed99cef007336be480d941b3a4ec64b40034cf081603a0965b25cc73085bb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page