commit 98020e196cc6d458cd4af36d408f2b7743a40ed7
parent 6f7d8553fcacfa293447187c72d0780900dee3c3
Author: m21c <ho*******@gmail.com>
Date: Fri, 27 Jun 2025 21:25:45 +0200
r&d strings + comment (may be removed)
Diffstat:
| M | compiler.c | | | 83 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 83 insertions(+), 0 deletions(-)
diff --git a/compiler.c b/compiler.c
@@ -468,6 +468,17 @@ struct SrcLoc {
const char *filename;
} SrcLoc;
+/**
+ * @brief A node in the abstract syntax tree.
+ * @details The location is used to report errors. The type is used to store the
+ * type of the node. The union u is used to store the value of the node
+ * for its given kind. The lhs pointer points to the left hand side of
+ * its child node and the rhs pointer points to the right hand side of
+ * its child node (if any). Or the lhs and rhs pointer are used to
+ * point to the previous and next statement in a linked list (in case
+ * of ASTMT). Additionally, the payload pointer is used to store the
+ * condition of an if-statement and other statements.
+ */
struct Node {
Kind kind;
SrcLoc loc;
@@ -7595,6 +7606,78 @@ finish:
// }}}
+// @section toplevel bundle & use {{{
+
+typedef struct String String;
+
+struct String {
+ char *string;
+ int length;
+};
+
+static String
+makestring(char *string)
+{
+ String result;
+
+ result.string = string;
+ result.length = strlen(string);
+
+ return result;
+}
+
+static bool
+endswithcase(String name, String ending)
+{
+ const int delta = name.length - ending.length;
+ int i;
+
+ if (name.length < ending.length)
+ return false;
+
+ for (i = 0; i < ending.length; ++i) {
+ const int j = i + delta;
+ if (tolower(name.string[j]) != ending.string[i])
+ return false;
+ }
+
+ return true;
+}
+
+static bool
+beginswith(String name, String beginning)
+{
+ int i;
+
+ if (name.length < beginning.length)
+ return false;
+
+ for (i = 0; i < beginning.length; ++i) {
+ if (name.string[i] != beginning.string[i])
+ return false;
+ }
+
+ return true;
+}
+
+#if 0
+static String
+duplicatestring(String s)
+{
+ String copy;
+
+ copy.string = (char *) calloc(s.length + 1, sizeof*(s.string));
+ copy.length = s.length;
+
+ assert(copy.string);
+ strncpy(copy.string, s.string, s.length);
+
+ return copy;
+}
+#endif
+
+// }}}
+
// @section init source {{{
static void