Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

๐Ÿš€ CPascal is a systems programming language that combines Pascal's clean, readable syntax with C's semantic model and full ABI compatibility. โšก Compiles to LLVM with zero runtime overhead, enabling seamless interoperation with any C library without bindings. ๐ŸŽฎ Ideal for game development, ๐Ÿ”ง device drivers, and modernizing C codebases. ๐Ÿ’Ž

License

Notifications You must be signed in to change notification settings

tinyBigGAMES/CPascal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

31 Commits

Repository files navigation

CPascal License CPascal LLVM License

๐Ÿšง CPascal is a Work in Progress

CPascal is currently under active development and evolving quickly. Some features described in this documentation may be incomplete, experimental, or subject to significant changes as the project matures.

We welcome your feedback, ideas, and issue reports โ€” your input will directly influence the direction and quality of CPascal as we strive to build the ultimate modern Pascal development platform.

CPascal

A systems programming language with Pascal syntax and C semantics

CPascal combines the readable syntax of Pascal with the semantic model and binary compatibility of C. It compiles to LLVM IR and maintains full C ABI compatibility, enabling seamless interoperation with existing C libraries and codebases without translation layers or bindings.

๐ŸŽฏ Design Philosophy

"Better C with Pascal Syntax"

CPascal is designed as a modernized systems programming language where every construct maps directly to equivalent C constructs at the binary level. This ensures zero-overhead abstraction and complete compatibility while providing a cleaner, more structured syntax.

โœจ Key Features

๐Ÿ”— Full C ABI Compatibility

  • All data types, function calls, and memory layouts identical to C
  • Direct linking with any C library without bindings
  • Binary-compatible function pointers and structures
  • Identical memory layout and alignment rules

๐Ÿ“ Clean Pascal Syntax

  • Structured programming constructs (begin/end, if/then/else)
  • Strong typing with type safety
  • Clear procedure/function distinction
  • Readable control flow statements

โšก Zero Runtime Overhead

  • Direct compilation to efficient machine code via LLVM
  • No garbage collection or automatic memory management
  • No runtime type information (RTTI)
  • Minimal runtime requirements

๐ŸŒŸ Modern Language Features

  • Multiple Assignment: A, B := GetCoordinates()
  • Ternary Operator: Max := (A > B) ? A : B
  • Compound Assignment: Value += 10, Flags or= 80ใƒ‰ใƒซ
  • Inline Assembly: Extended assembly with input/output constraints
  • Variadic Functions: Full C-style variadic function support
  • Module System: Clean imports without preprocessor complexity

๐ŸŽ›๏ธ Advanced Systems Programming

  • Inline assembly with GCC-compatible extended syntax
  • Atomic operations and memory barriers
  • Direct hardware access and register manipulation
  • Platform-specific optimizations

๐Ÿš€ Quick Start

Hello World

program HelloWorld;
function printf(const AFormat: PChar, ...): Int32; external;
begin
 printf("Hello, World!\n");
end.

Graphics Application

program GraphicsDemo;
import Graphics, Math;
{$LIBPATH /usr/local/lib}
{$LINK SDL2}
{$LINK OpenGL32}
// External SDL2 functions
function SDL_Init(const AFlags: UInt32): Int32; external "SDL2";
function SDL_CreateWindow(const ATitle: PChar; const AX, AY, AW, AH, AFlags: Int32): Pointer; external "SDL2";
const
 SDL_INIT_VIDEO = 00000020ใƒ‰ใƒซ;
 SDL_WINDOW_OPENGL = 00000002ใƒ‰ใƒซ;
var
 Window: Pointer;
 Running: Boolean;
begin
 if SDL_Init(SDL_INIT_VIDEO) <> 0 then
 exit;
 Window := SDL_CreateWindow("CPascal Demo", 100, 100, 800, 600, SDL_WINDOW_OPENGL);
 if Window = nil then
 exit;
 Running := true;
 while Running do
 begin
 // Game loop
 ProcessEvents();
 UpdateGame();
 RenderFrame();
 end;
 SDL_DestroyWindow(Window);
 SDL_Quit();
end.

Advanced Features

module DataStructures;
// Multiple assignment
function GetCoordinates(): (Int32, Int32);
begin
 Result := (100, 200);
end;
// Ternary operator and compound assignment
function ProcessData(const AValues: ^Int32; const ACount: Int32): Int32;
var
 LIndex, LSum, LMax: Int32;
begin
 LSum := 0;
 LMax := 0;
 for LIndex := 0 to ACount - 1 do
 begin
 LSum += AValues[LIndex]; // Compound assignment
 LMax := (AValues[LIndex] > LMax) ? AValues[LIndex] : LMax; // Ternary
 end;
 Result := LSum;
end;
// Inline assembly with constraints
function AtomicIncrement(const APtr: ^Int32): Int32; inline;
begin
 asm
 "lock incl %1"
 "movl %1, %0"
 : "=r" (Result) // Output: register
 : "m" (APtr^) // Input: memory location
 : "memory" // Clobbered: memory
 end;
end;
// Union types
type
 TValue = union
 AsInt: Int32;
 AsFloat: Single;
 AsBytes: array[0..3] of UInt8;
 end;
var
 LValue: TValue;
begin
 LValue.AsInt := 3ใƒ‰ใƒซF800000; // IEEE 754 for 1.0
 // LValue.AsFloat is now 1.0
end;

๐Ÿ“Š C ABI Type Mapping

CPascal Type C Equivalent Size Description
Int8 int8_t 1 Signed 8-bit integer
UInt8 uint8_t 1 Unsigned 8-bit integer
Int32 int32_t 4 Signed 32-bit integer
UInt32 uint32_t 4 Unsigned 32-bit integer
Int64 int64_t 8 Signed 64-bit integer
Single float 4 IEEE 754 single precision
Double double 8 IEEE 754 double precision
Boolean bool 1 C99 boolean
Pointer void* 8/4 Platform pointer
PChar char* 8/4 Null-terminated string

All record types map to C structs with identical layout and alignment.

๐Ÿ—๏ธ Project Structure

project/
โ”œโ”€โ”€ src/
โ”‚ โ”œโ”€โ”€ main.cpas # Program entry point
โ”‚ โ”œโ”€โ”€ graphics.cpas # Graphics module
โ”‚ โ”œโ”€โ”€ audio.cpas # Audio module
โ”‚ โ””โ”€โ”€ platform/
โ”‚ โ”œโ”€โ”€ windows.cpas # Platform-specific code
โ”‚ โ”œโ”€โ”€ linux.cpas
โ”‚ โ””โ”€โ”€ macos.cpas
โ”œโ”€โ”€ lib/
โ”‚ โ”œโ”€โ”€ SDL2.lib # External libraries
โ”‚ โ””โ”€โ”€ OpenGL32.lib
โ””โ”€โ”€ build/
 โ”œโ”€โ”€ obj/ # Compiled objects
 โ””โ”€โ”€ bin/ # Final executables

๐ŸŽฏ Target Applications

  • Systems Programming: Device drivers, OS components
  • Game Development: High-performance game engines
  • Embedded Systems: Microcontroller programming
  • Performance-Critical Applications: Real-time systems
  • C Codebase Modernization: Gradual migration from C

๐Ÿ“š Documentation

๐Ÿ“‹ Coding Standards

  • Naming: L prefix for locals, A prefix for parameters
  • Declarations: Each variable on separate line, no inline var
  • Parameters: Always const unless var/out needed
  • Testing: Comprehensive tests for all new functionality
  • Documentation: Update relevant guides and inline docs

๐Ÿ† Contributors

Join our growing community of developers building the future of Pascal development!

๐Ÿ“„ License

This project is licensed under the BSD 3-Clause License - see the LICENSE file for details.

BSD 3-Clause License
Copyright ยฉ 2025-present tinyBigGAMESTM LLC
All Rights Reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice
2. Redistributions in binary form must reproduce the above copyright notice
3. Neither the name of the copyright holder nor the names of its contributors
 may be used to endorse or promote products derived from this software
 without specific prior written permission.

๐Ÿ“ž Support & Community

๐Ÿ’ฌ Community Channels

๐ŸŒŸ Acknowledgments

  • ๐Ÿ’– Built with love for the Delphi community
  • ๐ŸŽฏ Inspired by Pascal's readable syntax and C's systems programming power
  • ๐Ÿš€ Focused on practical, real-world usage scenarios
  • ๐Ÿ† Committed to enterprise-grade quality and performance
  • ๐ŸŒ Supporting the future of Pascal application development

๐ŸŽ–๏ธ Special Thanks

  • Delphi Community - For continued support and feedback
  • Beta Testers - Early adopters who helped shape CPascal
  • Contributors - Everyone who has submitted issues, PRs, and improvements

Made with โค๏ธ by tinyBigGAMESTM

CPascal - Where Pascal meets C, systems programming becomes elegant.

About

๐Ÿš€ CPascal is a systems programming language that combines Pascal's clean, readable syntax with C's semantic model and full ABI compatibility. โšก Compiles to LLVM with zero runtime overhead, enabling seamless interoperation with any C library without bindings. ๐ŸŽฎ Ideal for game development, ๐Ÿ”ง device drivers, and modernizing C codebases. ๐Ÿ’Ž

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published

Contributors 3

AltStyle ใซใ‚ˆใฃใฆๅค‰ๆ›ใ•ใ‚ŒใŸใƒšใƒผใ‚ธ (->ใ‚ชใƒชใ‚ธใƒŠใƒซ) /