2026-05-03 21:45:29 +03:00
|
|
|
#
|
|
|
|
|
# Blaise — An Object Pascal Compiler
|
|
|
|
|
# Copyright (c) 2026 Graeme Geldenhuys
|
|
|
|
|
# SPDX-License-Identifier: Apache-2.0 WITH Swift-exception
|
|
|
|
|
# Licensed under the Apache License v2.0 with Runtime Library Exception.
|
|
|
|
|
# See LICENSE file in the project root for full license terms.
|
|
|
|
|
#
|
2026-07-04 21:44:54 +03:00
|
|
|
# Each Pascal unit is compiled directly via Blaise's unit-as-top-level
|
|
|
|
|
# mode (project_unit_as_toplevel, 2026-05-24): a single
|
|
|
|
|
# `blaise --source X.pas --output X.o` invocation runs qbe + cc -c
|
|
|
|
|
# + objcopy-embed in one step. No build-driver shims, no IR-strip
|
|
|
|
|
# sed pipelines, no intermediate .ssa/.s files needed.
|
2026-05-22 17:39:08 +03:00
|
|
|
SHELL = /bin/bash
|
|
|
|
|
|
2026-07-04 21:44:54 +03:00
|
|
|
CC = gcc
|
|
|
|
|
CFLAGS = -O2 -Wall -Wextra -std=c11
|
|
|
|
|
|
|
|
|
|
SRC_DIR = src/main/c
|
|
|
|
|
PAS_SRC_DIR = src/main/pascal
|
|
|
|
|
ASM_DIR = src/main/asm
|
2026-05-01 16:42:29 +03:00
|
|
|
OBJ_DIR = target
|
|
|
|
|
LIB = $(OBJ_DIR)/blaise_rtl.a
|
Add Phase 2: record/class types, ARC strings, RTL stubs, and grammar doc
Symbol table:
- Added tyClass kind and NewClassType factory; TRecordTypeDesc now
accepts an optional kind parameter so records and classes share the
same descriptor with distinct semantics.
Semantic analyser:
- AnalyseTypeDecls runs before PushScope so type symbols land in global
scope and survive PopScope.
- Handles TRecordTypeDef and TClassTypeDef; sets IsConstructorCall on
TypeName.Create expressions and IsClassAccess on class-variable field
access and assignment nodes.
Code generator (QBE IR):
- Class variables: 8-byte pointer slot, zeroed on entry.
- Constructor calls: malloc(sizeof fields), store pointer.
- Class field access/write: load pointer, add field offset, load/store.
- ARC string assignment: AddRef new value, Release old value, then store.
- Block exit: Release every string variable in scope (EmitStringCleanup).
Lexer / Parser / AST:
- Added tkClass keyword and ParseClassDef; FieldDecl parsing refactored
into ParseFieldDecl(AFields) shared by both record and class.
- AST gains TClassTypeDef, and IsConstructorCall/IsClassAccess flags on
TFieldAccessExpr and TFieldAssignment.
RTL:
- blaise_arc.c: Phase 2 no-op stubs for _StringAddRef / _StringRelease.
- rtl/Makefile: builds blaise_rtl.a; `make install` copies it next to
the compiler binary for automatic discovery by FindRTL.
- Blaise.pas driver: FindRTL checks BLAISE_RTL env var then binary dir;
links the RTL archive when present.
Tests:
- 180 unit tests (records ×23, classes ×22, ARC ×9, codegen ×9, …).
- 4 end-to-end integration tests in tests/integration/test_arc_strings.sh
covering string assignment, two-var cleanup, reassignment cycle, and
empty-program linkage.
Docs:
- design.adoc updated with Phase 2 implementation status table.
- docs/grammar.ebnf: new authoritative EBNF grammar for the Blaise
language as implemented, including ARC semantic annotations.
2026-04-20 21:04:12 +03:00
|
|
|
|
|
|
|
|
# Where the compiler binary lives — install copies the RTL there so the
|
|
|
|
|
# driver finds it automatically next to itself.
|
2026-04-24 19:42:54 +03:00
|
|
|
COMPILER_BIN = ../compiler/target
|
2026-05-01 16:42:29 +03:00
|
|
|
BLAISE = $(COMPILER_BIN)/blaise
|
2026-07-04 21:44:54 +03:00
|
|
|
# This Makefile IS a hand-managed separate-compilation system: it compiles each
|
|
|
|
|
# RTL unit to its own object and archives an explicit object list. The
|
|
|
|
|
# compiler's own incremental mode (now the default) would, on top of that, write
|
|
|
|
|
# per-dependency side-effect .o files next to each output and skip inlining a
|
|
|
|
|
# used unit's bodies — but those side-effect objects are not in the archive's
|
|
|
|
|
# object list, so a cross-unit symbol (e.g. typeinfo_TRtlPlatform, referenced by
|
|
|
|
|
# the derived TRtlPlatformPosix in another unit) ends up undefined at link.
|
|
|
|
|
# Force whole-program compilation per unit so every unit object is self-contained.
|
|
|
|
|
BLAISE_FLAGS = --no-incremental
|
|
|
|
|
|
|
|
|
|
# Assembly sources — platform-specific, no C compiler needed.
|
|
|
|
|
ASM_OBJS = $(OBJ_DIR)/blaise_setjmp_x86_64.o \
|
|
|
|
|
$(OBJ_DIR)/blaise_atomic_x86_64.o \
|
|
|
|
|
$(OBJ_DIR)/blaise_utf8_x86_64.o
|
|
|
|
|
|
|
|
|
|
# Pascal RTL units compiled via the Blaise compiler.
|
|
|
|
|
PAS_OBJS = $(OBJ_DIR)/blaise_mem.o \
|
|
|
|
|
$(OBJ_DIR)/blaise_str.o \
|
|
|
|
|
$(OBJ_DIR)/blaise_set.o \
|
|
|
|
|
$(OBJ_DIR)/blaise_arc.o \
|
|
|
|
|
$(OBJ_DIR)/blaise_weak.o \
|
|
|
|
|
$(OBJ_DIR)/blaise_float.o \
|
|
|
|
|
$(OBJ_DIR)/blaise_thread.o \
|
|
|
|
|
$(OBJ_DIR)/blaise_exc.o \
|
|
|
|
|
$(OBJ_DIR)/rtl_platform_posix.o
|
|
|
|
|
|
|
|
|
|
OBJS = $(ASM_OBJS) $(PAS_OBJS)
|
Add Phase 2: record/class types, ARC strings, RTL stubs, and grammar doc
Symbol table:
- Added tyClass kind and NewClassType factory; TRecordTypeDesc now
accepts an optional kind parameter so records and classes share the
same descriptor with distinct semantics.
Semantic analyser:
- AnalyseTypeDecls runs before PushScope so type symbols land in global
scope and survive PopScope.
- Handles TRecordTypeDef and TClassTypeDef; sets IsConstructorCall on
TypeName.Create expressions and IsClassAccess on class-variable field
access and assignment nodes.
Code generator (QBE IR):
- Class variables: 8-byte pointer slot, zeroed on entry.
- Constructor calls: malloc(sizeof fields), store pointer.
- Class field access/write: load pointer, add field offset, load/store.
- ARC string assignment: AddRef new value, Release old value, then store.
- Block exit: Release every string variable in scope (EmitStringCleanup).
Lexer / Parser / AST:
- Added tkClass keyword and ParseClassDef; FieldDecl parsing refactored
into ParseFieldDecl(AFields) shared by both record and class.
- AST gains TClassTypeDef, and IsConstructorCall/IsClassAccess flags on
TFieldAccessExpr and TFieldAssignment.
RTL:
- blaise_arc.c: Phase 2 no-op stubs for _StringAddRef / _StringRelease.
- rtl/Makefile: builds blaise_rtl.a; `make install` copies it next to
the compiler binary for automatic discovery by FindRTL.
- Blaise.pas driver: FindRTL checks BLAISE_RTL env var then binary dir;
links the RTL archive when present.
Tests:
- 180 unit tests (records ×23, classes ×22, ARC ×9, codegen ×9, …).
- 4 end-to-end integration tests in tests/integration/test_arc_strings.sh
covering string assignment, two-var cleanup, reassignment cycle, and
empty-program linkage.
Docs:
- design.adoc updated with Phase 2 implementation status table.
- docs/grammar.ebnf: new authoritative EBNF grammar for the Blaise
language as implemented, including ARC semantic annotations.
2026-04-20 21:04:12 +03:00
|
|
|
|
|
|
|
|
.PHONY: all install clean
|
|
|
|
|
|
|
|
|
|
all: $(LIB)
|
|
|
|
|
|
|
|
|
|
$(LIB): $(OBJS)
|
|
|
|
|
ar rcs $@ $^
|
|
|
|
|
|
2026-07-04 21:44:54 +03:00
|
|
|
# --- Assembly rules ---
|
|
|
|
|
$(OBJ_DIR)/%.o: $(ASM_DIR)/%.s
|
|
|
|
|
@mkdir -p $(OBJ_DIR)
|
|
|
|
|
$(CC) -c -o $@ $<
|
|
|
|
|
|
|
|
|
|
# --- Pascal unit rules (unit-as-top-level) ---
|
|
|
|
|
$(OBJ_DIR)/blaise_mem.o: $(PAS_SRC_DIR)/blaise_mem.pas
|
|
|
|
|
@mkdir -p $(OBJ_DIR)
|
|
|
|
|
$(BLAISE) $(BLAISE_FLAGS) --source $< --unit-path $(PAS_SRC_DIR) --output $@
|
|
|
|
|
|
|
|
|
|
$(OBJ_DIR)/blaise_str.o: $(PAS_SRC_DIR)/blaise_str.pas
|
|
|
|
|
@mkdir -p $(OBJ_DIR)
|
|
|
|
|
$(BLAISE) $(BLAISE_FLAGS) --source $< --unit-path $(PAS_SRC_DIR) --output $@
|
|
|
|
|
|
|
|
|
|
$(OBJ_DIR)/blaise_set.o: $(PAS_SRC_DIR)/blaise_set.pas
|
|
|
|
|
@mkdir -p $(OBJ_DIR)
|
|
|
|
|
$(BLAISE) $(BLAISE_FLAGS) --source $< --unit-path $(PAS_SRC_DIR) --output $@
|
|
|
|
|
|
|
|
|
|
$(OBJ_DIR)/blaise_arc.o: $(PAS_SRC_DIR)/blaise_arc.pas
|
|
|
|
|
@mkdir -p $(OBJ_DIR)
|
|
|
|
|
$(BLAISE) $(BLAISE_FLAGS) --source $< --unit-path $(PAS_SRC_DIR) --output $@
|
|
|
|
|
|
|
|
|
|
$(OBJ_DIR)/blaise_weak.o: $(PAS_SRC_DIR)/blaise_weak.pas
|
|
|
|
|
@mkdir -p $(OBJ_DIR)
|
|
|
|
|
$(BLAISE) $(BLAISE_FLAGS) --source $< --unit-path $(PAS_SRC_DIR) --output $@
|
|
|
|
|
|
|
|
|
|
$(OBJ_DIR)/blaise_float.o: $(PAS_SRC_DIR)/blaise_float.pas
|
|
|
|
|
@mkdir -p $(OBJ_DIR)
|
|
|
|
|
$(BLAISE) $(BLAISE_FLAGS) --source $< --unit-path $(PAS_SRC_DIR) --output $@
|
|
|
|
|
|
|
|
|
|
$(OBJ_DIR)/blaise_thread.o: $(PAS_SRC_DIR)/blaise_thread.pas
|
|
|
|
|
@mkdir -p $(OBJ_DIR)
|
|
|
|
|
$(BLAISE) $(BLAISE_FLAGS) --source $< --unit-path $(PAS_SRC_DIR) --output $@
|
|
|
|
|
|
|
|
|
|
$(OBJ_DIR)/blaise_exc.o: $(PAS_SRC_DIR)/blaise_exc.pas
|
|
|
|
|
@mkdir -p $(OBJ_DIR)
|
|
|
|
|
$(BLAISE) $(BLAISE_FLAGS) --source $< --unit-path $(PAS_SRC_DIR) --output $@
|
|
|
|
|
|
|
|
|
|
$(OBJ_DIR)/rtl_platform_posix.o: $(PAS_SRC_DIR)/rtl.platform.posix.pas \
|
|
|
|
|
$(PAS_SRC_DIR)/rtl.platform.pas
|
refactor(runtime): replace blaise_exc.c with Pascal + x86_64 assembly
Port all exception frame management, type identity, and runtime check
functions from C to pure Pascal (blaise_exc.pas). Replace libc
setjmp/longjmp with a minimal custom implementation in x86_64 assembly
(blaise_setjmp_x86_64.s, ~40 lines) that saves only the 8 callee-saved
registers (64-byte jmp_buf vs libc's 200-byte one).
This eliminates the last C source file from the runtime build. The only
non-Pascal code in the runtime is now the assembly setjmp stub.
Changes:
- runtime/src/main/asm/blaise_setjmp_x86_64.s: _blaise_setjmp/_blaise_longjmp
- runtime/src/main/pascal/blaise_exc.pas: _PushExcFrame, _PopExcFrame,
_Raise, _Reraise, _CurrentException, _CurrentExceptionMessage,
_IsInstance, _ImplementsInterface, _GetItab, _Raise_InvalidCast,
_CheckNil — all ported from blaise_exc.c
- uCodeGenQBE.pas: emit call $_blaise_setjmp instead of call $setjmp
- cp.test.exceptions.pas: IR assertion updated for new symbol name
- runtime/Makefile: assembly rule, Pascal blaise_exc build, C rules removed
- .gitignore: whitelist runtime/src/main/asm/*.s
- runtime/src/main/c/blaise_exc.c: deleted
2083 tests pass, fixpoint verified (stage-3/stage-4).
2026-05-21 03:01:08 +03:00
|
|
|
@mkdir -p $(OBJ_DIR)
|
2026-06-19 06:27:41 +03:00
|
|
|
$(BLAISE) $(BLAISE_FLAGS) --source $< --unit-path $(PAS_SRC_DIR) --output $@
|
refactor(runtime): replace blaise_exc.c with Pascal + x86_64 assembly
Port all exception frame management, type identity, and runtime check
functions from C to pure Pascal (blaise_exc.pas). Replace libc
setjmp/longjmp with a minimal custom implementation in x86_64 assembly
(blaise_setjmp_x86_64.s, ~40 lines) that saves only the 8 callee-saved
registers (64-byte jmp_buf vs libc's 200-byte one).
This eliminates the last C source file from the runtime build. The only
non-Pascal code in the runtime is now the assembly setjmp stub.
Changes:
- runtime/src/main/asm/blaise_setjmp_x86_64.s: _blaise_setjmp/_blaise_longjmp
- runtime/src/main/pascal/blaise_exc.pas: _PushExcFrame, _PopExcFrame,
_Raise, _Reraise, _CurrentException, _CurrentExceptionMessage,
_IsInstance, _ImplementsInterface, _GetItab, _Raise_InvalidCast,
_CheckNil — all ported from blaise_exc.c
- uCodeGenQBE.pas: emit call $_blaise_setjmp instead of call $setjmp
- cp.test.exceptions.pas: IR assertion updated for new symbol name
- runtime/Makefile: assembly rule, Pascal blaise_exc build, C rules removed
- .gitignore: whitelist runtime/src/main/asm/*.s
- runtime/src/main/c/blaise_exc.c: deleted
2083 tests pass, fixpoint verified (stage-3/stage-4).
2026-05-21 03:01:08 +03:00
|
|
|
|
Add Phase 2: record/class types, ARC strings, RTL stubs, and grammar doc
Symbol table:
- Added tyClass kind and NewClassType factory; TRecordTypeDesc now
accepts an optional kind parameter so records and classes share the
same descriptor with distinct semantics.
Semantic analyser:
- AnalyseTypeDecls runs before PushScope so type symbols land in global
scope and survive PopScope.
- Handles TRecordTypeDef and TClassTypeDef; sets IsConstructorCall on
TypeName.Create expressions and IsClassAccess on class-variable field
access and assignment nodes.
Code generator (QBE IR):
- Class variables: 8-byte pointer slot, zeroed on entry.
- Constructor calls: malloc(sizeof fields), store pointer.
- Class field access/write: load pointer, add field offset, load/store.
- ARC string assignment: AddRef new value, Release old value, then store.
- Block exit: Release every string variable in scope (EmitStringCleanup).
Lexer / Parser / AST:
- Added tkClass keyword and ParseClassDef; FieldDecl parsing refactored
into ParseFieldDecl(AFields) shared by both record and class.
- AST gains TClassTypeDef, and IsConstructorCall/IsClassAccess flags on
TFieldAccessExpr and TFieldAssignment.
RTL:
- blaise_arc.c: Phase 2 no-op stubs for _StringAddRef / _StringRelease.
- rtl/Makefile: builds blaise_rtl.a; `make install` copies it next to
the compiler binary for automatic discovery by FindRTL.
- Blaise.pas driver: FindRTL checks BLAISE_RTL env var then binary dir;
links the RTL archive when present.
Tests:
- 180 unit tests (records ×23, classes ×22, ARC ×9, codegen ×9, …).
- 4 end-to-end integration tests in tests/integration/test_arc_strings.sh
covering string assignment, two-var cleanup, reassignment cycle, and
empty-program linkage.
Docs:
- design.adoc updated with Phase 2 implementation status table.
- docs/grammar.ebnf: new authoritative EBNF grammar for the Blaise
language as implemented, including ARC semantic annotations.
2026-04-20 21:04:12 +03:00
|
|
|
install: $(LIB)
|
|
|
|
|
@mkdir -p $(COMPILER_BIN)
|
|
|
|
|
cp $(LIB) $(COMPILER_BIN)/blaise_rtl.a
|
|
|
|
|
@echo "Installed blaise_rtl.a → $(COMPILER_BIN)/blaise_rtl.a"
|
|
|
|
|
|
|
|
|
|
clean:
|
2026-05-01 16:42:29 +03:00
|
|
|
rm -f $(OBJ_DIR)/*.o $(OBJ_DIR)/*.s $(OBJ_DIR)/*.ssa $(LIB)
|