blaise/rtl/Makefile

38 lines
879 B
Makefile
Raw Normal View History

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
CC = gcc
CFLAGS = -O2 -Wall -Wextra -std=c11
SRC_DIR = src/main/c
OBJ_DIR = target
LIB = $(OBJ_DIR)/blaise_rtl.a
# Where the compiler binary lives — install copies the RTL there so the
# driver finds it automatically next to itself.
COMPILER_BIN = ../compiler/target
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
SRCS = $(SRC_DIR)/blaise_arc.c \
Implement [Weak] attribute for cycle-breaking under ARC A weak reference is a slot that does not contribute to the target's refcount and is automatically nil'd when the target is freed. This breaks reference cycles that would otherwise leak under universal ARC. Attribute model (Delphi-compatible) type TNode = class Other: TNode; // strong, default [Weak] Back: TNode; // weak, no refcount, zeroed on free end; The parser accepts `[Ident]` and `[Ident(args)]` attribute lists before var and class-field declarations. Attribute names are captured verbatim on TVarDecl.Attributes / TFieldDecl.Attributes; unknown attributes are accepted silently so user-defined attributes (which will materialise with RTTI) don't need to wait for the syntax. Semantic analysis resolves `[Weak]` with the Delphi convention that the `Attribute` suffix is optional — `[Weak]` and `[WeakAttribute]` both resolve to the recognised marker. Applying [Weak] to a non- reference type (Integer, string, record) is an error at declaration time. Resolved weakness is surfaced on TVarDecl.IsWeak / TFieldInfo.IsWeak and TSymbol.IsWeak for codegen consumption. Lexer: tkLBracket / tkRBracket added. RTL (blaise_weak.c): global chained hash table maps target pointers to lists of registered weak slot addresses. _WeakAssign registers a new slot (and unregisters any prior), _WeakClear unregisters and zeros, _WeakZeroSlots nils all slots registered against a target. The last is called from _ClassRelease at refcount zero, before field cleanup and free, so weak readers never see dangling memory. Codegen: weak class/interface vars bypass addref/release entirely. Variable assignment, field assignment, scope-exit cleanup, exception- path cleanup, and per-class _FieldCleanup functions all branch on the weak flag to emit _WeakAssign / _WeakClear against the slot address instead of strong refcount operations. Tests * cp.test.weakref.pas — 14 unit tests covering lexer, parser, semantic validation (including the suffix-drop rule), and codegen emission at every insertion point. * cp.test.e2e.TestRun_WeakRef_BreaksCycle_Valgrind — compile and run a two-node mutual-reference program with [Weak]. Without the attribute, valgrind reports both nodes as definitely lost; with it, the run is leak-free. All 711 compiler tests pass. Deferred: TCustomAttribute / WeakAttribute Pascal-side class declarations. The compiler resolves `[Weak]` purely by attribute name, so the RTL classes are not load-bearing today. They will be added as empty marker types when RTTI arrives and RTTI-queryable attributes become meaningful.
2026-04-23 12:15:00 +03:00
$(SRC_DIR)/blaise_exc.c \
$(SRC_DIR)/blaise_weak.c \
$(SRC_DIR)/blaise_str.c \
$(SRC_DIR)/blaise_io.c \
$(SRC_DIR)/blaise_process.c
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
OBJS = $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SRCS))
.PHONY: all install clean
all: $(LIB)
$(LIB): $(OBJS)
ar rcs $@ $^
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(OBJ_DIR)
$(CC) $(CFLAGS) -c -o $@ $<
install: $(LIB)
@mkdir -p $(COMPILER_BIN)
cp $(LIB) $(COMPILER_BIN)/blaise_rtl.a
@echo "Installed blaise_rtl.a → $(COMPILER_BIN)/blaise_rtl.a"
clean:
rm -f $(OBJ_DIR)/*.o $(LIB)