From 290c72732f21f1cddb3a0f8ec3213e4ec321da14 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 15 Nov 2025 18:13:44 -0500 Subject: Add Path.lines() --- src/environment.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/environment.c') diff --git a/src/environment.c b/src/environment.c index 96595ac7..8f49f86e 100644 --- a/src/environment.c +++ b/src/environment.c @@ -325,6 +325,7 @@ env_t *global_env(bool source_mapping) { {"is_pipe", "Path$is_pipe", "func(path:Path, follow_symlinks=yes -> Bool)"}, // {"is_socket", "Path$is_socket", "func(path:Path, follow_symlinks=yes -> Bool)"}, // {"is_symlink", "Path$is_symlink", "func(path:Path -> Bool)"}, // + {"lines", "Path$lines", "func(path:Path -> [Text]?)"}, // {"modified", "Path$modified", "func(path:Path, follow_symlinks=yes -> Int64?)"}, // {"owner", "Path$owner", "func(path:Path, follow_symlinks=yes -> Text?)"}, // {"parent", "Path$parent", "func(path:Path -> Path)"}, // -- cgit v1.2.3 From cb9d3b1a2c2c59c368f6121a16a9ab928b0ff951 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 23 Nov 2025 00:35:05 -0500 Subject: Added Text.find(text, target, start=1) --- src/environment.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/environment.c') diff --git a/src/environment.c b/src/environment.c index 8f49f86e..3a2995f7 100644 --- a/src/environment.c +++ b/src/environment.c @@ -353,6 +353,7 @@ env_t *global_env(bool source_mapping) { {"caseless_equals", "Text$equal_ignoring_case", "func(a,b:Text, language='C' -> Bool)"}, // {"codepoint_names", "Text$codepoint_names", "func(text:Text -> [Text])"}, // {"ends_with", "Text$ends_with", "func(text,suffix:Text, remainder:&Text? = none -> Bool)"}, // + {"find", "Text$find", "func(text,target:Text, start=1 -> Int?)"}, // {"from", "Text$from", "func(text:Text, first:Int -> Text)"}, // {"from_c_string", "Text$from_str", "func(str:CString -> Text?)"}, // {"from_codepoint_names", "Text$from_codepoint_names", "func(codepoint_names:[Text] -> Text?)"}, // -- cgit v1.2.3 From 2a24b0a3fc3c4986572ae2c4ea0e8e387497a7f6 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 23 Nov 2025 14:19:04 -0500 Subject: Add `at_cleanup()` function --- src/environment.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/environment.c') diff --git a/src/environment.c b/src/environment.c index 3a2995f7..d8c82513 100644 --- a/src/environment.c +++ b/src/environment.c @@ -529,17 +529,18 @@ env_t *global_env(bool source_mapping) { struct { const char *name, *code, *type_str; } global_vars[] = { - {"USE_COLOR", "USE_COLOR", "Bool"}, + {"EMPTY", "EMPTY", "Empty"}, {"TOMO_VERSION", "TOMO_VERSION_TEXT", "Text"}, - {"say", "say", "func(text:Text, newline=yes)"}, - {"print", "say", "func(text:Text, newline=yes)"}, - {"getenv", "getenv_text", "func(name:Text -> Text?)"}, - {"setenv", "setenv_text", "func(name:Text, value:Text -> Text?)"}, + {"USE_COLOR", "USE_COLOR", "Bool"}, {"ask", "ask", "func(prompt:Text, bold=yes, force_tty=yes -> Text?)"}, + {"at_cleanup", "tomo_at_cleanup", "func(fn:func())"}, {"exit", "tomo_exit", "func(message:Text?=none, code=Int32(1) -> Abort)"}, {"fail", "fail_text", "func(message:Text -> Abort)"}, + {"getenv", "getenv_text", "func(name:Text -> Text?)"}, + {"print", "say", "func(text:Text, newline=yes)"}, + {"say", "say", "func(text:Text, newline=yes)"}, + {"setenv", "setenv_text", "func(name:Text, value:Text -> Text?)"}, {"sleep", "sleep_num", "func(seconds:Num)"}, - {"EMPTY", "EMPTY", "Empty"}, }; for (size_t i = 0; i < sizeof(global_vars) / sizeof(global_vars[0]); i++) { -- cgit v1.2.3 From bbf7a60dcd524c2d86ac7efe7bc97d4a627b6d15 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 24 Nov 2025 20:22:36 -0500 Subject: Fix `from_num` incomplete renaming --- src/environment.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/environment.c') diff --git a/src/environment.c b/src/environment.c index d8c82513..6075ce49 100644 --- a/src/environment.c +++ b/src/environment.c @@ -459,7 +459,7 @@ env_t *global_env(bool source_mapping) { {"Int$from_int16", "func(i:Int16 -> Int)"}, // {"Int$from_int32", "func(i:Int32 -> Int)"}, // {"Int$from_int64", "func(i:Int64 -> Int)"}, // - {"Int$from_num", "func(n:Num, truncate=no -> Int)"}, // + {"Int$from_num64", "func(n:Num, truncate=no -> Int)"}, // {"Int$from_num32", "func(n:Num32, truncate=no -> Int)"}); ADD_CONSTRUCTORS("Int64", // {"Int64$from_bool", "func(b:Bool -> Int64)"}, // @@ -468,7 +468,7 @@ env_t *global_env(bool source_mapping) { {"Int64$from_int16", "func(i:Int16 -> Int64)"}, // {"Int64$from_int32", "func(i:Int32 -> Int64)"}, // {"Int64$from_int", "func(i:Int, truncate=no -> Int64)"}, // - {"Int64$from_num", "func(n:Num, truncate=no -> Int64)"}, // + {"Int64$from_num64", "func(n:Num, truncate=no -> Int64)"}, // {"Int64$from_num32", "func(n:Num32, truncate=no -> Int64)"}); ADD_CONSTRUCTORS("Int32", // {"Int32$from_bool", "func(b:Bool -> Int32)"}, // @@ -477,7 +477,7 @@ env_t *global_env(bool source_mapping) { {"Int32$from_int16", "func(i:Int16 -> Int32)"}, // {"Int32$from_int64", "func(i:Int64, truncate=no -> Int32)"}, // {"Int32$from_int", "func(i:Int, truncate=no -> Int32)"}, // - {"Int32$from_num", "func(n:Num, truncate=no -> Int32)"}, // + {"Int32$from_num64", "func(n:Num, truncate=no -> Int32)"}, // {"Int32$from_num32", "func(n:Num32, truncate=no -> Int32)"}); ADD_CONSTRUCTORS("Int16", // {"Int16$from_bool", "func(b:Bool -> Int16)"}, // @@ -486,7 +486,7 @@ env_t *global_env(bool source_mapping) { {"Int16$from_int32", "func(i:Int32, truncate=no -> Int16)"}, // {"Int16$from_int64", "func(i:Int64, truncate=no -> Int16)"}, // {"Int16$from_int", "func(i:Int, truncate=no -> Int16)"}, // - {"Int16$from_num", "func(n:Num, truncate=no -> Int16)"}, // + {"Int16$from_num64", "func(n:Num, truncate=no -> Int16)"}, // {"Int16$from_num32", "func(n:Num32, truncate=no -> Int16)"}); ADD_CONSTRUCTORS("Int8", // {"Int8$from_bool", "func(b:Bool -> Int8)"}, // @@ -495,7 +495,7 @@ env_t *global_env(bool source_mapping) { {"Int8$from_int32", "func(i:Int32, truncate=no -> Int8)"}, // {"Int8$from_int64", "func(i:Int64, truncate=no -> Int8)"}, // {"Int8$from_int", "func(i:Int, truncate=no -> Int8)"}, // - {"Int8$from_num", "func(n:Num, truncate=no -> Int8)"}, // + {"Int8$from_num64", "func(n:Num, truncate=no -> Int8)"}, // {"Int8$from_num32", "func(n:Num32, truncate=no -> Int8)"}); ADD_CONSTRUCTORS("Num", // {"Num$from_bool", "func(b:Bool -> Num)"}, // @@ -514,7 +514,7 @@ env_t *global_env(bool source_mapping) { {"Num32$from_int32", "func(i:Int32, truncate=no -> Num32)"}, // {"Num32$from_int64", "func(i:Int64, truncate=no -> Num32)"}, // {"Num32$from_int", "func(i:Int, truncate=no -> Num32)"}, // - {"Num32$from_num", "func(n:Num -> Num32)"}); + {"Num32$from_num64", "func(n:Num -> Num32)"}); ADD_CONSTRUCTORS("Path", // {"Path$escape_text", "func(text:Text -> Path)"}, // {"Path$escape_path", "func(path:Path -> Path)"}, // -- cgit v1.2.3 From 437be558a893ac70c030794df99a866e8ed01879 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Thu, 27 Nov 2025 12:05:49 -0500 Subject: Add `recursive` arg to Path.create_directory() --- src/environment.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/environment.c') diff --git a/src/environment.c b/src/environment.c index 6075ce49..88a15bb5 100644 --- a/src/environment.c +++ b/src/environment.c @@ -310,7 +310,8 @@ env_t *global_env(bool source_mapping) { {"child", "Path$child", "func(path:Path, child:Text -> Path)"}, // {"children", "Path$children", "func(path:Path, include_hidden=no -> [Path])"}, // {"concatenated_with", "Path$concat", "func(a,b:Path -> Path)"}, // - {"create_directory", "Path$create_directory", "func(path:Path, permissions=Int32(0o755))"}, // + {"create_directory", "Path$create_directory", + "func(path:Path, permissions=Int32(0o755), recursive=yes)"}, // {"current_dir", "Path$current_dir", "func(->Path)"}, // {"exists", "Path$exists", "func(path:Path -> Bool)"}, // {"expand_home", "Path$expand_home", "func(path:Path -> Path)"}, // -- cgit v1.2.3 From 8b897851facaa177e2346e0d97fcba7411dfc0aa Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Thu, 27 Nov 2025 12:35:52 -0500 Subject: Update `setenv()` to take an optional value, also bugfix for `setenv()` returning a value. --- src/environment.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/environment.c') diff --git a/src/environment.c b/src/environment.c index 88a15bb5..43d22c3d 100644 --- a/src/environment.c +++ b/src/environment.c @@ -540,7 +540,7 @@ env_t *global_env(bool source_mapping) { {"getenv", "getenv_text", "func(name:Text -> Text?)"}, {"print", "say", "func(text:Text, newline=yes)"}, {"say", "say", "func(text:Text, newline=yes)"}, - {"setenv", "setenv_text", "func(name:Text, value:Text -> Text?)"}, + {"setenv", "setenv_text", "func(name:Text, value:Text?)"}, {"sleep", "sleep_num", "func(seconds:Num)"}, }; -- cgit v1.2.3 From 4d8aa867c7f4661167a4742fbdd865ed2449503e Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 30 Nov 2025 14:12:01 -0500 Subject: Add `base` parameter to integer parsing functions --- src/environment.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/environment.c') diff --git a/src/environment.c b/src/environment.c index 43d22c3d..7e04fe79 100644 --- a/src/environment.c +++ b/src/environment.c @@ -93,7 +93,7 @@ env_t *global_env(bool source_mapping) { MAKE_TYPE("Empty", EMPTY_TYPE, Text("Empty$$type"), Text("Empty$$info")), MAKE_TYPE( // "Bool", Type(BoolType), Text("Bool_t"), Text("Bool$info"), - {"parse", "Bool$parse", "func(text:Text, remainder:&Text? = none -> Bool?)"}), + {"parse", "Bool$parse", "func(text:Text, remainder:&Text?=none -> Bool?)"}), MAKE_TYPE( // "Byte", Type(ByteType), Text("Byte_t"), Text("Byte$info"), {"get_bit", "Byte$get_bit", "func(x:Byte, bit_index:Int -> Bool)"}, // @@ -101,7 +101,7 @@ env_t *global_env(bool source_mapping) { {"is_between", "Byte$is_between", "func(x:Byte, low:Byte, high:Byte -> Bool)"}, // {"max", "Byte$max", "Byte"}, // {"min", "Byte$min", "Byte"}, // - {"parse", "Byte$parse", "func(text:Text, remainder:&Text? = none -> Byte?)"}, // + {"parse", "Byte$parse", "func(text:Text, base:Int?=none, remainder:&Text?=none -> Byte?)"}, // {"to", "Byte$to", "func(first:Byte, last:Byte, step:Int8?=none -> func(->Byte?))"}), MAKE_TYPE( // "Int", Type(BigIntType), Text("Int_t"), Text("Int$info"), {"abs", "Int$abs", "func(x:Int -> Int)"}, // @@ -126,7 +126,7 @@ env_t *global_env(bool source_mapping) { {"next_prime", "Int$next_prime", "func(x:Int -> Int)"}, // {"octal", "Int$octal", "func(i:Int, digits=0, prefix=yes -> Text)"}, // {"onward", "Int$onward", "func(first:Int,step=1 -> func(->Int?))"}, // - {"parse", "Int$parse", "func(text:Text, remainder:&Text? = none -> Int?)"}, // + {"parse", "Int$parse", "func(text:Text, base:Int?=none, remainder:&Text?=none -> Int?)"}, // {"plus", "Int$plus", "func(x,y:Int -> Int)"}, // {"power", "Int$power", "func(base:Int,exponent:Int -> Int)"}, // #if __GNU_MP_VERSION >= 6 @@ -145,7 +145,7 @@ env_t *global_env(bool source_mapping) { {"clamped", "Int64$clamped", "func(x,low,high:Int64 -> Int64)"}, // {"divided_by", "Int64$divided_by", "func(x,y:Int64 -> Int64)"}, // {"gcd", "Int64$gcd", "func(x,y:Int64 -> Int64)"}, // - {"parse", "Int64$parse", "func(text:Text, remainder:&Text? = none -> Int64?)"}, // + {"parse", "Int64$parse", "func(text:Text, base:Int?=none, remainder:&Text?=none -> Int64?)"}, // {"get_bit", "Int64$get_bit", "func(x:Int64, bit_index:Int -> Bool)"}, // {"hex", "Int64$hex", "func(i:Int64, digits=0, uppercase=yes, prefix=yes -> Text)"}, // {"is_between", "Int64$is_between", "func(x:Int64,low:Int64,high:Int64 -> Bool)"}, // @@ -167,7 +167,7 @@ env_t *global_env(bool source_mapping) { {"clamped", "Int32$clamped", "func(x,low,high:Int32 -> Int32)"}, // {"divided_by", "Int32$divided_by", "func(x,y:Int32 -> Int32)"}, // {"gcd", "Int32$gcd", "func(x,y:Int32 -> Int32)"}, // - {"parse", "Int32$parse", "func(text:Text, remainder:&Text? = none -> Int32?)"}, // + {"parse", "Int32$parse", "func(text:Text, base:Int?=none, remainder:&Text?=none -> Int32?)"}, // {"get_bit", "Int32$get_bit", "func(x:Int32, bit_index:Int -> Bool)"}, // {"hex", "Int32$hex", "func(i:Int32, digits=0, uppercase=yes, prefix=yes -> Text)"}, // {"is_between", "Int32$is_between", "func(x:Int32,low:Int32,high:Int32 -> Bool)"}, // @@ -189,7 +189,7 @@ env_t *global_env(bool source_mapping) { {"clamped", "Int16$clamped", "func(x,low,high:Int16 -> Int16)"}, // {"divided_by", "Int16$divided_by", "func(x,y:Int16 -> Int16)"}, // {"gcd", "Int16$gcd", "func(x,y:Int16 -> Int16)"}, // - {"parse", "Int16$parse", "func(text:Text, remainder:&Text? = none -> Int16?)"}, // + {"parse", "Int16$parse", "func(text:Text, base:Int?=none, remainder:&Text?=none -> Int16?)"}, // {"get_bit", "Int16$get_bit", "func(x:Int16, bit_index:Int -> Bool)"}, // {"hex", "Int16$hex", "func(i:Int16, digits=0, uppercase=yes, prefix=yes -> Text)"}, // {"is_between", "Int16$is_between", "func(x:Int16,low:Int16,high:Int16 -> Bool)"}, // @@ -211,7 +211,7 @@ env_t *global_env(bool source_mapping) { {"clamped", "Int8$clamped", "func(x,low,high:Int8 -> Int8)"}, // {"divided_by", "Int8$divided_by", "func(x,y:Int8 -> Int8)"}, // {"gcd", "Int8$gcd", "func(x,y:Int8 -> Int8)"}, // - {"parse", "Int8$parse", "func(text:Text, remainder:&Text? = none -> Int8?)"}, // + {"parse", "Int8$parse", "func(text:Text, base:Int?=none, remainder:&Text?=none -> Int8?)"}, // {"get_bit", "Int8$get_bit", "func(x:Int8, bit_index:Int -> Bool)"}, // {"hex", "Int8$hex", "func(i:Int8, digits=0, uppercase=yes, prefix=yes -> Text)"}, // {"is_between", "Int8$is_between", "func(x:Int8,low:Int8,high:Int8 -> Bool)"}, // @@ -245,7 +245,7 @@ env_t *global_env(bool source_mapping) { C(SQRT1_2), {"INF", "(Num_t)(INFINITY)", "Num"}, // {"TAU", "(Num_t)(2.*M_PI)", "Num"}, // {"mix", "Num$mix", "func(amount,x,y:Num -> Num)"}, // - {"parse", "Num$parse", "func(text:Text, remainder:&Text? = none -> Num?)"}, // + {"parse", "Num$parse", "func(text:Text, remainder:&Text?=none -> Num?)"}, // {"abs", "fabs", "func(n:Num -> Num)"}, // F_opt(acos), F_opt(acosh), F_opt(asin), F(asinh), F(atan), F_opt(atanh), F(cbrt), F(ceil), F_opt(cos), F(cosh), F(erf), F(erfc), F(exp), F(exp2), F(expm1), F(floor), F(j0), F(j1), F_opt(log), F_opt(log10), @@ -274,7 +274,7 @@ env_t *global_env(bool source_mapping) { {"INF", "(Num32_t)(INFINITY)", "Num32"}, // {"TAU", "(Num32_t)(2.f*M_PI)", "Num32"}, // {"mix", "Num32$mix", "func(amount,x,y:Num32 -> Num32)"}, // - {"parse", "Num32$parse", "func(text:Text, remainder:&Text? = none -> Num32?)"}, // + {"parse", "Num32$parse", "func(text:Text, remainder:&Text?=none -> Num32?)"}, // {"abs", "fabsf", "func(n:Num32 -> Num32)"}, // {"modulo", "Num32$mod", "func(x,y:Num32 -> Num32)"}, // {"modulo1", "Num32$mod1", "func(x,y:Num32 -> Num32)"}, // -- cgit v1.2.3 From 09942b27ae6fd7e7d394b2d251ef77c8a6f69e07 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 7 Dec 2025 19:02:13 -0500 Subject: Rename `Empty()` -> `Present()` for set-like tables --- src/environment.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/environment.c') diff --git a/src/environment.c b/src/environment.c index 7e04fe79..c5932e30 100644 --- a/src/environment.c +++ b/src/environment.c @@ -19,7 +19,7 @@ type_t *PATH_TYPE = NULL; public type_t *PATH_TYPE_TYPE = NULL; public -type_t *EMPTY_TYPE = NULL; +type_t *PRESENT_TYPE = NULL; static type_t *declare_type(env_t *env, const char *def_str) { ast_t *ast = parse_file_str(def_str); @@ -70,7 +70,7 @@ env_t *global_env(bool source_mapping) { PATH_TYPE_TYPE = declare_type(env, "enum PathType(Relative, Absolute, Home)"); PATH_TYPE = declare_type(env, "struct Path(type:PathType, components:[Text])"); - EMPTY_TYPE = declare_type(env, "struct Empty()"); + PRESENT_TYPE = declare_type(env, "struct Present()"); typedef struct { const char *name, *code, *type_str; @@ -90,7 +90,7 @@ env_t *global_env(bool source_mapping) { MAKE_TYPE("Void", Type(VoidType), Text("void"), Text("Void$info")), MAKE_TYPE("Abort", Type(AbortType), Text("void"), Text("Abort$info")), MAKE_TYPE("Memory", Type(MemoryType), Text("void"), Text("Memory$info")), - MAKE_TYPE("Empty", EMPTY_TYPE, Text("Empty$$type"), Text("Empty$$info")), + MAKE_TYPE("Present", PRESENT_TYPE, Text("Present$$type"), Text("Present$$info")), MAKE_TYPE( // "Bool", Type(BoolType), Text("Bool_t"), Text("Bool$info"), {"parse", "Bool$parse", "func(text:Text, remainder:&Text?=none -> Bool?)"}), @@ -530,7 +530,7 @@ env_t *global_env(bool source_mapping) { struct { const char *name, *code, *type_str; } global_vars[] = { - {"EMPTY", "EMPTY", "Empty"}, + {"PRESENT", "PRESENT", "Present"}, {"TOMO_VERSION", "TOMO_VERSION_TEXT", "Text"}, {"USE_COLOR", "USE_COLOR", "Bool"}, {"ask", "ask", "func(prompt:Text, bold=yes, force_tty=yes -> Text?)"}, -- cgit v1.2.3 From 544b1fb6a70d55bf368b827136cf0f37a26e8288 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 7 Dec 2025 21:42:45 -0500 Subject: Change Paths to be an enum of their different types. --- src/environment.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'src/environment.c') diff --git a/src/environment.c b/src/environment.c index c5932e30..bdbc8a4f 100644 --- a/src/environment.c +++ b/src/environment.c @@ -17,8 +17,6 @@ type_t *TEXT_TYPE = NULL; public type_t *PATH_TYPE = NULL; public -type_t *PATH_TYPE_TYPE = NULL; -public type_t *PRESENT_TYPE = NULL; static type_t *declare_type(env_t *env, const char *def_str) { @@ -67,8 +65,9 @@ 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_TYPE = declare_type(env, "enum PathType(Relative, Absolute, Home)"); - PATH_TYPE = declare_type(env, "struct Path(type:PathType, components:[Text])"); + PATH_TYPE = declare_type( + env, + "enum Path(AbsolutePath(components:[Text]), RelativePath(components:[Text]), HomePath(components:[Text]))"); PRESENT_TYPE = declare_type(env, "struct Present()"); @@ -291,11 +290,6 @@ env_t *global_env(bool source_mapping) { #undef F_opt #undef F #undef C - MAKE_TYPE( // - "PathType", PATH_TYPE_TYPE, Text("PathType_t"), Text("PathType$info"), // - {"Relative", "PATHTYPE_RELATIVE", "PathType"}, // - {"Absolute", "PATHTYPE_ABSOLUTE", "PathType"}, // - {"Home", "PATHTYPE_HOME", "PathType"}), MAKE_TYPE( // "Path", PATH_TYPE, Text("Path_t"), Text("Path$info"), // {"accessed", "Path$accessed", "func(path:Path, follow_symlinks=yes -> Int64?)"}, // @@ -310,6 +304,7 @@ env_t *global_env(bool source_mapping) { {"child", "Path$child", "func(path:Path, child:Text -> Path)"}, // {"children", "Path$children", "func(path:Path, include_hidden=no -> [Path])"}, // {"concatenated_with", "Path$concat", "func(a,b:Path -> Path)"}, // + {"components", "Path$components", "func(path:Path -> [Text])"}, // {"create_directory", "Path$create_directory", "func(path:Path, permissions=Int32(0o755), recursive=yes)"}, // {"current_dir", "Path$current_dir", "func(->Path)"}, // -- cgit v1.2.3 From 19c8450aa0a9ea008a3e5fd4ec44f7c3761db663 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 7 Dec 2025 22:53:45 -0500 Subject: Switch paths to use Result return values instead of fail() --- src/environment.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src/environment.c') diff --git a/src/environment.c b/src/environment.c index bdbc8a4f..f84b6697 100644 --- a/src/environment.c +++ b/src/environment.c @@ -18,6 +18,8 @@ public type_t *PATH_TYPE = NULL; public type_t *PRESENT_TYPE = NULL; +public +type_t *RESULT_TYPE = NULL; static type_t *declare_type(env_t *env, const char *def_str) { ast_t *ast = parse_file_str(def_str); @@ -68,6 +70,7 @@ env_t *global_env(bool source_mapping) { PATH_TYPE = declare_type( env, "enum Path(AbsolutePath(components:[Text]), RelativePath(components:[Text]), HomePath(components:[Text]))"); + RESULT_TYPE = declare_type(env, "enum Result(Success, Failure(reason:Text))"); PRESENT_TYPE = declare_type(env, "struct Present()"); @@ -90,6 +93,7 @@ env_t *global_env(bool source_mapping) { MAKE_TYPE("Abort", Type(AbortType), Text("void"), Text("Abort$info")), MAKE_TYPE("Memory", Type(MemoryType), Text("void"), Text("Memory$info")), MAKE_TYPE("Present", PRESENT_TYPE, Text("Present$$type"), Text("Present$$info")), + MAKE_TYPE("Result", RESULT_TYPE, Text("Result_t"), Text("Result$$info")), MAKE_TYPE( // "Bool", Type(BoolType), Text("Bool_t"), Text("Bool$info"), {"parse", "Bool$parse", "func(text:Text, remainder:&Text?=none -> Bool?)"}), @@ -293,8 +297,9 @@ env_t *global_env(bool source_mapping) { MAKE_TYPE( // "Path", PATH_TYPE, Text("Path_t"), Text("Path$info"), // {"accessed", "Path$accessed", "func(path:Path, follow_symlinks=yes -> Int64?)"}, // - {"append", "Path$append", "func(path:Path, text:Text, permissions=Int32(0o644))"}, // - {"append_bytes", "Path$append_bytes", "func(path:Path, bytes:[Byte], permissions=Int32(0o644))"}, // + {"append", "Path$append", "func(path:Path, text:Text, permissions=Int32(0o644) -> Result)"}, // + {"append_bytes", "Path$append_bytes", + "func(path:Path, bytes:[Byte], permissions=Int32(0o644) -> Result)"}, // {"base_name", "Path$base_name", "func(path:Path -> Text)"}, // {"by_line", "Path$by_line", "func(path:Path -> func(->Text?)?)"}, // {"can_execute", "Path$can_execute", "func(path:Path -> Bool)"}, // @@ -306,7 +311,7 @@ env_t *global_env(bool source_mapping) { {"concatenated_with", "Path$concat", "func(a,b:Path -> Path)"}, // {"components", "Path$components", "func(path:Path -> [Text])"}, // {"create_directory", "Path$create_directory", - "func(path:Path, permissions=Int32(0o755), recursive=yes)"}, // + "func(path:Path, permissions=Int32(0o755), recursive=yes -> Result)"}, // {"current_dir", "Path$current_dir", "func(->Path)"}, // {"exists", "Path$exists", "func(path:Path -> Bool)"}, // {"expand_home", "Path$expand_home", "func(path:Path -> Path)"}, // @@ -324,21 +329,21 @@ env_t *global_env(bool source_mapping) { {"lines", "Path$lines", "func(path:Path -> [Text]?)"}, // {"modified", "Path$modified", "func(path:Path, follow_symlinks=yes -> Int64?)"}, // {"owner", "Path$owner", "func(path:Path, follow_symlinks=yes -> Text?)"}, // - {"parent", "Path$parent", "func(path:Path -> Path)"}, // + {"parent", "Path$parent", "func(path:Path -> Path?)"}, // {"read", "Path$read", "func(path:Path -> Text?)"}, // {"read_bytes", "Path$read_bytes", "func(path:Path, limit:Int?=none -> [Byte]?)"}, // {"relative_to", "Path$relative_to", "func(path:Path, relative_to:Path -> Path)"}, // - {"remove", "Path$remove", "func(path:Path, ignore_missing=no)"}, // + {"remove", "Path$remove", "func(path:Path, ignore_missing=no -> Result)"}, // {"resolved", "Path$resolved", "func(path:Path, relative_to=(./) -> Path)"}, // - {"set_owner", "Path$set_owner", // - "func(path:Path, owner:Text?=none, group:Text?=none, follow_symlinks=yes)"}, // + {"set_owner", "Path$set_owner", + "func(path:Path, owner:Text?=none, group:Text?=none, follow_symlinks=yes -> Result)"}, // {"sibling", "Path$sibling", "func(path:Path, name:Text -> Path)"}, // {"subdirectories", "Path$children", "func(path:Path, include_hidden=no -> [Path])"}, // {"unique_directory", "Path$unique_directory", "func(path:Path -> Path)"}, // - {"write", "Path$write", "func(path:Path, text:Text, permissions=Int32(0o644))"}, // - {"write_bytes", "Path$write_bytes", "func(path:Path, bytes:[Byte], permissions=Int32(0o644))"}, // - {"write_unique", "Path$write_unique", "func(path:Path, text:Text -> Path)"}, // - {"write_unique_bytes", "Path$write_unique_bytes", "func(path:Path, bytes:[Byte] -> Path)"}), + {"write", "Path$write", "func(path:Path, text:Text, permissions=Int32(0o644) -> Result)"}, // + {"write_bytes", "Path$write_bytes", "func(path:Path, bytes:[Byte], permissions=Int32(0o644) -> Result)"}, // + {"write_unique", "Path$write_unique", "func(path:Path, text:Text -> Path?)"}, // + {"write_unique_bytes", "Path$write_unique_bytes", "func(path:Path, bytes:[Byte] -> Path?)"}), MAKE_TYPE( // "Text", TEXT_TYPE, Text("Text_t"), Text("Text$info"), // {"as_c_string", "Text$as_c_string", "func(text:Text -> CString)"}, // -- cgit v1.2.3 From 08c47e1fabd1a2fb43c18828db8ad845f7db3a99 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 7 Dec 2025 23:08:08 -0500 Subject: More correct handling for sleep() --- src/environment.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/environment.c') diff --git a/src/environment.c b/src/environment.c index f84b6697..cf662749 100644 --- a/src/environment.c +++ b/src/environment.c @@ -541,7 +541,7 @@ env_t *global_env(bool source_mapping) { {"print", "say", "func(text:Text, newline=yes)"}, {"say", "say", "func(text:Text, newline=yes)"}, {"setenv", "setenv_text", "func(name:Text, value:Text?)"}, - {"sleep", "sleep_num", "func(seconds:Num)"}, + {"sleep", "sleep_seconds", "func(seconds:Num)"}, }; for (size_t i = 0; i < sizeof(global_vars) / sizeof(global_vars[0]); i++) { -- cgit v1.2.3