From 699e18b65b07af73ccd14b28f83572b1843c7d37 Mon Sep 17 00:00:00 2001 From: _ov4 Date: Wed, 14 Oct 2026 03:29:04 +0000 Subject: feat(types): add native C scalar types and imported aliases Co-Authored-By: Claude Fable 5.1 --- include/cps/Lexer.h | 5 +++++ include/cps/TypeAST.h | 11 +++++++++++ include/cps/TypeSystem.h | 18 +++++++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/cps/Lexer.h b/include/cps/Lexer.h index 2876a58..2f6f231 100644 --- a/include/cps/Lexer.h +++ b/include/cps/Lexer.h @@ -89,6 +89,11 @@ enum Token { tok_endclass = -605, tok_public = -606, tok_private = -607, + tok_c_type = -608, + tok_c_int = -609, + tok_c_char = -610, + tok_c_string = -611, + tok_c_double = -612, tok_try = -700, tok_catch = -701, diff --git a/include/cps/TypeAST.h b/include/cps/TypeAST.h index a23f836..95c1d6d 100644 --- a/include/cps/TypeAST.h +++ b/include/cps/TypeAST.h @@ -8,6 +8,17 @@ namespace cps { +// TYPE = C_TYPE("") +class CTypeDeclAST : public StmtAST { + std::string Name; + std::string Expression; +public: + CTypeDeclAST(std::string Name, std::string Expression) + : Name(std::move(Name)), Expression(std::move(Expression)) {} + const std::string &getName() const { return Name; } + const std::string &getExpression() const { return Expression; } +}; + // ---- User-defined type declarations (CIE 9618 ยง4.1) ---- // One field of a record TYPE body. Plain data, not a statement node, so the diff --git a/include/cps/TypeSystem.h b/include/cps/TypeSystem.h index 2ef1cd6..20c485f 100644 --- a/include/cps/TypeSystem.h +++ b/include/cps/TypeSystem.h @@ -29,7 +29,9 @@ enum class TypeKind { Void, Enum, Record, - Pointer + Pointer, + CScalar, + CPointer }; // ---- Per-kind payloads (filled only for the matching TypeKind) ---- @@ -68,6 +70,16 @@ struct TypeInfo { EnumPayload Enum; // Kind == Enum only PointerPayload Pointer; // Kind == Pointer only + // C aliases share an identity even when their pseudocode names differ. + std::string CIdentity; + unsigned CRank = 0; + bool CSigned = false; + std::string CInputFormat; + std::string COutputFormat; + + bool isC() const; + bool sameType(const TypeInfo *Other) const; + bool isNumeric() const; bool isIntegral() const; bool isReal() const; @@ -125,6 +137,10 @@ public: bool definePointer(const std::string &Name, const std::string &PointeeName, std::string &Err); + bool defineCAlias(const std::string &Name, const std::string &Expression, + std::string &Err); + const TypeInfo *importCType(const std::string &Expression, std::string &Err); + bool sameType(const std::string &Left, const std::string &Right) const; const EnumConstant *lookupEnumConstant(const std::string &Name) const; -- cgit v1.3.1-4-g156e