Вирт - русифицированный паскаль. A modern, self-hosting Object Pascal compiler built for the 2020s. Zero legacy, full ARC, and unified UTF-8.
Find a file
Graeme Geldenhuys dade93c7cc feat(rtl): Phase 5 streams — CopyStream + capability markers; interface ABI fixes
Adds CopyStream(Src: TInputStream; Dst: TOutputStream): Int64 — the
free function callers reach for whenever they want to drain one stream
into another.  Discovers capability at runtime in this preference order:

  1. Dst implements IReaderFrom  → dispatch to Dst.ReadFrom(Src).
  2. Src implements IWriterTo    → dispatch to Src.WriteTo(Dst).
  3. Fallback: 8 KiB byte-loop through a stack buffer.

The two marker interfaces ship empty in v1 — no concrete fast-path
implementations yet.  Adding IReaderFrom to TFileOutputStream (with
sendfile(2) on Linux) or IWriterTo to TBuffer (with TransferTo) is a
future, non-breaking change: existing CopyStream callers automatically
pick up the speedup.  This is the Go io.Copy idiom.

Streams unit cleanup: every concrete class now explicitly lists the
interfaces it implements (IInputStream / IOutputStream / ICloseable),
which was missing in earlier phases.  Required for the new
Supports() queries to work correctly.

Compiler fixes — interface ABI and arg analysis:

  * AnalyseMethodCall (statement form): the tyInterface branch never
    called AnalyseExpr on argument expressions, so codegen later
    crashed when an arg like @Buf[0] referenced a TIdentExpr with
    nil ResolvedType.  Fixed by calling AnalyseExpr on each arg
    (overload validation isn't possible without param info, but
    type resolution is needed).

  * Interface parameters now use a two-slot fat-pointer ABI:
    `function F(I: IFoo)` lowers to `function $F(l %_par_I_obj, l
    %_par_I_itab)`, with matching `_var_I_obj` / `_var_I_itab`
    local slots in the prologue.  Call sites for TIdentExpr args
    decompose `Os` into `l (loadl _var_Os_obj), l (loadl
    _var_Os_itab)`.  Previously interface params were emitted as a
    single `w` slot (QBE rejected the storel into them).

    Remaining gap: non-identifier interface arguments (function
    returns, casts, field accesses) raise ECodeGenError with a
    clear message.  Tracked in the project's perf-focus memory note.

Test coverage: four new e2e cases —
  * Interface dispatch via Supports (the inline Phase 1 workaround
    pattern, now using real interface dispatch).
  * Interface as function parameter (exercises the new ABI).
  * CopyStream memory → memory and file → file (both through the
    fallback byte-loop path).

Suite is now 1868 (was 1864); ./scripts/fixpoint.sh clean.
2026-05-15 00:54:27 +01:00
.github Add Patreon funding configuration 2026-05-13 08:54:21 +01:00
compiler feat(rtl): Phase 5 streams — CopyStream + capability markers; interface ABI fixes 2026-05-15 00:54:27 +01:00
docs feat(parser): array-of-enum typed constants 2026-05-14 16:33:59 +01:00
plugins chore(license): relicense from BSD-3-Clause to Apache 2.0 + Runtime Library Exception 2026-05-03 19:45:29 +01:00
rtl feat(rtl): Phase 5 streams — CopyStream + capability markers; interface ABI fixes 2026-05-15 00:54:27 +01:00
scripts fix(fixpoint): add stage-4 fallback for cross-release bootstrap gaps 2026-05-13 00:38:23 +01:00
tests chore(license): relicense from BSD-3-Clause to Apache 2.0 + Runtime Library Exception 2026-05-03 19:45:29 +01:00
tools fix: we don't have any code for migration-analyser yet. Disable tests for it. 2026-05-08 00:52:44 +01:00
vendor/qbe fix(rebased): resolve conflicts and make bcl.testing compile under Blaise 2026-05-12 19:28:11 +01:00
.gitignore feat(rtl): Step 6 — pure Pascal StrUtils + ExpandFileName in SysUtils 2026-05-14 10:33:38 +01:00
LICENSE chore(license): relicense from BSD-3-Clause to Apache 2.0 + Runtime Library Exception 2026-05-03 19:45:29 +01:00
NOTICE chore(license): relicense from BSD-3-Clause to Apache 2.0 + Runtime Library Exception 2026-05-03 19:45:29 +01:00
project.xml chore: bump version to 0.8.0-dev 2026-05-13 00:50:08 +01:00
README.adoc feat(class): abstract methods and abstract classes 2026-05-14 21:17:19 +01:00

