aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/compile/optionals.c34
-rw-r--r--src/stdlib/c_strings.c6
-rw-r--r--src/stdlib/c_strings.h3
-rw-r--r--src/stdlib/paths.c3
4 files changed, 31 insertions, 15 deletions
diff --git a/src/compile/optionals.c b/src/compile/optionals.c
index 8cb6af2b..798d75a6 100644
--- a/src/compile/optionals.c
+++ b/src/compile/optionals.c
@@ -85,19 +85,27 @@ Text_t check_none(type_t *t, Text_t value) {
t = Match(t, OptionalType)->type;
// NOTE: these use statement expressions ({...;}) because some compilers
// complain about excessive parens around equality comparisons
- if (t->tag == PointerType || t->tag == FunctionType || t->tag == CStringType) return Texts("(", value, " == NULL)");
- else if (t->tag == BigIntType) return Texts("((", value, ").small == 0)");
- else if (t->tag == ClosureType) return Texts("((", value, ").fn == NULL)");
- else if (t->tag == NumType)
- return Texts(Match(t, NumType)->bits == TYPE_NBITS64 ? "Num$isnan(" : "Num32$isnan(", value, ")");
- else if (t->tag == ListType) return Texts("((", value, ").data == NULL)");
- else if (t->tag == TableType) return Texts("((", value, ").entries.data == NULL)");
- else if (t->tag == BoolType) return Texts("((", value, ") == NONE_BOOL)");
- else if (t->tag == TextType) return Texts("((", value, ").tag == TEXT_NONE)");
- else if (t->tag == IntType || t->tag == ByteType || t->tag == StructType) return Texts("!(", value, ").has_value");
- else if (t->tag == EnumType) return Texts("((", value, ").$tag == 0)");
- print_err("Optional check not implemented for: ", type_to_text(t));
- return EMPTY_TEXT;
+ switch (t->tag) {
+ case PointerType:
+ case FunctionType:
+ case CStringType:
+ case PathType: return Texts("(", value, " == NULL)");
+ case BigIntType: return Texts("((", value, ").small == 0)");
+ case ClosureType: return Texts("((", value, ").fn == NULL)");
+ case NumType: return Texts(Match(t, NumType)->bits == TYPE_NBITS64 ? "Num$isnan(" : "Num32$isnan(", value, ")");
+ case ListType: return Texts("((", value, ").data == NULL)");
+ case TableType: return Texts("((", value, ").entries.data == NULL)");
+ case BoolType: return Texts("((", value, ") == NONE_BOOL)");
+ case TextType: return Texts("((", value, ").tag == TEXT_NONE)");
+ case IntType:
+ case ByteType:
+ case StructType: return Texts("!(", value, ").has_value");
+ case EnumType: return Texts("((", value, ").$tag == 0)");
+ default: {
+ print_err("Optional check not implemented for: ", type_to_text(t));
+ return EMPTY_TEXT;
+ }
+ }
}
public
diff --git a/src/stdlib/c_strings.c b/src/stdlib/c_strings.c
index cbe46b68..e70d6d81 100644
--- a/src/stdlib/c_strings.c
+++ b/src/stdlib/c_strings.c
@@ -47,7 +47,8 @@ PUREFUNC public bool CString$is_none(const void *c_str, const TypeInfo_t *info)
return *(const char **)c_str == NULL;
}
-static void CString$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *info) {
+public
+void CString$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *info) {
(void)info;
const char *str = *(const char **)obj;
int64_t len = (int64_t)strlen(str);
@@ -55,7 +56,8 @@ static void CString$serialize(const void *obj, FILE *out, Table_t *pointers, con
fwrite(str, sizeof(char), (size_t)len, out);
}
-static void CString$deserialize(FILE *in, void *out, List_t *pointers, const TypeInfo_t *info) {
+public
+void CString$deserialize(FILE *in, void *out, List_t *pointers, const TypeInfo_t *info) {
(void)info;
int64_t len = -1;
Int64$deserialize(in, &len, pointers, &Int64$info);
diff --git a/src/stdlib/c_strings.h b/src/stdlib/c_strings.h
index eba3a3df..7a45e54a 100644
--- a/src/stdlib/c_strings.h
+++ b/src/stdlib/c_strings.h
@@ -12,6 +12,9 @@ Text_t CString$as_text(const char **str, bool colorize, const TypeInfo_t *info);
PUREFUNC int CString$compare(const void *x, const void *y, const TypeInfo_t *type);
PUREFUNC bool CString$equal(const void *x, const void *y, const TypeInfo_t *type);
PUREFUNC uint64_t CString$hash(const void *str, const TypeInfo_t *type);
+PUREFUNC bool CString$is_none(const void *c_str, const TypeInfo_t *info);
const char *CString$join(const char *glue, List_t strings);
+void CString$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *info);
+void CString$deserialize(FILE *in, void *out, List_t *pointers, const TypeInfo_t *info);
extern const TypeInfo_t CString$info;
diff --git a/src/stdlib/paths.c b/src/stdlib/paths.c
index db596b04..907467bd 100644
--- a/src/stdlib/paths.c
+++ b/src/stdlib/paths.c
@@ -867,5 +867,8 @@ const TypeInfo_t Path$info = {
.compare = CString$compare,
.equal = CString$equal,
.hash = CString$hash,
+ .is_none = CString$is_none,
+ .serialize = CString$serialize,
+ .deserialize = CString$deserialize,
},
};