From 05cdcb6a1cc3d4de3a0b3d12d4babcd6438b4754 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Tue, 13 Oct 2026 13:45:03 +0000 Subject: Add record-derived classes with explicit field visibility Co-Authored-By: Claude Fable 5.1 --- doc/cpsc.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'doc') diff --git a/doc/cpsc.md b/doc/cpsc.md index fa4ae2b..8a57a63 100644 --- a/doc/cpsc.md +++ b/doc/cpsc.md @@ -66,6 +66,30 @@ Save IR and run it: cpsc test.cps -r -o result.ir ``` +# CLASSES + +Declare classes at top level. Every field must explicitly specify `PUBLIC` or +`PRIVATE`, without `DECLARE`: + +```text +CLASS Person + PUBLIC Name : STRING + PRIVATE Age : INTEGER +ENDCLASS + +DECLARE p : Person +p.Name <- "Alice" +OUTPUT p.Name +``` + +Classes use record value semantics: zero initialization, whole-value copying, +arrays, pointers and ordinary function/procedure parameters. Private fields cannot +be read, written or addressed externally; they are still initialized and copied +with the whole value. Record `TYPE` fields remain implicitly public and cannot +specify access levels. Class methods, constructors, destructors, `NEW` and +`INHERITS` are not supported. Array fields remain unsupported in both records and +classes. + # EXIT STATUS **0** -- cgit v1.3.1-4-g156e