= Blaise Pascal Compiler
:icons: font
:source-highlighter: rouge

**The Pascal you love, reimagined for the modern era.**

Blaise is a next-generation Object Pascal compiler built from the ground up to eliminate decades of legacy baggage. It prioritizes developer productivity, memory safety, and high-performance execution.


== ✨ The Vision

The Object Pascal ecosystem has two options: Embarcadero Delphi (proprietary,
Windows-first) and Free Pascal (open source but carrying 30 years of accumulated
complexity — five language modes, five string types, and thousands of include files).

This compiler takes a different approach:

* *One language mode.* No `{$mode}` switches; no legacy dialect support.
* *One string type.* UTF-8 reference-counted string and 0-based indexing. `RawBytes` for binary data.
* *One memory model.* Automatic reference counting applies uniformly to
  strings, classes, and interfaces. No manual/auto split between `TObject`
  and `TInterfacedObject`; `[Weak]` breaks cycles. `Free` is retained as a
  synonym for immediate release.
* *Clean interfaces.* No COM GUIDs; interface dispatch via compile-time vtable mapping.
* *Reified generics.* Monomorphization at compile time — no type erasure.
* *Modern build system.* PasBuild with `project.xml`; no makefiles.
* *First-class debugger.* OPDF is the default debug format; DWARF is not required.

See link:docs/design.adoc[docs/design.adoc] for the full architecture and
implementation plan.

The result — A modern, cross-platform Object Pascal compiler targeting native code via
https://c9x.me/compile/[QBE] (and eventually LLVM). Single language mode,
single string type, zero-GUID interfaces, reified generics, and first-class
https://github.com/graemeg/opdebugger[OPDF] debug format support.


== 🚀 Project Status

* **Self-Hosting:** Yes. Blaise bootstraps and recompiles itself with byte-for-byte fixpoint. FPC is no longer required — the entire toolchain runs on Blaise alone.
* **Testing:** 1846 tests and growing (Test-Driven Development from day one). The test suite itself compiles under Blaise.
* **Backends:** Currently utilising a QBE backend, with an LLVM backend in active development.


[cols="1,3,1", options="header"]
|===
| Phase | Goal | Status

| 1
| Bootstrap pipeline — Hello World on Linux x86_64 via PasBuild
| Complete ✅

| 2
| Type system — classes, records, ARC, exceptions
| Complete ✅

| 3
| Generics + zero-GUID interfaces
| Complete ✅

| 4
| OPDF debug info emission
| Complete ✅

| 5
| Self-hosting + LLVM + Windows + macOS ARM64
| In-Progress

| 6
| LSP + VS Code extension
| Planned

| 7
| Migration analyser for FPC/Delphi codebases
| Planned
|===

== What Is Dropped From Classic Pascal

[cols="1,3", options="header"]
|===
| Feature | Reason for removal

| `ShortString`, `AnsiString`, `WideString`, `UnicodeString`
| Replaced by a single UTF-8 reference-counted `string` type

| `with` statement
| Source of hard-to-diagnose symbol resolution bugs; breaks static analysis

| Old-style `object` types
| Use `record` (stack/value) or `class` (heap/reference) instead

| COM-style interface GUIDs
| Interface dispatch via compile-time vtable; GUIDs are unnecessary complexity

| Multiple language modes
| One dialect, maintained well, beats five dialects maintained poorly

| `assign`, `reset`, `rewrite`, `blockread`
| Replaced by a stream-based I/O RTL

| `TObject` vs `TInterfacedObject` split
| One unified class model under automatic reference counting; `[Weak]`
  breaks cycles
|===

== 📢 Community

The core architecture is still being finalised, so the project is not yet
accepting code contributions. Feedback on language design, syntax choices, and
the future direction of Blaise is very welcome — please use the
https://github.com/graemeg/blaise/discussions[Discussions] tab on GitHub.


== Repository Layout

This project uses PasBuild's multi-module layout. Each subdirectory with a
`project.xml` is an independent module; the root `project.xml` is the aggregator.

