crosstl

Universal Programming Language & Translator

https://github.com/crossgl/crosstl

Science Score: 77.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 3 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
    2 of 34 committers (5.9%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (7.0%) to scientific vocabulary

Keywords

apple directx game-development gamedev graphics metal modular mojo opengl python vulkan
Last synced: 6 months ago · JSON representation ·

Repository

Universal Programming Language & Translator

Basic Info
  • Host: GitHub
  • Owner: CrossGL
  • License: apache-2.0
  • Language: Python
  • Default Branch: main
  • Homepage: https://crossgl.net
  • Size: 1020 KB
Statistics
  • Stars: 69
  • Watchers: 2
  • Forks: 87
  • Open Issues: 0
  • Releases: 4
Topics
apple directx game-development gamedev graphics metal modular mojo opengl python vulkan
Created almost 2 years ago · Last pushed 8 months ago
Metadata Files
Readme Contributing License Citation Codeowners Zenodo

README.md




CrossTL - Universal Programming Language & Translator

CrossTL is a revolutionary universal programming language translator built around CrossGL - a powerful intermediate representation (IR) language that serves as the bridge between diverse programming languages, platforms, and computing paradigms. More than just a translation tool, CrossGL represents a complete programming language designed for universal code portability and cross-platform development.

🌍 CrossGL: The Universal Programming Language

Beyond Shader Translation - A Complete Programming Ecosystem

CrossGL has evolved far beyond its origins as a shader language into a comprehensive programming language with full support for:

  • Advanced Control Flow: Complex conditionals, loops, switch statements, and pattern matching
  • Rich Data Structures: Arrays, structs, enums, and custom types
  • Memory Management: Buffer handling, pointer operations, and memory layout control
  • Function Systems: First-class functions, generics, and polymorphism
  • Compute Paradigms: Parallel processing, GPU computing, and heterogeneous execution
  • Modern Language Features: Type inference, pattern matching, and algebraic data types

🚀 Write Once, Deploy Everywhere

CrossGL enables you to write sophisticated programs once and deploy across:

  • Graphics APIs: Metal, DirectX (HLSL), OpenGL (GLSL), Vulkan (SPIRV)
  • Systems Languages: Rust, Mojo
  • GPU Computing: CUDA, HIP
  • Specialized Domains: Slang (real-time graphics), compute shaders

🎯 Supported Translation Targets

CrossTL provides comprehensive bidirectional translation between CrossGL and major programming ecosystems:

Graphics & Compute APIs

  • Metal - Apple's unified graphics and compute API
  • DirectX (HLSL) - Microsoft's graphics framework
  • OpenGL (GLSL) - Cross-platform graphics standard
  • Vulkan (SPIRV) - High-performance graphics and compute

Systems Programming Languages

  • Rust - Memory-safe systems programming with GPU support
  • Mojo - AI-first systems language with Python compatibility

Parallel Computing Platforms

  • CUDA - NVIDIA's parallel computing platform
  • HIP - AMD's GPU computing interface

Specialized Languages

  • Slang - Real-time shading and compute language

Universal Intermediate Representation

  • CrossGL (.cgl) - Our universal programming language and IR

💡 Revolutionary Advantages

  1. 🔄 Universal Portability: Write complex algorithms once, run on any platform
  2. ⚡ Performance Preservation: Maintain optimization opportunities across translations
  3. 🧠 Simplified Development: Master one language instead of platform-specific variants
  4. 🔍 Advanced Debugging: Universal tooling for analysis and optimization
  5. 🔮 Future-Proof Architecture: Easily adapt to emerging programming paradigms
  6. 🌐 Bidirectional Translation: Migrate existing codebases to CrossGL or translate to any target
  7. 📈 Scalable Complexity: From simple shaders to complex distributed algorithms
  8. 🎯 Domain Flexibility: Graphics, AI, HPC, systems programming, and beyond

⚙️ Translation Architecture

CrossTL employs a sophisticated multi-stage translation pipeline:

  1. Lexical Analysis: Advanced tokenization with context-aware parsing
  2. Syntax Analysis: Robust AST generation with error recovery
  3. Semantic Analysis: Type checking, scope resolution, and semantic validation
  4. IR Generation: Conversion to CrossGL intermediate representation
  5. Optimization Passes: Platform-agnostic code optimization and analysis
  6. Target Generation: Backend-specific code generation with optimization
  7. Post-Processing: Platform-specific optimizations and formatting

🔄 Bidirectional Translation Capabilities

CrossGL supports seamless translation in both directions - import existing code from any supported language or export CrossGL to any target platform.

🌈 CrossGL Programming Language Examples

Complex Algorithm Implementation

```cpp // Advanced pattern matching and algebraic data types enum Result { Ok(T), Error(E) }

struct Matrix { data: T[], rows: u32, cols: u32 }

function matrixMultiply(a: Matrix, b: Matrix) -> Result, String> { if (a.cols != b.rows) { return Result::Error("Matrix dimensions incompatible"); }

let result = Matrix<T> {
    data: new T[a.rows * b.cols],
    rows: a.rows,
    cols: b.cols
};

parallel for i in 0..a.rows {
    for j in 0..b.cols {
        let mut sum = T::default();
        for k in 0..a.cols {
            sum += a.data[i * a.cols + k] * b.data[k * b.cols + j];
        }
        result.data[i * result.cols + j] = sum;
    }
}

return Result::Ok(result);

}

// GPU compute shader with advanced memory management compute spawn matrixCompute { buffer float* matrixA; buffer float* matrixB; buffer float* result;

local float shared_memory[256];

void main() {
    let idx = workgroup_id() * workgroup_size() + local_id();

    // Complex parallel reduction with shared memory
    shared_memory[local_id()] = matrix_A[idx] * matrix_B[idx];
    workgroup_barrier();

    // Tree reduction
    for stride in [128, 64, 32, 16, 8, 4, 2, 1] {
        if (local_id() < stride) {
            shared_memory[local_id()] += shared_memory[local_id() + stride];
        }
        workgroup_barrier();
    }

    if (local_id() == 0) {
        result[workgroup_id()] = shared_memory[0];
    }
}

} ```

Advanced Graphics Pipeline

```cpp // Physically-based rendering with advanced material system struct Material { albedo: vec3, metallic: float, roughness: float, normal_map: texture2d, displacement: texture2d }

struct Lighting { position: vec3, color: vec3, intensity: float, attenuation: vec3 }

shader PBRShader { vertex { input vec3 position; input vec3 normal; input vec2 texCoord; input vec4 tangent;

    uniform mat4 modelMatrix;
    uniform mat4 viewMatrix;
    uniform mat4 projectionMatrix;

    output vec3 worldPos;
    output vec3 worldNormal;
    output vec2 uv;
    output mat3 TBN;

    void main() {
        vec4 worldPosition = modelMatrix * vec4(position, 1.0);
        worldPos = worldPosition.xyz;

        vec3 T = normalize(vec3(modelMatrix * vec4(tangent.xyz, 0.0)));
        vec3 N = normalize(vec3(modelMatrix * vec4(normal, 0.0)));
        vec3 B = cross(N, T) * tangent.w;
        TBN = mat3(T, B, N);

        worldNormal = N;
        uv = texCoord;

        gl_Position = projectionMatrix * viewMatrix * worldPosition;
    }
}

// Advanced fragment shader with PBR lighting
fragment {
    input vec3 worldPos;
    input vec3 worldNormal;
    input vec2 uv;
    input mat3 TBN;

    uniform Material material;
    uniform Lighting lights[8];
    uniform int lightCount;
    uniform vec3 cameraPos;

    output vec4 fragColor;

    vec3 calculatePBR(vec3 albedo, float metallic, float roughness,
                     vec3 normal, vec3 viewDir, vec3 lightDir, vec3 lightColor) {
        // Advanced PBR calculation with microfacet model
        vec3 halfVector = normalize(viewDir + lightDir);
        float NdotV = max(dot(normal, viewDir), 0.0);
        float NdotL = max(dot(normal, lightDir), 0.0);
        float NdotH = max(dot(normal, halfVector), 0.0);
        float VdotH = max(dot(viewDir, halfVector), 0.0);

        // Fresnel term
        vec3 F0 = mix(vec3(0.04), albedo, metallic);
        vec3 F = F0 + (1.0 - F0) * pow(1.0 - VdotH, 5.0);

        // Distribution term (GGX)
        float alpha = roughness * roughness;
        float alpha2 = alpha * alpha;
        float denom = NdotH * NdotH * (alpha2 - 1.0) + 1.0;
        float D = alpha2 / (3.14159 * denom * denom);

        // Geometry term
        float G = geometrySmith(NdotV, NdotL, roughness);

        vec3 numerator = D * G * F;
        float denominator = 4.0 * NdotV * NdotL + 0.001;
        vec3 specular = numerator / denominator;

        vec3 kS = F;
        vec3 kD = vec3(1.0) - kS;
        kD *= 1.0 - metallic;

        return (kD * albedo / 3.14159 + specular) * lightColor * NdotL;
    }

    void main() {
        vec3 normal = normalize(TBN * (texture(material.normal_map, uv).rgb * 2.0 - 1.0));
        vec3 viewDir = normalize(cameraPos - worldPos);

        vec3 color = vec3(0.0);

        for (int i = 0; i < lightCount; ++i) {
            vec3 lightDir = normalize(lights[i].position - worldPos);
            float distance = length(lights[i].position - worldPos);
            float attenuation = 1.0 / (lights[i].attenuation.x +
                                      lights[i].attenuation.y * distance +
                                      lights[i].attenuation.z * distance * distance);

            vec3 lightColor = lights[i].color * lights[i].intensity * attenuation;
            color += calculatePBR(material.albedo, material.metallic,
                                 material.roughness, normal, viewDir, lightDir, lightColor);
        }

        // Add ambient lighting
        color += material.albedo * 0.03;

        // Tone mapping and gamma correction
        color = color / (color + vec3(1.0));
        color = pow(color, vec3(1.0/2.2));

        fragColor = vec4(color, 1.0);
    }
}

} ```

Getting Started

Install CrossTL's universal translator:

bash pip install crosstl

Basic Usage

1. Create CrossGL Program

```cpp // algorithm.cgl - Universal algorithm implementation function quicksort(arr: T[], low: i32, high: i32) -> void { if (low < high) { let pivot = partition(arr, low, high); quicksort(arr, low, pivot - 1); quicksort(arr, pivot + 1, high); } }

function partition(arr: T[], low: i32, high: i32) -> i32 { let pivot = arr[high]; let i = low - 1;

for j in low..high {
    if (arr[j] <= pivot) {
        i++;
        swap(arr[i], arr[j]);
    }
}

swap(arr[i + 1], arr[high]);
return i + 1;

}

compute parallel_sort { buffer float* data; uniform int size;

void main() {
    let idx = global_id();
    if (idx < size) {
        // Parallel bitonic sort implementation
        bitonicSort(data, size, idx);
    }
}

} ```

2. Universal Translation

```python import crosstl

Translate to any target language/platform

rustcode = crosstl.translate('algorithm.cgl', backend='rust', saveshader='algorithm.rs') cudacode = crosstl.translate('algorithm.cgl', backend='cuda', saveshader='algorithm.cu') metalcode = crosstl.translate('algorithm.cgl', backend='metal', saveshader='algorithm.metal') mojocode = crosstl.translate('algorithm.cgl', backend='mojo', saveshader='algorithm.mojo') ```

Advanced Translation Examples

Cross-Platform AI Kernels

```python import crosstl

Translate neural network kernels across AI platforms

ai_kernel = """ compute neuralNetwork { buffer float* weights; buffer float* inputs; buffer float* outputs; buffer float* biases;

uniform int input_size;
uniform int output_size;

void main() {
    let neuron_id = global_id();
    if (neuron_id >= output_size) return;

    float sum = 0.0;
    for i in 0..input_size {
        sum += weights[neuron_id * input_size + i] * inputs[i];
    }

    outputs[neuron_id] = relu(sum + biases[neuron_id]);
}

} """

Deploy across AI hardware platforms

cudaai = crosstl.translate(aikernel, backend='cuda') # NVIDIA GPUs hipai = crosstl.translate(aikernel, backend='hip') # AMD GPUs metalai = crosstl.translate(aikernel, backend='metal') # Apple Silicon mojoai = crosstl.translate(aikernel, backend='mojo') # Mojo AI runtime ```

Systems Programming Translation

```python

Translate systems-level code across platforms

systemscode = """ struct MemoryPool { buffer u8* memory; sizet capacity; size_t used; mutex lock; }

function allocate(pool: MemoryPool, size: size_t) -> void { lock_guard guard(pool.lock);

if (pool.used + size > pool.capacity) {
    return null;
}

void* ptr = pool.memory + pool.used;
pool.used += size;
return ptr;

} """

rustsystems = crosstl.translate(systemscode, backend='rust') # Memory-safe systems code cppsystems = crosstl.translate(systemscode, backend='cpp') # High-performance C++ csystems = crosstl.translate(systemscode, backend='c') # Portable C code ```

Reverse Translation - Import Existing Code

```python

Import and unify existing codebases

conversions = [ ('existingshader.hlsl', 'unified.cgl'), # DirectX to CrossGL ('gpukernel.cu', 'unified.cgl'), # CUDA to CrossGL ('graphics.metal', 'unified.cgl'), # Metal to CrossGL ('algorithm.rs', 'unified.cgl'), # Rust to CrossGL ('compute.mojo', 'unified.cgl'), # Mojo to CrossGL ]

for source, target in conversions: unifiedcode = crosstl.translate(source, backend='cgl', saveshader=target) print(f"✅ Unified {source} into CrossGL: {target}") ```

Comprehensive Platform Deployment

```python import crosstl

One CrossGL program, unlimited platforms

program = 'universal_algorithm.cgl'

Deploy across all supported platforms

deployment_targets = { # Graphics APIs 'metal': '.metal', # Apple ecosystems 'directx': '.hlsl', # Windows/Xbox 'opengl': '.glsl', # Cross-platform 'vulkan': '.spirv', # High-performance

# Systems languages
'rust': '.rs',          # Memory safety
'mojo': '.mojo',        # AI-optimized
'cpp': '.cpp',          # Performance
'c': '.c',              # Portability

# Parallel computing
'cuda': '.cu',          # NVIDIA
'hip': '.hip',          # AMD
'opencl': '.cl',        # Cross-vendor

# Specialized
'slang': '.slang',      # Real-time graphics
'wgsl': '.wgsl',        # Web platforms

}

for backend, extension in deploymenttargets.items(): outputfile = f'deployments/{program.stem}{backend}{extension}' try: code = crosstl.translate(program, backend=backend, saveshader=outputfile) print(f"✅ {backend.upper()}: {outputfile}") except Exception as e: print(f"⚠️ {backend.upper()}: {str(e)}")

print(f"\n🚀 Universal deployment complete!") print(f"📁 Check deployments/ directory for platform-specific implementations") ```

Language Features Deep Dive

CrossGL provides comprehensive programming language features:

Type System

  • Strong static typing with type inference
  • Generic programming with type parameters
  • Algebraic data types (enums with associated data)
  • Trait/interface system for polymorphism
  • Memory layout control for performance

Control Flow

  • Pattern matching for complex conditional logic
  • Advanced loops (for, while, loop with break/continue)
  • Exception handling with Result types
  • Async/await for concurrent programming

Memory Management

  • Explicit lifetime management when needed
  • Buffer abstractions for GPU programming
  • Pointer safety with compile-time checks
  • Reference semantics for efficient data sharing

Parallelism

  • Compute shaders for GPU programming
  • Parallel loops for CPU vectorization
  • Workgroup operations for GPU synchronization
  • Memory barriers for consistency

For comprehensive language documentation, visit our Language Reference.

Contributing

CrossGL is a community-driven project. Whether you're contributing language features, backend implementations, optimizations, or documentation, your contributions shape the future of universal programming! 🌟

Find out more in our Contributing Guide

Community

Join the universal programming revolution

  • Twitter - Latest updates and announcements
  • LinkedIn - Professional community
  • Discord - Real-time discussions and support
  • YouTube - Tutorials and deep dives

Shape the future of programming languages!

License

CrossTL is open-source and licensed under the Apache License 2.0.


CrossGL: One Language, Infinite Possibilities 🌍

Building the universal foundation for the next generation of programming

The CrossGL Team

Owner

  • Name: CrossGL
  • Login: CrossGL
  • Kind: organization

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
title: "CrossTL: Universal Programming Language & Translator"
authors:
  - family-names: "Niketan"
    given-names: "Nripesh"
    affiliation: "CrossGL"
    orcid: "https://orcid.org/0009-0008-2066-1937"
  - family-names: "Shrivastava"
    given-names: "Vaatsalya"
    affiliation: "CrossGL"
version: "1.0.0"
date-released: "2025-07-07"
doi: "10.5281/zenodo.15826974"
url: "https://github.com/CrossGL/crosstl"
repository-code: "https://github.com/CrossGL/crosstl"
license: Apache-2.0
keywords:
  - "programming languages"
  - "code translation"
  - "cross-platform development"
  - "GPU computing"
  - "compiler"
abstract: "CrossTL is a revolutionary universal programming language translator built around CrossGL - a powerful intermediate representation language that serves as the bridge between diverse programming languages, platforms, and computing paradigms."

GitHub Events

Total
  • Issues event: 94
  • Watch event: 36
  • Delete event: 8
  • Issue comment event: 540
  • Push event: 208
  • Pull request review comment event: 15
  • Pull request review event: 60
  • Pull request event: 139
  • Fork event: 61
  • Create event: 14
Last Year
  • Issues event: 94
  • Watch event: 36
  • Delete event: 8
  • Issue comment event: 540
  • Push event: 208
  • Pull request review comment event: 15
  • Pull request review event: 60
  • Pull request event: 139
  • Fork event: 61
  • Create event: 14

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 237
  • Total Committers: 34
  • Avg Commits per committer: 6.971
  • Development Distribution Score (DDS): 0.654
Past Year
  • Commits: 236
  • Committers: 34
  • Avg Commits per committer: 6.941
  • Development Distribution Score (DDS): 0.657
Top Committers
Name Email Commits
Nripesh Niketan n****4@g****m 82
samthakur587 s****8@g****m 50
Vaatsalya 9****3 25
anshikavashistha 9****a 8
Solo-Levelings t****4@g****m 8
Husien vora w****a@g****m 7
Maharshi Basu 8****r 6
pre-commit-ci[bot] 6****] 6
Jyotin Goel 1****5 5
Yogesh 1****k 4
Prithvi-Rao e****4@s****n 4
Vruddhi Shah v****3@g****m 3
Archit Gupta 9****7 2
C B Dev Narayan d****b@p****n 2
Pratush Rai 4****0 2
Priyash Shah 8****7 2
Sahil06012002 9****2 2
dheeraxspidey 1****y 2
rigved-desai 1****i 2
zephyr_whisper 1****4 1
sahithi aele s****d@g****m 1
aditya112patel 1****l 1
Thirulogeswaren t****v@o****m 1
Swayam Patil 9****8 1
Satyam Singh 1****6 1
Ratnesh Kumar Jaiswal 1****l 1
Raghav K 1****3 1
Jayshree Menon 1****z 1
Inanna 9****7 1
Gopal Krishna Shukla 6****1 1
and 4 more...
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 111
  • Total pull requests: 174
  • Average time to close issues: about 2 months
  • Average time to close pull requests: 19 days
  • Total issue authors: 18
  • Total pull request authors: 45
  • Average comments per issue: 3.59
  • Average comments per pull request: 1.53
  • Merged pull requests: 103
  • Bot issues: 0
  • Bot pull requests: 4
