Skip to content

this is compiler for Bobi language whose sytax is the same as python but GIL

Notifications You must be signed in to change notification settings

dabian321/BoBiCompiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bobi

A Python-compatible programming language compiler without GIL (Global Interpreter Lock), designed for true multi-core parallelism.

Features

  • No GIL: Native multi-threading support with true parallelism
  • Python Syntax: Familiar Python 3.10+ compatible syntax
  • High Performance: Stack-based VM with optimized bytecode
  • Thread-Safe: Built-in synchronization primitives (Lock, RLock, Semaphore, Event, Queue)
  • Package Manager: Built-in package management similar to pip/cargo
  • Cross-Platform: Windows, Linux, macOS support

Installation

From Source

# Clone the repository
git clone https://github.com/example/bobi.git
cd bobi

# Build with Cargo
cargo build --release

# The binary is at target/release/bobi (or bobi.exe on Windows)

Requirements

  • Rust 1.70+ (with Cargo)
  • Optional: LLVM 17 (for native code generation)

Quick Start

Run a Script

# Run a .bobi file
bobi run hello.bobi

# Or simply
bobi hello.bobi

Interactive REPL

bobi repl

Create a New Project

# Create project in new directory
bobi new my_project

# Or initialize in current directory
bobi init

Language Syntax

Bobi uses Python-compatible syntax:

# Variables and basic types
x = 42
y = 3.14
name = "Bobi"
flag = True

# Functions
def add(a, b):
    return a + b

result = add(10, 20)
print(result)  # 30

# Recursion
def fib(n):
    if n <= 1:
        return n
    return fib(n - 1) + fib(n - 2)

print(fib(10))  # 55

# Control flow
x = 15
if x > 20:
    print("big")
elif x > 10:
    print("medium")
else:
    print("small")

# Loops
for i in range(10):
    print(i)

total = 0
while total < 100:
    total = total + 1

# Lists
nums = [1, 2, 3, 4, 5]
for n in nums:
    print(n)

# Type annotations (optional)
def greet(name: str) -> str:
    return "Hello, " + name + "!"

Multi-Threading (No GIL)

Bobi provides true parallel execution without GIL:

import threading

def worker(name, count):
    for i in range(count):
        print(name, i)

# Create threads
t1 = threading.Thread(target=worker, args=("Thread-1", 5))
t2 = threading.Thread(target=worker, args=("Thread-2", 5))

# Start threads (truly parallel!)
t1.start()
t2.start()

# Wait for completion
t1.join()
t2.join()

Synchronization Primitives

import threading

# Lock for mutual exclusion
lock = threading.Lock()
with lock:
    # Critical section
    pass

# RLock (reentrant lock)
rlock = threading.RLock()

# Semaphore
sem = threading.Semaphore(3)

# Event for signaling
event = threading.Event()
event.set()
event.wait()
event.clear()

# Thread-safe Queue
from queue import Queue
q = Queue()
q.put(item)
item = q.get()

Package Manager

Bobi includes a built-in package manager:

# Install a package
bobi pkg install requests

# Install specific version
bobi pkg install numpy --version 1.2.0

# List installed packages
bobi pkg list

# Uninstall a package
bobi pkg uninstall requests

# Install from bobi.toml
bobi pkg sync

# Update packages
bobi pkg update

Project Configuration (bobi.toml)

[package]
name = "my_project"
version = "0.1.0"
authors = ["Your Name"]
description = "My awesome Bobi project"

[dependencies]
requests = "2.0"
numpy = "1.5"

[dev-dependencies]
pytest = "7.0"

CLI Commands

bobi [FILE]              Run a source file directly
bobi run <FILE>          Run a source file
bobi build <FILE>        Compile to bytecode
bobi repl                Start interactive REPL
bobi check <FILE>        Check for errors without running
bobi init                Initialize project in current directory
bobi new <NAME>          Create new project
bobi pkg <COMMAND>       Package manager commands
bobi target list         List available compilation targets

Project Structure

bobi/
├── crates/
│   ├── bobi_cli/        # Command-line interface
│   ├── bobi_lexer/      # Tokenizer
│   ├── bobi_parser/     # Parser (AST generation)
│   ├── bobi_hir/        # High-level IR
│   ├── bobi_typeck/     # Type checking
│   ├── bobi_mir/        # Mid-level IR
│   ├── bobi_bytecode/   # Bytecode compiler & VM
│   ├── bobi_codegen_llvm/  # LLVM backend (optional)
│   ├── bobi_runtime/    # Runtime support
│   ├── bobi_sync/       # Synchronization primitives
│   ├── bobi_channel/    # Channel implementation
│   ├── bobi_parallel/   # Parallel utilities
│   ├── bobi_ffi/        # Foreign function interface
│   ├── bobi_std/        # Standard library
│   ├── bobi_pkg/        # Package manager
│   └── bobi_driver/     # Compilation driver
├── examples/            # Example programs
└── Cargo.toml           # Workspace configuration

Supported Features

Feature Status
Basic arithmetic Done
Variables Done
Functions Done
Recursion Done
if/elif/else Done
for loops Done
while loops Done
Lists Done
Tuples Done
Dictionaries Done
Sets Done
Strings Done
Type annotations Done
Multi-threading Done
Lock/RLock Done
Semaphore/Event Done
Queue Done
Package manager Done
Classes In Progress
Async/await Planned
LLVM codegen Planned

License

MIT OR Apache-2.0

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

About

this is compiler for Bobi language whose sytax is the same as python but GIL

Resources

Stars

Watchers

Forks

Packages

No packages published