....
project.xml                       Root aggregator (packaging=pom)
│
├── compiler/                     The compiler binary (packaging=application)
│   ├── project.xml
│   └── src/
│       ├── main/pascal/          uLexer, uParser, uAST, uCodeGenQBE, ...
│       └── test/pascal/          Test suite (bcl.testing, compiled by Blaise)
│
├── rtl/                          Runtime library (packaging=library)
│   ├── project.xml
│   └── src/
│       ├── main/pascal/          System.pas, SysUtils.pas, Classes.pas, ...
│       └── test/pascal/          RTL test suite (punit, compiled by Blaise)
│
├── tools/
│   └── migration-analyser/       FPC/Delphi migration report tool (packaging=application)
│       ├── project.xml           depends on compiler module
│       └── src/
│           ├── main/pascal/
│           └── test/pascal/
│
├── vendor/qbe/                   Vendored QBE backend source (pinned, built from source)
└── docs/                         Design documents and specifications
....

PasBuild compiles each module to its own `target/` subdirectory. Build output is
never committed to the repository.

== Building

=== Prerequisites

* A previously released Blaise binary (see `releases/`)
* https://github.com/graemeg/pasbuild[PasBuild]
* A C compiler (`gcc` or `clang`) for building the vendored QBE backend and linking
* GNU `make` for the RTL build

NOTE: FPC is *not* required. Blaise is fully self-hosting — each release binary
compiles the next version. The bootstrap chain starts from the binary in
`releases/`.

=== Bootstrap from a release

The RTL build compiles its Pascal units (`blaise_str.pas`, `blaise_arc.pas`,
`blaise_sys.pas`) using the Blaise binary at `compiler/target/blaise`. On a
clean checkout that binary does not exist yet, so the release binary must be
passed explicitly via the `BLAISE` make variable.

[source,shell]
----
# 0. Build the vendored QBE backend (once-off — not needed again unless
#    you update vendor/qbe/)
cd vendor/qbe && make && cd ../..

# 1. Build the RTL using the release binary (BLAISE= avoids chicken-and-egg)
cd rtl && make BLAISE=../releases/v0.7.0/blaise && make install && cd ..

# 2. Compile the compiler using the latest release binary
releases/v0.7.0/blaise \
  --source compiler/src/main/pascal/Blaise.pas \
  --unit-path compiler/src/main/pascal \
  --unit-path rtl/src/main/pascal \
  --emit-ir > /tmp/blaise.ssa

# 3. Assemble and link
vendor/qbe/qbe -o /tmp/blaise.s /tmp/blaise.ssa
gcc -o compiler/target/blaise /tmp/blaise.s compiler/target/blaise_rtl.a
----

Once `compiler/target/blaise` exists, subsequent RTL rebuilds (`make && make install`)
work without the override. The QBE build in step 0 is a one-off and does not
need to be repeated when rebuilding the compiler.

=== Build via PasBuild

PasBuild can drive the full compile and test cycle using a Blaise binary:

[source,shell]
----
pasbuild compile -m blaise-compiler --compiler compiler/target/blaise
pasbuild test -m blaise-compiler --compiler compiler/target/blaise
----

=== Run tests

[source,shell]
----
pasbuild test -m blaise-compiler --compiler compiler/target/blaise
----

=== Verify self-hosting fixpoint

After any compiler change, verify that the compiler reproduces itself:

[source,shell]
----
./scripts/fixpoint.sh
----

This generates stage-2 and stage-3 IR and confirms they are identical.

=== Running the compiler

Once built, the compiler binary is at `compiler/target/blaise`.

[source,shell]
----
# Compile a single-file program
compiler/target/blaise --source Hello.pas --emit-ir > Hello.ssa
vendor/qbe/qbe -o Hello.s Hello.ssa
gcc -o Hello Hello.s compiler/target/blaise_rtl.a

# Compile with unit search paths
compiler/target/blaise --source MyApp.pas \
  --unit-path src/units \
  --emit-ir > MyApp.ssa

# Emit QBE IR only (useful for debugging the compiler itself)
compiler/target/blaise --source Hello.pas --emit-ir
----

== Licence

Apache License v2.0 with Runtime Library Exception. See link:LICENSE[LICENSE].


---
*Built with ❤️ for the Pascal community by Graeme.*