Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.

Commit 9d32f61

Browse files
committed
Release v0.4.0: Real-World Usage
NitroPascal v0.4.0 delivers the features that matter for building real applications in production: function pointers for callbacks, structured RTL modules (Types, SysUtils, StrUtils, DateUtils), static library linking (demonstrated with raylib), comprehensive benchmarking suite, and dramatically expanded runtime capabilities. KEY MILESTONE: NitroPascal now demonstrates REAL-WORLD VIABILITY. Static link raylib for game development. Compare performance against Delphi with included benchmarks. Structure your code with standard Pascal RTL modules. Build production software with a mature, organized runtime library. FUNCTION POINTERS (PROCEDURAL TYPES): - Procedural type declarations (type TCallback = procedure(X: Integer)) - Function variable assignments - Callback patterns for event handling - Higher-order functions and functional programming - Framework integration hooks - Plugin architectures - Event-driven programming patterns STRUCTURED RTL MODULES: - System.Types - Base type declarations and utilities - System.SysUtils - System utilities and conversions - System.StrUtils - String manipulation utilities - System.DateUtils - Date/time functions (foundation) - Organized, discoverable API surface - Standard Pascal module structure - Clear separation of concerns - Professional codebase organization STATIC LIBRARY LINKING: - Link against static libraries (.lib/.a files) - Demonstrated with raylib game development library - Zero-overhead integration with C/C++ libraries - Single-executable deployment (no DLL dependencies) - Complete control over dependencies - Simplified distribution ENHANCED STRING LIBRARY: - StringOfChar(Ch, Count) - Create repeated character strings - UniqueString(S) - Ensure unique string reference - SetString(S, Buffer, Len) - Direct buffer to string - Val(S, V, Code) - String to numeric with error code - Str(X, S) - Numeric to string (legacy compatibility) - UpCase(Ch) - Single character uppercase - WideCharLen(S) - Wide string length - WideCharToString(S) - Convert wide to string - StringToWideChar(S, Buf, BufSize) - String to wide buffer - WideCharToStrVar(S, Dest) - Wide to string variable - Complete wide character support for Unicode EXPANDED MATH LIBRARY: - Logarithms: Ln(X), Log10(X), Log2(X), LogN(Base, X) - Exponential: Exp(X), Power(Base, Exponent) - Integer/fractional: Int(X), Frac(X) - Hyperbolic trig: Sinh(X), Cosh(X), Tanh(X) - Inverse hyperbolic: ArcSinh(X), ArcCosh(X), ArcTanh(X) - Mathematical constant: Pi - ArcTan2(Y, X) for proper angle calculations - Scientific computing capabilities - Complete mathematical toolkit ENHANCED FILE I/O: - Read(F, Var) - Read from text file to variable - Eoln(F) - Test for end of line in text file - SeekEof(F) - Skip whitespace, test for EOF - SeekEoln(F) - Skip whitespace, test for EOL - Flush(F) - Force write buffer to disk - Truncate(F) - Truncate file at current position - Erase(F) - Delete closed file - Rename(F, NewName) - Rename closed file - IOResult - Get last I/O error code - Complete Delphi file I/O compatibility ENHANCED MEMORY FUNCTIONS: - AllocMem(Size) - Allocate zero-filled memory - FillByte(Dest, Count, Value) - Fill byte array - FillWord(Dest, Count, Value) - Fill word array - FillDWord(Dest, Count, Value) - Fill dword array - Efficient bulk memory operations - Type-specific fill operations ENHANCED ORDINAL FUNCTIONS: - Odd(X) - Test if integer is odd - Swap(X) - Swap byte order (endianness) - Byte manipulation utilities PLATFORM SERVICES: - RunError(ErrorCode) - Terminate with error code - Abort - Terminate with exception - Enhanced program control CODE GENERATION IMPROVEMENTS: - Line number directives (#line) for debugging - Source position tracking in generated code - Better debuggability - Improved error messages with source locations COMPILER DIRECTIVES: - {$include_header 'filename'} - Include C/C++ headers directly - Seamless integration with native libraries - Direct access to platform APIs BENCHMARK SUITE: - Comprehensive performance comparison: NitroPascal vs Delphi - Real-world test scenarios - Quantifiable performance metrics - Optimization validation - Demonstrates competitive performance ENHANCED C++ RUNTIME: - Expanded standard library wrappers - More complete RTL implementation - Better Delphi compatibility - Optimized performance paths BUILD SYSTEM ENHANCEMENTS: - Static library linking support - Improved dependency management - Better library path resolution - Cross-platform static linking REAL-WORLD DEMONSTRATIONS: - Raylib integration example (static linking) - Game development capabilities - High-performance graphics - Professional library integration - Production-ready examples This release proves NitroPascal's real-world viability. With function pointers for callbacks, structured RTL modules for organization, static linking for deployment simplicity, and comprehensive benchmarks showing competitive performance, you can confidently build production applications. THE REAL-WORLD MILESTONE: NitroPascal isn't just production-ready - it's production-proven. Static link libraries like raylib. Write callbacks and event handlers with function pointers. Structure your code with standard Pascal modules. Compare performance directly against Delphi. Ship real applications with confidence. Write once in pure Delphi. Link static libraries. Ship single executables. Run everywhere. Version: 0.4.0
1 parent 82e3fd7 commit 9d32f61

File tree

109 files changed

+13187
-1222
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+13187
-1222
lines changed

.gitignore

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ modules/
8484
# NitroPascal
8585
bin/res/*
8686
!bin/res/.gitkeep
87-
bin/projects/*
88-
!bin/projects/.gitkeep
87+
#bin/projects/*
88+
#!bin/projects/.gitkeep
8989
checkpoint.zip
9090
_checkpoint.cmd
9191
bin/run_unittests.cmd
@@ -99,3 +99,8 @@ src/TASK.md
9999
src/TASK0.md
100100
src/TASK2.md
101101
checkpoint_base.zip
102+
docs/BENCHMARK.pdf
103+
docs/COVERAGE.pdf
104+
docs/DESIGN.pdf
105+
docs/MANUAL.pdf
106+
bin/tests/*

bin/projects/NPBench/build.zig

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const std = @import("std");
2+
3+
pub fn build(b: *std.Build) void {
4+
const target = b.standardTargetOptions(.{});
5+
const optimize = .ReleaseFast;
6+
7+
// Create module for C++ sources
8+
const module = b.addModule("NPBench", .{
9+
.target = target,
10+
.optimize = optimize,
11+
.link_libc = true,
12+
});
13+
14+
// C++ compiler flags
15+
const cpp_flags = [_][]const u8{
16+
"-std=c++20",
17+
};
18+
19+
// Add all generated C++ files
20+
module.addCSourceFile(.{
21+
.file = b.path("generated/NPBench.cpp"),
22+
.flags = &cpp_flags,
23+
});
24+
module.addCSourceFile(.{
25+
.file = b.path("generated/UNPBench.cpp"),
26+
.flags = &cpp_flags,
27+
});
28+
29+
// Add runtime source
30+
module.addCSourceFile(.{
31+
.file = b.path("runtime/runtime.cpp"),
32+
.flags = &cpp_flags,
33+
});
34+
35+
module.addIncludePath(b.path("runtime"));
36+
37+
// Create executable
38+
const exe = b.addExecutable(.{
39+
.name = "NPBench",
40+
.root_module = module,
41+
});
42+
43+
// Link C++ standard library
44+
exe.linkLibCpp();
45+
46+
b.installArtifact(exe);
47+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* NitroPascal Runtime Library - Implementation
3+
*
4+
* This file includes all implementation modules.
5+
* Each module contributes implementation as needed.
6+
*
7+
* Version: 1.0
8+
* Date: 2025-10-15
9+
*/
10+
11+
#include "runtime.h"
12+
13+
// ============================================================================
14+
// MODULE IMPLEMENTATIONS IN DEPENDENCY ORDER
15+
// ============================================================================
16+
17+
#include "runtime_string.cpp"
18+
#include "runtime_console.cpp"
19+
#include "runtime_control.cpp"
20+
#include "runtime_operators.cpp"
21+
#include "runtime_ordinal.cpp"
22+
#include "runtime_containers.cpp"
23+
#include "runtime_memory.cpp"
24+
#include "runtime_math.cpp"
25+
#include "runtime_file.cpp"
26+
#include "runtime_exceptions.cpp"
27+
#include "runtime_cmdline.cpp"
28+
#include "runtime_format.cpp"
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/**
2+
* NitroPascal Runtime Library
3+
*
4+
* This is the C++ Runtime Library (RTL) that provides Delphi/Object Pascal
5+
* semantics in C++20. The code generator emits calls to these functions
6+
* and classes, making code generation trivial.
7+
*
8+
* Key Design Principles:
9+
* - All Delphi semantics are wrapped in C++ functions/classes
10+
* - Code generator just emits function calls (simple syntax translation)
11+
* - All complexity lives here (written once, correct once)
12+
* - Uses C++20 features (fold expressions, concepts, etc.)
13+
*
14+
* Module Organization:
15+
* - runtime_types.h: Core type aliases
16+
* - runtime_operators_custom.h: Custom output operators (before namespace)
17+
* - runtime_string.h/cpp: String class and utilities
18+
* - runtime_console.h/cpp: Console I/O
19+
* - runtime_control.h/cpp: Control flow (for, while, repeat)
20+
* - runtime_operators.h/cpp: Arithmetic operators (div, mod, shl, shr)
21+
* - runtime_ordinal.h/cpp: Ordinal functions (Ord, Chr, Succ, Pred, Inc, Dec)
22+
* - runtime_containers.h/cpp: DynArray<T>, Set<T>
23+
* - runtime_memory.h/cpp: Memory management (New, Dispose, GetMem, Move)
24+
* - runtime_math.h/cpp: Math functions (Abs, Sqrt, Sin, Cos, etc.)
25+
* - runtime_file.h/cpp: File I/O (Text, Binary files)
26+
* - runtime_exceptions.h/cpp: Exception handling
27+
* - runtime_cmdline.h/cpp: Command line parameters
28+
* - runtime_format.h/cpp: String formatting
29+
*
30+
* Version: 1.0
31+
* Date: 2025-10-15
32+
*/
33+
34+
#pragma once
35+
36+
// ============================================================================
37+
// GLOBAL INCLUDES (required before np namespace)
38+
// ============================================================================
39+
40+
#include <iostream>
41+
#include <string>
42+
#include <functional>
43+
#include <cstdint>
44+
#include <vector>
45+
#include <unordered_set>
46+
#include <memory>
47+
#include <sstream>
48+
#include <iomanip>
49+
#include <stdexcept>
50+
#include <cassert>
51+
#include <array>
52+
#include <cstring>
53+
#include <cmath>
54+
#include <cstdlib>
55+
#include <ctime>
56+
#include <fstream>
57+
#include <sys/stat.h>
58+
#include <algorithm>
59+
60+
61+
62+
// ============================================================================
63+
// MODULAR INCLUDES IN DEPENDENCY ORDER
64+
// ============================================================================
65+
66+
#include "runtime_types.h"
67+
#include "runtime_operators_custom.h"
68+
#include "runtime_string.h"
69+
#include "runtime_console.h"
70+
#include "runtime_control.h"
71+
#include "runtime_operators.h"
72+
#include "runtime_ordinal.h"
73+
#include "runtime_containers.h"
74+
#include "runtime_memory.h"
75+
#include "runtime_math.h"
76+
#include "runtime_file.h"
77+
#include "runtime_exceptions.h"
78+
#include "runtime_cmdline.h"
79+
#include "runtime_format.h"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* NitroPascal Runtime - Command Line Implementation
3+
*/
4+
5+
#include "runtime_cmdline.h"
6+
7+
namespace np {
8+
9+
// Command line functions are header-only
10+
11+
} // namespace np
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* NitroPascal Runtime - Command Line Parameters
3+
*/
4+
5+
#pragma once
6+
7+
#include "runtime_types.h"
8+
#include "runtime_string.h"
9+
10+
namespace np {
11+
12+
// ============================================================================
13+
// COMMAND LINE PARAMETERS
14+
// ============================================================================
15+
16+
inline int _argc = 0;
17+
inline char** _argv = nullptr;
18+
19+
inline void InitCommandLine(int argc, char* argv[]) {
20+
_argc = argc;
21+
_argv = argv;
22+
}
23+
24+
inline Integer ParamCount() {
25+
return _argc - 1;
26+
}
27+
28+
inline String ParamStr(const Integer AIndex) {
29+
if (AIndex < 0 || AIndex >= _argc) {
30+
return String(u"");
31+
}
32+
return String(_argv[AIndex]);
33+
}
34+
35+
} // namespace np
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* NitroPascal Runtime - Console I/O Implementation
3+
*/
4+
5+
#include "runtime_console.h"
6+
7+
#ifdef _WIN32
8+
#include <windows.h>
9+
#include <io.h>
10+
#include <fcntl.h>
11+
#endif
12+
13+
namespace np {
14+
15+
void InitializeConsole() {
16+
#ifdef _WIN32
17+
SetConsoleOutputCP(CP_UTF8);
18+
SetConsoleCP(CP_UTF8);
19+
_setmode(_fileno(stdout), _O_BINARY);
20+
_setmode(_fileno(stderr), _O_BINARY);
21+
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
22+
if (hOut != INVALID_HANDLE_VALUE) {
23+
DWORD dwMode = 0;
24+
if (GetConsoleMode(hOut, &dwMode)) {
25+
dwMode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
26+
SetConsoleMode(hOut, dwMode);
27+
}
28+
}
29+
#endif
30+
}
31+
32+
} // namespace np
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* NitroPascal Runtime - Console I/O
3+
*/
4+
5+
#pragma once
6+
7+
#include "runtime_types.h"
8+
#include "runtime_operators_custom.h"
9+
#include "runtime_string.h"
10+
#include <iostream>
11+
12+
namespace np {
13+
14+
// ============================================================================
15+
// CONSOLE INITIALIZATION
16+
// ============================================================================
17+
18+
void InitializeConsole();
19+
20+
// ============================================================================
21+
// I/O FUNCTIONS
22+
// ============================================================================
23+
24+
template<typename... Args>
25+
void Write(Args&&... args) {
26+
std::cout << std::boolalpha;
27+
(std::cout << ... << std::forward<Args>(args));
28+
}
29+
30+
template<typename... Args>
31+
void WriteLn(Args&&... args) {
32+
std::cout << std::boolalpha;
33+
(std::cout << ... << std::forward<Args>(args));
34+
std::cout << std::endl;
35+
}
36+
37+
inline void WriteLn() {
38+
std::cout << std::endl;
39+
}
40+
41+
template<typename T>
42+
void ReadLn(T& value) {
43+
std::cin >> value;
44+
}
45+
46+
inline void ReadLn(String& value) {
47+
std::string line;
48+
std::getline(std::cin, line);
49+
value = String(line);
50+
}
51+
52+
} // namespace np
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* NitroPascal Runtime - Containers Implementation
3+
*/
4+
5+
#include "runtime_containers.h"
6+
7+
namespace np {
8+
9+
// Containers are header-only (templates)
10+
11+
} // namespace np

0 commit comments

Comments
 (0)