Past Year
  • Issues: 49
  • Pull requests: 125
  • Average time to close issues: about 2 months
  • Average time to close pull requests: 25 days
  • Issue authors: 14
  • Pull request authors: 37
  • Average comments per issue: 4.63
  • Average comments per pull request: 1.66
  • Merged pull requests: 62
  • Bot issues: 0
  • Bot pull requests: 3
Top Authors
Issue Authors
  • samthakur587 (91)
  • code-with-parth (8)
  • ashwith2427 (3)
  • AeleSahithi (2)
  • Rithik1073 (1)
  • he11owthere (1)
  • ParidhiChauhan (1)
  • RohithKesoju (1)
  • Swish78 (1)
  • pracheeeeez (1)
  • Proxihox (1)
  • vaatsalya123 (1)
  • aarthiab (1)
  • Mukilan2003 (1)
  • Aparnendua (1)
Pull Request Authors
  • samthakur587 (50)
  • Sambit712 (20)
  • anshikavashistha (19)
  • NripeshN (17)
  • gjyotin305 (12)
  • Solo-Levelings (11)
  • themaverick (10)
  • MashyBasker (9)
  • Raghav-2903 (7)
  • mr-195 (6)
  • pre-commit-ci[bot] (6)
  • dheeraxspidey (5)
  • ArchitGupta07 (5)
  • himaanisrivatsava (5)
  • adityanarayanan343 (4)
Top Labels
Issue Labels
stale (15) enhancement (14) Directx backend (11) hacktoberfest (11) good first issue (5) ToDO (4) Translator Frontend (3) opengl backend (2) vulkan backend (1) tests (1) question (1)
Pull Request Labels
stale (29) Directx backend (9) hacktoberfest (9) enhancement (7) bug (2) Translator Frontend (1)

Dependencies

requirements.txt pypi
  • gast *
  • pytest *
setup.py pypi
  • gast *