aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-14 03:29:04 +0000
committer_ov4 <ov4@ov4.org>2026-10-14 03:29:04 +0000
commit699e18b65b07af73ccd14b28f83572b1843c7d37 (patch)
tree98b98269e02eb9052b2af698383a858d63b120a7 /include
parent3ef7f8b778dce23af25965b379126b9dd95d1c27 (diff)
feat(types): add native C scalar types and imported aliases
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Diffstat (limited to 'include')
-rw-r--r--include/cps/Lexer.h5
-rw-r--r--include/cps/TypeAST.h11
-rw-r--r--include/cps/TypeSystem.h18
3 files changed, 33 insertions, 1 deletions
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 <name> = C_TYPE("<C type expression>")
+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;