Skip to content

Deploying Lesma

Introduction

Lesma is a modern, compiled programming language designed with simplicity, readability, and productivity in mind. Built on top of LLVM, it combines the ease of use of Python with the performance of compiled languages like C++ or Rust.

The language features a clean, Python-inspired syntax that emphasizes readability while providing strong typing, pattern matching, and modern language features. Lesma compiles to native code through LLVM, making it suitable for performance-critical applications.

Key highlights of Lesma:

  • Python-Like Syntax: Familiar, readable code structure
  • Compiled Performance: LLVM backend for optimized native code
  • Strong Typing: Type inference with optional explicit annotations
  • Pattern Matching: Expressive pattern matching for complex logic
  • First-Class Functions: Functions as values for functional programming
  • Memory Safety: Safe memory management without garbage collection overhead
  • Cross-Platform: Compiles for multiple target architectures
  • Modern Features: Generics, traits, and advanced type system
  • Active Development: Growing language with regular updates
  • 100% Open Source: MIT licensed

This guide walks through deploying a Lesma development environment on Klutch.sh using Docker, enabling you to compile and run Lesma programs in the cloud.

Why Deploy Lesma on Klutch.sh

Deploying a Lesma development environment on Klutch.sh provides several advantages:

Consistent Environment: Same development setup across all machines.

Simplified Setup: Skip the complex LLVM and toolchain installation.

Cloud Compilation: Compile programs without local resource constraints.

Persistent Workspace: Your code and binaries survive restarts.

GitHub Integration: Sync your Lesma projects automatically.

Scalable Resources: Allocate CPU for faster compilation.

Prerequisites

Before deploying Lesma on Klutch.sh, ensure you have:

  • A Klutch.sh account
  • A GitHub account with a repository for your configuration
  • Basic familiarity with Docker and programming concepts
  • Understanding of compiled language workflows

Understanding Lesma Architecture

Lesma uses a multi-stage compilation process:

Lexer: Tokenizes source code into a stream of tokens.

Parser: Builds an Abstract Syntax Tree (AST) from tokens.

Type Checker: Validates types and performs inference.

LLVM IR Generation: Converts AST to LLVM Intermediate Representation.

Optimization: LLVM optimization passes improve generated code.

Code Generation: LLVM backend produces native machine code.

Preparing Your Repository

Create a GitHub repository for your Lesma environment.

Repository Structure

lesma-deploy/
├── Dockerfile
├── examples/
│ ├── hello.les
│ └── fibonacci.les
├── README.md
└── .dockerignore

Creating the Dockerfile

Create a Dockerfile in the root of your repository:

FROM python:3.11-slim
# Install system dependencies
RUN apt-get update && apt-get install -y \
llvm-15 \
llvm-15-dev \
clang-15 \
cmake \
build-essential \
git \
&& rm -rf /var/lib/apt/lists/*
# Set LLVM paths
ENV LLVM_CONFIG=/usr/bin/llvm-config-15
ENV PATH="/usr/lib/llvm-15/bin:$PATH"
# Install Lesma
RUN pip install lesma
# Create workspace
WORKDIR /workspace
# Copy example files
COPY examples/ /workspace/examples/
# Expose port for any web-based tools
EXPOSE 8080
# Default command
CMD ["bash"]

Alternative Development Environment

For a more comprehensive development setup:

FROM python:3.11
# Install system dependencies
RUN apt-get update && apt-get install -y \
llvm-15 \
llvm-15-dev \
clang-15 \
cmake \
build-essential \
git \
curl \
vim \
&& rm -rf /var/lib/apt/lists/*
# Set LLVM paths
ENV LLVM_CONFIG=/usr/bin/llvm-config-15
ENV PATH="/usr/lib/llvm-15/bin:$PATH"
# Install Lesma
RUN pip install lesma
# Install development tools
RUN pip install ipython pytest
# Create workspace
WORKDIR /workspace
# Copy project files
COPY . /workspace/
# Keep container running
CMD ["tail", "-f", "/dev/null"]

Example Lesma Programs

Create examples/hello.les:

def main()
print("Hello, Lesma!")

Create examples/fibonacci.les:

def fibonacci(n: int) -> int
if n <= 1
return n
return fibonacci(n - 1) + fibonacci(n - 2)
def main()
for i in range(10)
print(fibonacci(i))

Deploying Lesma on Klutch.sh

    Push Your Repository to GitHub

    Initialize and push your repository:

    Terminal window
    git init
    git add .
    git commit -m "Initial Lesma development environment"
    git remote add origin https://github.com/yourusername/lesma-deploy.git
    git push -u origin main

    Create a New Project on Klutch.sh

    Navigate to the Klutch.sh dashboard and create a new project named “lesma” or “lesma-dev”.

    Create a New App

    Within your project, create a new app. Connect your GitHub account and select the repository containing your Dockerfile.

    Configure Resources

    Lesma compilation benefits from CPU resources:

    • Allocate sufficient CPU for compilation
    • At least 1GB memory for LLVM operations

    Attach Persistent Volumes

    Add storage for your code and compiled binaries:

    Mount PathRecommended SizePurpose
    /workspace5 GBSource code and binaries

    Deploy Your Application

    Click Deploy to start the build process.

    Access the Environment

    Use the terminal access to interact with your Lesma environment.

Using Lesma

Compiling Programs

Compile a Lesma program:

Terminal window
lesma compile examples/hello.les -o hello
./hello

Running Programs Directly

Run without creating an executable:

Terminal window
lesma run examples/hello.les

Checking Syntax

Validate code without compiling:

Terminal window
lesma check examples/fibonacci.les

Language Features

Variables and Types

# Type inference
let x = 42
let name = "Lesma"
# Explicit types
let count: int = 100
let pi: float = 3.14159

Functions

def greet(name: str) -> str
return "Hello, " + name + "!"
def add(a: int, b: int) -> int
return a + b

Control Flow

# If statements
if x > 10
print("Large")
elif x > 5
print("Medium")
else
print("Small")
# For loops
for i in range(10)
print(i)
# While loops
while x > 0
x = x - 1

Pattern Matching

def describe(n: int) -> str
match n
case 0
return "zero"
case 1
return "one"
case _
return "many"

Classes and Structs

struct Point
x: float
y: float
def distance(self, other: Point) -> float
let dx = self.x - other.x
let dy = self.y - other.y
return sqrt(dx * dx + dy * dy)

Development Workflow

Project Organization

my-lesma-project/
├── src/
│ ├── main.les
│ └── utils.les
├── tests/
│ └── test_utils.les
└── README.md

Building Projects

For multi-file projects:

Terminal window
lesma compile src/main.les -o myapp

Debugging

View LLVM IR for debugging:

Terminal window
lesma compile --emit-llvm examples/hello.les

Troubleshooting

Compilation Errors

  • Check syntax matches Lesma conventions
  • Verify type annotations are correct
  • Review error messages for line numbers

LLVM Issues

  • Ensure LLVM paths are correctly set
  • Check LLVM version compatibility
  • Verify llvm-config is accessible

Performance Issues

  • Allocate more CPU for compilation
  • Use release mode for optimized binaries
  • Check for algorithmic inefficiencies

Additional Resources

Conclusion

Deploying a Lesma development environment on Klutch.sh gives you access to this modern compiled language without the complexity of local LLVM setup. With persistent storage for your projects and cloud-based compilation, you can explore and develop with Lesma from anywhere.

Whether you’re learning a new language or building performance-critical applications, the Lesma environment on Klutch.sh provides the tools you need for productive development.