Skip to content

Mehxeo/Sharp---Shattered-Game-Engine

Repository files navigation

Sharp Logo

Sharp Programming Language

A modern, statically-typed language compiled to native code via LLVM. This README is the single source for installation, CLI usage, syntax, types, data structures, and examples — everything a programmer needs to use Sharp.

See the companion engine guide: README_ENGINE.md

Install or Build

  • If published: cargo install sharp
  • From source (macOS example):
    brew install llvm@18
    export LLVM_SYS_180_PREFIX=/opt/homebrew/opt/llvm
    cargo build --release

CLI Usage

# Compile to LLVM IR
./target/release/sharp program.shrp --emit-llvm

# Run LLVM IR (macOS Homebrew LLVM)
/opt/homebrew/opt/llvm@18/bin/lli program.ll

# Check without codegen
./target/release/sharp program.shrp --check

# Emit object file
./target/release/sharp program.shrp --emit-obj -o program.o

# Emit native binary
./target/release/sharp program.shrp --emit-binary -o program

Language Fundamentals

  • Types: int, float, bool, string, void, auto
  • Variables with optional types:
    def main() -> int {
        x: int = 10
        y = 20  // inferred
        return x + y
    }
    
  • Functions:
    def add(a: int, b: int) -> int { return a + b }
    
  • Control Flow: if/elif/else, while, for i in 0 .. N, match
  • Operators: arithmetic, comparison, logical, and compound assignments
  • Printing: print(x) and println(x) support int, bool, and string literals

Data Structures and Methods

Structs

struct Vector2 { x: float, y: float }

struct GameObject {
    position: Vector2
    health: int
    active: bool
}

Impl Blocks and Methods

impl Vector2 {
    def new(x: float, y: float) -> Vector2 {
        return Vector2 { x: x, y: y }
    }
    def magnitude(self) -> float {
        return (self.x * self.x + self.y * self.y).sqrt()
    }
}

impl GameObject {
    def take_damage(mut self, amount: int) { self.health -= amount }
}

Struct Initialization

let pos = Vector2 { x: 10.0, y: 20.0 }
let player = GameObject {
    position: Vector2 { x: 0.0, y: 0.0 },
    health: 100,
    active: true
}

Enums

enum GameState { Loading, MainMenu, Playing, Paused, GameOver }
enum EntityType { Player, Enemy, NPC, Projectile }

Arrays (type annotations)

# [T] or [T; N]
positions: [Vector2; 3]
values: [int]

Syntax Reference (Quick)

def f(a: int) -> int { return a }

def main() -> int {
    total: int = 0
    for i in 0 .. 10 { total += i }
    if total > 20 { return total } else { return 0 }
}

struct Health { current: int, max: int }
impl Health {
    def new(max: int) -> Health { return Health { current: max, max: max } }
    def take_damage(mut self, amount: int) { self.current -= amount }
    def is_alive(self) -> bool { return self.current > 0 }
}

Examples

See the examples directory for runnable programs:

  • examples/hello.shrp
  • examples/simple.shrp
  • examples/advanced.shrp
  • examples/structs.shrp
  • examples/enums.shrp
  • examples/gameobjects.shrp
  • examples/gameobject_simple.shrp

Roadmap

  • Arrays with methods (len/push)
  • String utilities and formatting
  • Traits and generics
  • Pattern matching on enums
  • Standard library (math, collections, io)

Distribution

Sharp availability targets:

  • Cargo: cargo install sharp
  • Homebrew: brew install sharp
  • Docker: docker pull yourusername/sharp
  • GitHub Releases: download binaries

License

MIT License

Contributing

Contributions welcome. Please open issues or PRs.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages