๐ง 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 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.
"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.
- 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
- Structured programming constructs (
begin
/end
,if
/then
/else
) - Strong typing with type safety
- Clear procedure/function distinction
- Readable control flow statements
- Direct compilation to efficient machine code via LLVM
- No garbage collection or automatic memory management
- No runtime type information (RTTI)
- Minimal runtime requirements
- 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
- Inline assembly with GCC-compatible extended syntax
- Atomic operations and memory barriers
- Direct hardware access and register manipulation
- Platform-specific optimizations
program HelloWorld;
function printf(const AFormat: PChar, ...): Int32; external;
begin
printf("Hello, World!\n");
end.
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.
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 := $3F800000; // IEEE 754 for 1.0
// LValue.AsFloat is now 1.0
end;
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/
โโโ 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
- 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
- Language Specification - Complete language reference
- BNF Grammar - Formal grammar specification
- Test & Coverage Report - View current test results and feature coverage.
- C Migration Guide - Migrating from C to CPascal
- API Reference - Standard library documentation
- Naming:
L
prefix for locals,A
prefix for parameters - Declarations: Each variable on separate line, no inline
var
- Parameters: Always
const
unlessvar
/out
needed - Testing: Comprehensive tests for all new functionality
- Documentation: Update relevant guides and inline docs
Join our growing community of developers building the future of Pascal development!
This project is licensed under the BSD 3-Clause License - see the LICENSE file for details.
BSD 3-Clause License
Copyright ยฉ 2025-present tinyBigGAMESโข 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.
- ๐ Issues: GitHub Issues - Bug reports & feature requests
- ๐ฌ Discussions: GitHub Discussions - General questions & ideas
- ๐ฌ Discord: Join our community - Real-time chat & support
- ๐ฆ Bluesky: @tinybiggames.com - Updates & announcements
- ๐ 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
- 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 tinyBigGAMESโข
CPascal - Where Pascal meets C, systems programming becomes elegant.