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 PyPI version PyPI downloads

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.1.tar.gz (145.5 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.1-py3-none-any.whl (84.3 kB view details)

Uploaded Python 3

File details

Details for the file optilang-1.0.1.tar.gz.

File metadata

  • Download URL: optilang-1.0.1.tar.gz
  • Upload date:
  • Size: 145.5 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.1.tar.gz
Algorithm Hash digest
SHA256 6f8cc5e29780ce5cbb2c144a22e0402fb00533e8fd41378c41c06e4d577381d6
MD5 5a7f93223fabd91bfc977e08546f4cab
BLAKE2b-256 d868a7d00ed67c8ff988354c7e559f2b5f848a473c157080c097fc0ffce2035f

See more details on using hashes here.

File details

Details for the file optilang-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: optilang-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 84.3 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5fa71ec8f3d54b671a891ff6c8e722df6e94a52328d520635b8c09aa4e5448bc
MD5 e798b01d4ac6d39012c3dc522b85f1b2
BLAKE2b-256 9b9ef48e227fb56243d0e473575b640589a8c483adafedc6dd99ffb4aef3a5ae

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