aboutsummaryrefslogtreecommitdiff
path: root/src/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'src/stdlib')
-rw-r--r--src/stdlib/print.h1
-rw-r--r--src/stdlib/text.h15
2 files changed, 13 insertions, 3 deletions
diff --git a/src/stdlib/print.h b/src/stdlib/print.h
index 5ef5b6ed..ce20152b 100644
--- a/src/stdlib/print.h
+++ b/src/stdlib/print.h
@@ -12,7 +12,6 @@
#include <assert.h>
#include <ctype.h>
#include <gc.h>
-#include <gc/cord.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
diff --git a/src/stdlib/text.h b/src/stdlib/text.h
index fc336612..642a74b6 100644
--- a/src/stdlib/text.h
+++ b/src/stdlib/text.h
@@ -8,6 +8,7 @@
#include "datatypes.h"
#include "integers.h"
+#include "mapmacro.h"
#include "optionals.h"
#include "types.h"
#include "util.h"
@@ -26,10 +27,20 @@ typedef struct {
#define Text(str) ((Text_t){.length=sizeof(str)-1, .tag=TEXT_ASCII, .ascii="" str})
-//int Text$print(FILE *stream, Text_t t);
+static inline Text_t Text_from_str_literal(const char *str) {
+ return (Text_t){.length=strlen(str), .tag=TEXT_ASCII, .ascii=str};
+}
+
+static inline Text_t Text_from_text(Text_t t) {
+ return t;
+}
+
+#define convert_to_text(x) _Generic(x, Text_t: Text_from_text, char*: Text$from_str, const char*: Text$from_str)(x)
+
Text_t Text$_concat(int n, Text_t items[n]);
#define Text$concat(...) Text$_concat(sizeof((Text_t[]){__VA_ARGS__})/sizeof(Text_t), (Text_t[]){__VA_ARGS__})
-#define Texts(...) Text$concat(__VA_ARGS__)
+#define Texts(...) Text$concat(MAP_LIST(convert_to_text, __VA_ARGS__))
+// int Text$print(FILE *stream, Text_t t);
Text_t Text$slice(Text_t text, Int_t first_int, Int_t last_int);
Text_t Text$from(Text_t text, Int_t first);
Text_t Text$to(Text_t text, Int_t last);