aboutsummaryrefslogtreecommitdiff
path: root/lib/CodeGen/Builtins.h
diff options
context:
space:
mode:
author_ov4 <ov4@ov4.org>2026-10-16 09:42:45 +0000
committer_ov4 <ov4@ov4.org>2026-10-16 09:42:45 +0000
commit3dc3a15c86287b2788142b58e2512269cd5274c6 (patch)
tree1610b02343fd3e8b6b733c0cbfe327be6fef4394 /lib/CodeGen/Builtins.h
parentdb6ac29d0ac769ff780f3901ed987b97965f3f5e (diff)
refactor(codegen): split emission by responsibility
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Diffstat (limited to 'lib/CodeGen/Builtins.h')
-rw-r--r--lib/CodeGen/Builtins.h37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/CodeGen/Builtins.h b/lib/CodeGen/Builtins.h
new file mode 100644
index 0000000..34e36a9
--- /dev/null
+++ b/lib/CodeGen/Builtins.h
@@ -0,0 +1,37 @@
+#pragma once
+#include <string>
+
+namespace cps::detail {
+
+// Single source of truth for the built-in functions: name, arity and return
+// type. emitExpr checks arity against this table before dispatching, and
+// getExprTypeInfo reads the return type from it.
+struct BuiltinInfo {
+ const char *Name;
+ unsigned Arity;
+ const char *ReturnTypeName;
+};
+
+inline constexpr BuiltinInfo Builtins[] = {
+ {"LENGTH", 1, "INTEGER"},
+ {"MID", 3, "STRING"},
+ {"RIGHT", 2, "STRING"},
+ {"LEFT", 2, "STRING"},
+ {"LCASE", 1, "STRING"},
+ {"UCASE", 1, "STRING"},
+ {"ASC", 1, "INTEGER"},
+ {"CHR", 1, "STRING"},
+ {"IS_NUM", 1, "BOOLEAN"},
+ {"NUM_TO_STR", 1, "STRING"},
+ {"STR_TO_NUM", 1, "REAL"},
+ {"EOF", 1, "BOOLEAN"},
+};
+
+inline const BuiltinInfo *findBuiltin(const std::string &Name) {
+ for (const auto &B : Builtins) {
+ if (Name == B.Name) return &B;
+ }
+ return nullptr;
+}
+
+} // namespace cps::detail