aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2026-02-19 23:58:49 -0500
committerBruce Hill <bruce@bruce-hill.com>2026-02-19 23:58:49 -0500
commitb780cff8e43bb9834ecd44f33ae8d33bb8528d82 (patch)
tree69067a393b73a29e2e811f782872c48532e987af
parentfde2d5876236c9048ee1112be90c8af41c910149 (diff)
Code cleanup
-rw-r--r--src/compile/binops.c4
-rw-r--r--src/compile/cli.c2
-rw-r--r--src/compile/expressions.c3
-rw-r--r--src/compile/optionals.c3
-rw-r--r--src/compile/types.c7
-rw-r--r--src/environment.c5
-rw-r--r--src/stdlib/cli.c4
-rw-r--r--src/stdlib/optionals.h2
-rw-r--r--src/types.c5
-rw-r--r--src/types.h3
10 files changed, 19 insertions, 19 deletions
diff --git a/src/compile/binops.c b/src/compile/binops.c
index acf1e031..89111a5f 100644
--- a/src/compile/binops.c
+++ b/src/compile/binops.c
@@ -228,8 +228,10 @@ Text_t compile_binary_op(env_t *env, ast_t *ast) {
type_to_text(rhs_t), " values");
}
case Concat: {
- if (overall_t == PATH_TYPE) return Texts("Path$concat(", lhs, ", ", rhs, ")");
switch (overall_t->tag) {
+ case PathType: {
+ return Texts("Path$concat(", lhs, ", ", rhs, ")");
+ }
case TextType: {
return Texts("Text$concat(", lhs, ", ", rhs, ")");
}
diff --git a/src/compile/cli.c b/src/compile/cli.c
index ade6caa7..64abe2e7 100644
--- a/src/compile/cli.c
+++ b/src/compile/cli.c
@@ -13,7 +13,7 @@
static Text_t get_flag_options(type_t *t, Text_t separator) {
if (t->tag == BoolType) {
return Text("yes|no");
- } else if (t == PATH_TYPE) {
+ } else if (t->tag == PathType) {
return Text("path");
} else if (t->tag == EnumType) {
Text_t options = EMPTY_TEXT;
diff --git a/src/compile/expressions.c b/src/compile/expressions.c
index c3918de3..3f5d24df 100644
--- a/src/compile/expressions.c
+++ b/src/compile/expressions.c
@@ -56,8 +56,6 @@ Text_t compile_empty(type_t *t) {
if (t->tag == OptionalType) return compile_none(t);
- if (t == PATH_TYPE) return Text("NONE_PATH");
-
switch (t->tag) {
case BigIntType: return Text("I(0)");
case IntType: {
@@ -76,6 +74,7 @@ Text_t compile_empty(type_t *t) {
case TableType: return Text("EMPTY_TABLE");
case TextType: return Text("EMPTY_TEXT");
case CStringType: return Text("\"\"");
+ case PathType: return Text("NONE_PATH");
case PointerType: {
DeclareMatch(ptr, t, PointerType);
Text_t empty_pointed = compile_empty(ptr->pointed);
diff --git a/src/compile/optionals.c b/src/compile/optionals.c
index 75dff935..8cb6af2b 100644
--- a/src/compile/optionals.c
+++ b/src/compile/optionals.c
@@ -48,8 +48,6 @@ Text_t compile_none(type_t *t) {
if (t == NULL) compiler_err(NULL, NULL, NULL, "I can't compile a `none` value with no type");
- if (t == PATH_TYPE) return Text("NONE_PATH");
-
switch (t->tag) {
case BigIntType: return Text("NONE_INT");
case IntType: {
@@ -68,6 +66,7 @@ Text_t compile_none(type_t *t) {
case TableType: return Text("NONE_TABLE");
case TextType: return Text("NONE_TEXT");
case CStringType: return Text("NULL");
+ case PathType: return Text("NONE_PATH");
case PointerType: return Texts("((", compile_type(t), ")NULL)");
case ClosureType: return Text("NONE_CLOSURE");
case NumType: return Text("nan(\"none\")");
diff --git a/src/compile/types.c b/src/compile/types.c
index aac27f4c..e81ebed3 100644
--- a/src/compile/types.c
+++ b/src/compile/types.c
@@ -11,8 +11,6 @@
public
Text_t compile_type(type_t *t) {
- if (t == PATH_TYPE) return Text("Path_t");
-
switch (t->tag) {
case ReturnType: errx(1, "Shouldn't be compiling ReturnType to a type");
case AbortType: return Text("void");
@@ -21,6 +19,7 @@ Text_t compile_type(type_t *t) {
case BoolType: return Text("Bool_t");
case ByteType: return Text("Byte_t");
case CStringType: return Text("const char*");
+ case PathType: return Text("Path_t");
case BigIntType: return Text("Int_t");
case IntType: return Texts("Int", (int32_t)Match(t, IntType)->bits, "_t");
case NumType:
@@ -68,10 +67,10 @@ Text_t compile_type(type_t *t) {
case NumType:
case BoolType:
case ByteType:
+ case PathType:
case ListType:
case TableType: return Texts("Optional", compile_type(nonnull));
case StructType: {
- if (nonnull == PATH_TYPE) return Text("OptionalPath_t");
DeclareMatch(s, nonnull, StructType);
return namespace_name(s->env, s->env->namespace->parent, Texts("$Optional", s->name, "$$type"));
}
@@ -87,7 +86,6 @@ Text_t compile_type(type_t *t) {
public
Text_t compile_type_info(type_t *t) {
if (t == NULL) compiler_err(NULL, NULL, NULL, "Attempt to compile a NULL type");
- if (t == PATH_TYPE) return Text("&Path$info");
switch (t->tag) {
case BoolType:
@@ -96,6 +94,7 @@ Text_t compile_type_info(type_t *t) {
case BigIntType:
case NumType:
case CStringType: return Texts("&", type_to_text(t), "$info");
+ case PathType: return Text("&Path$info");
case TextType: {
DeclareMatch(text, t, TextType);
if (!text->lang || streq(text->lang, "Text")) return Text("&Text$info");
diff --git a/src/environment.c b/src/environment.c
index d209471e..9779fb1c 100644
--- a/src/environment.c
+++ b/src/environment.c
@@ -67,9 +67,7 @@ env_t *global_env(bool source_mapping) {
(void)bind_type(env, "Int", Type(BigIntType));
(void)bind_type(env, "Int32", Type(IntType, .bits = TYPE_IBITS32));
(void)bind_type(env, "Memory", Type(MemoryType));
- PATH_TYPE = declare_type(
- env,
- "enum Path(AbsolutePath(components:[Text]), RelativePath(components:[Text]), HomePath(components:[Text]))");
+ (void)bind_type(env, "Path", Type(PathType));
RESULT_TYPE = declare_type(env, "enum Result(Success, Failure(reason:Text))");
PRESENT_TYPE = declare_type(env, "struct Present()");
@@ -677,6 +675,7 @@ env_t *get_namespace_by_type(env_t *env, type_t *t) {
case ListType: return NULL;
case TableType: return NULL;
case CStringType:
+ case PathType:
case BoolType:
case IntType:
case BigIntType:
diff --git a/src/stdlib/cli.c b/src/stdlib/cli.c
index e30f7ced..29a16634 100644
--- a/src/stdlib/cli.c
+++ b/src/stdlib/cli.c
@@ -53,7 +53,7 @@ static bool pop_boolean_cli_flag(List_t *args, char short_flag, const char *flag
return true;
}
} else if (short_flag && arg[0] == '-' && arg[1] != '-' && strchr(arg + 1, short_flag)) {
- char *loc = strchr(arg + 1, short_flag);
+ const char *loc = strchr(arg + 1, short_flag);
if (loc[1] == '=') {
// Case: -f=yes|no|true|false|on|off|1|0
OptionalBool_t b = Bool$parse(Text$from_str(loc + 2), NULL);
@@ -347,7 +347,7 @@ bool pop_cli_flag(List_t *args, char short_flag, const char *flag, void *dest, c
return true;
}
} else if (short_flag && arg[0] == '-' && arg[1] != '-' && strchr(arg + 1, short_flag)) {
- char *loc = strchr(arg + 1, short_flag);
+ const char *loc = strchr(arg + 1, short_flag);
char short_str[2] = {short_flag, '\0'};
if (loc[1] == '=') {
// Case: -f=...
diff --git a/src/stdlib/optionals.h b/src/stdlib/optionals.h
index 700a4ada..50dbd4de 100644
--- a/src/stdlib/optionals.h
+++ b/src/stdlib/optionals.h
@@ -15,7 +15,7 @@
#define NONE_TABLE ((OptionalTable_t){.entries.data = NULL})
#define NONE_CLOSURE ((OptionalClosure_t){.fn = NULL})
#define NONE_TEXT ((OptionalText_t){.tag = TEXT_NONE})
-#define NONE_PATH ((OptionalPath_t){.$tag = Path$tag$none})
+#define NONE_PATH (Path_t) NULL
PUREFUNC bool is_none(const void *obj, const TypeInfo_t *non_optional_type);
PUREFUNC uint64_t Optional$hash(const void *obj, const TypeInfo_t *type);
diff --git a/src/types.c b/src/types.c
index 24453150..e37f5544 100644
--- a/src/types.c
+++ b/src/types.c
@@ -37,6 +37,7 @@ Text_t type_to_text(type_t *t) {
case BoolType: return Text("Bool");
case ByteType: return Text("Byte");
case CStringType: return Text("CString");
+ case PathType: return Text("Path");
case TextType: return Match(t, TextType)->lang ? Text$from_str(Match(t, TextType)->lang) : Text("Text");
case BigIntType: return Text("Int");
case IntType: return Texts("Int", (int32_t)Match(t, IntType)->bits);
@@ -528,7 +529,6 @@ PUREFUNC size_t unpadded_struct_size(type_t *t) {
}
PUREFUNC size_t type_size(type_t *t) {
- if (t == PATH_TYPE) return sizeof(Path_t);
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wswitch-default"
@@ -542,6 +542,7 @@ PUREFUNC size_t type_size(type_t *t) {
case BoolType: return sizeof(bool);
case ByteType: return sizeof(uint8_t);
case CStringType: return sizeof(char *);
+ case PathType: return sizeof(Path_t);
case BigIntType: return sizeof(Int_t);
case IntType: {
switch (Match(t, IntType)->bits) {
@@ -616,7 +617,6 @@ PUREFUNC size_t type_size(type_t *t) {
}
PUREFUNC size_t type_align(type_t *t) {
- if (t == PATH_TYPE) return __alignof__(Path_t);
#ifdef __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wswitch-default"
@@ -630,6 +630,7 @@ PUREFUNC size_t type_align(type_t *t) {
case BoolType: return __alignof__(bool);
case ByteType: return __alignof__(uint8_t);
case CStringType: return __alignof__(char *);
+ case PathType: return __alignof__(Path_t);
case BigIntType: return __alignof__(Int_t);
case IntType: {
switch (Match(t, IntType)->bits) {
diff --git a/src/types.h b/src/types.h
index df5729ca..7057fef9 100644
--- a/src/types.h
+++ b/src/types.h
@@ -50,6 +50,7 @@ struct type_s {
NumType,
CStringType,
TextType,
+ PathType,
ListType,
TableType,
FunctionType,
@@ -64,7 +65,7 @@ struct type_s {
union {
struct {
- } UnknownType, AbortType, VoidType, MemoryType, BoolType;
+ } UnknownType, AbortType, VoidType, MemoryType, BoolType, PathType;
struct {
type_t *ret;
} ReturnType;