From 1a31be6f27fcf4bf55d32fa9a5064b69ef2484a8 Mon Sep 17 00:00:00 2001 From: imaqtkatt Date: Thu, 22 Aug 2024 11:41:17 -0300 Subject: [PATCH 01/10] wip implement delete functions --- src/run.c | 103 ++++++++++++++++ tests/programs/io_delete/delete_file.bend | 11 ++ tests/programs/io_delete/delete_file.hvm | 109 +++++++++++++++++ .../io_delete/delete_non_existing_file.bend | 11 ++ .../io_delete/delete_non_existing_file.hvm | 110 ++++++++++++++++++ 5 files changed, 344 insertions(+) create mode 100644 tests/programs/io_delete/delete_file.bend create mode 100644 tests/programs/io_delete/delete_file.hvm create mode 100644 tests/programs/io_delete/delete_non_existing_file.bend create mode 100644 tests/programs/io_delete/delete_non_existing_file.hvm diff --git a/src/run.c b/src/run.c index 13b3fa94..e331fdbe 100644 --- a/src/run.c +++ b/src/run.c @@ -1,6 +1,9 @@ #include #include #include +#include +#include +// #include #include "hvm.c" // Readback: λ-Encoded Ctr @@ -716,6 +719,104 @@ Port io_dl_close(Net* net, Book* book, Port argm) { return inject_ok(net, new_port(ERA, 0)); } +// Deletes a single file or an empty directory at the specified path. +// Returns Ok(None) if successful, or Err(reason) if an error occurs. +// This function attempts to remove both files and empty directories without +// first checking the type of the path. +// Returns: Result<*, IOError> +Port io_delete_file(Net* net, Book* book, Port argm) { + Str path = readback_str(net, book, argm); + + int result = remove(path.buf); + free(path.buf); + + if (result == 0) { + return inject_ok(net, new_port(ERA, 0)); + } else { + return inject_io_err_inner(net, new_port(NUM, new_i24(errno))); + } +} + +int delete_directory_recursive(const char* path) { + DIR *d = opendir(path); + size_t path_len = strlen(path); + int r = -1; + + if (d) { + struct dirent *p; + r = 0; + + while (!r && (p = readdir(d))) { + int r2 = -1; + char *buf; + size_t len; + + if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, "..")) { + continue; + } + + len = path_len + strlen(p->d_name) + 2; + buf = malloc(len); + + if (buf) { + struct stat statbuf; + snprintf(buf, len, "%s/%s", path, p->d_name); + + if (!stat(buf, &statbuf)) { + if (S_ISDIR(statbuf.st_mode)) { + r2 = delete_directory_recursive(buf); + } else { + r2 = remove(buf); + } + } + + free(buf); + } + + r = r2; + } + + closedir(d); + } + + if (!r) { + r = remove(path); + } + + return r; +} + +// Deletes a directory at the specified path. If recursive is True, +// it will delete the directory and all its contents. +// Returns Ok(None) if successful, or Err(reason) if an error occurs. +// Note: For non-recursive deletion of an empty directory, +// this function behaves the same as delete_file(path). +// Returns: Result<*, IOError> +Port io_delete_directory(Net* net, Book* book, Port argm) { + Tup tup = readback_tup(net, book, argm, 2); + if (2 != tup.elem_len) { + return inject_io_err_type(net); + } + + Str path = readback_str(net, book, tup.elem_buf[0]); + u32 rec = get_u24(get_val(tup.elem_buf[1])); + + int res; + if (rec) { + res = delete_directory_recursive(path.buf); + free(path.buf); + } else { + res = remove(path.buf); + free(path.buf); + } + + if (0 == res) { + return inject_ok(net, new_port(ERA, 0)); + } else { + return inject_io_err_inner(net, new_port(NUM, new_i24(errno))); + } +} + // Book Loader // ----------- @@ -731,6 +832,8 @@ void book_init(Book* book) { book->ffns_buf[book->ffns_len++] = (FFn){"DL_OPEN", io_dl_open}; book->ffns_buf[book->ffns_len++] = (FFn){"DL_CALL", io_dl_call}; book->ffns_buf[book->ffns_len++] = (FFn){"DL_CLOSE", io_dl_open}; + book->ffns_buf[book->ffns_len++] = (FFn){"DELETE_FILE", io_delete_file}; + book->ffns_buf[book->ffns_len++] = (FFn){"DELETE_DIRECTORY", io_delete_directory}; } // Monadic IO Evaluator diff --git a/tests/programs/io_delete/delete_file.bend b/tests/programs/io_delete/delete_file.bend new file mode 100644 index 00000000..2d36b517 --- /dev/null +++ b/tests/programs/io_delete/delete_file.bend @@ -0,0 +1,11 @@ +test-io = 1 + +IO/FS/delete_file path = + (call "DELETE_FILE" path) + +main = + use path = "./tests/programs/io_remove/files/remove_file.txt" + with IO { + ask s = (IO/FS/delete_file path) + (wrap s) + } diff --git a/tests/programs/io_delete/delete_file.hvm b/tests/programs/io_delete/delete_file.hvm new file mode 100644 index 00000000..64d3ba7c --- /dev/null +++ b/tests/programs/io_delete/delete_file.hvm @@ -0,0 +1,109 @@ +@IO/Call = (a (b (c (d ((@IO/Call/tag (a (b (c (d e))))) e))))) + +@IO/Call/tag = 1 + +@IO/Done = (a (b ((@IO/Done/tag (a (b c))) c))) + +@IO/Done/tag = 0 + +@IO/FS/delete_file = l + & @call ~ (k l) + & @String/Cons ~ (68 (j k)) + & @String/Cons ~ (69 (i j)) + & @String/Cons ~ (76 (h i)) + & @String/Cons ~ (69 (g h)) + & @String/Cons ~ (84 (f g)) + & @String/Cons ~ (69 (e f)) + & @String/Cons ~ (95 (d e)) + & @String/Cons ~ (70 (c d)) + & @String/Cons ~ (73 (b c)) + & @String/Cons ~ (76 (a b)) + & @String/Cons ~ (69 (@String/Nil a)) + +@IO/MAGIC = (13683217 16719857) + +@IO/bind = ((@IO/bind__C2 a) a) + +@IO/bind__C0 = (* (b (a c))) + & @undefer ~ (a (b c)) + +@IO/bind__C1 = (* (* (a (b ((c d) (e g)))))) + & @IO/Call ~ (@IO/MAGIC (a (b ((c f) g)))) + & @IO/bind ~ (d (e f)) + +@IO/bind__C2 = (?((@IO/bind__C0 @IO/bind__C1) a) a) + +@IO/wrap = a + & @IO/Done ~ (@IO/MAGIC a) + +@String/Cons = (a (b ((@String/Cons/tag (a (b c))) c))) + +@String/Cons/tag = 1 + +@String/Nil = ((@String/Nil/tag a) a) + +@String/Nil/tag = 0 + +@call = (a (b c)) + & @IO/Call ~ (@IO/MAGIC (a (b (@call__C0 c)))) + +@call__C0 = a + & @IO/Done ~ (@IO/MAGIC a) + +@main = ac + & @IO/bind ~ (wb ((((xb xb) (@IO/wrap zb)) zb) ac)) + & @IO/FS/delete_file ~ (vb wb) + & @String/Cons ~ (46 (ub vb)) + & @String/Cons ~ (47 (tb ub)) + & @String/Cons ~ (116 (sb tb)) + & @String/Cons ~ (101 (rb sb)) + & @String/Cons ~ (115 (qb rb)) + & @String/Cons ~ (116 (pb qb)) + & @String/Cons ~ (115 (ob pb)) + & @String/Cons ~ (47 (nb ob)) + & @String/Cons ~ (112 (mb nb)) + & @String/Cons ~ (114 (lb mb)) + & @String/Cons ~ (111 (kb lb)) + & @String/Cons ~ (103 (jb kb)) + & @String/Cons ~ (114 (ib jb)) + & @String/Cons ~ (97 (hb ib)) + & @String/Cons ~ (109 (gb hb)) + & @String/Cons ~ (115 (fb gb)) + & @String/Cons ~ (47 (eb fb)) + & @String/Cons ~ (105 (db eb)) + & @String/Cons ~ (111 (cb db)) + & @String/Cons ~ (95 (bb cb)) + & @String/Cons ~ (114 (ab bb)) + & @String/Cons ~ (101 (z ab)) + & @String/Cons ~ (109 (y z)) + & @String/Cons ~ (111 (x y)) + & @String/Cons ~ (118 (w x)) + & @String/Cons ~ (101 (v w)) + & @String/Cons ~ (47 (u v)) + & @String/Cons ~ (102 (t u)) + & @String/Cons ~ (105 (s t)) + & @String/Cons ~ (108 (r s)) + & @String/Cons ~ (101 (q r)) + & @String/Cons ~ (115 (p q)) + & @String/Cons ~ (47 (o p)) + & @String/Cons ~ (114 (n o)) + & @String/Cons ~ (101 (m n)) + & @String/Cons ~ (109 (l m)) + & @String/Cons ~ (111 (k l)) + & @String/Cons ~ (118 (j k)) + & @String/Cons ~ (101 (i j)) + & @String/Cons ~ (95 (h i)) + & @String/Cons ~ (102 (g h)) + & @String/Cons ~ (105 (f g)) + & @String/Cons ~ (108 (e f)) + & @String/Cons ~ (101 (d e)) + & @String/Cons ~ (46 (c d)) + & @String/Cons ~ (116 (b c)) + & @String/Cons ~ (120 (a b)) + & @String/Cons ~ (116 (@String/Nil a)) + +@test-io = 1 + +@undefer = (((a a) b) b) + + diff --git a/tests/programs/io_delete/delete_non_existing_file.bend b/tests/programs/io_delete/delete_non_existing_file.bend new file mode 100644 index 00000000..b79f34ce --- /dev/null +++ b/tests/programs/io_delete/delete_non_existing_file.bend @@ -0,0 +1,11 @@ +test-io = 1 + +IO/FS/delete_file path = + (call "DELETE_FILE" path) + +main = + use path = "./tests/programs/io_remove/files/non_existing.txt" + with IO { + ask s = (IO/FS/delete_file path) + (wrap s) + } diff --git a/tests/programs/io_delete/delete_non_existing_file.hvm b/tests/programs/io_delete/delete_non_existing_file.hvm new file mode 100644 index 00000000..cd749e09 --- /dev/null +++ b/tests/programs/io_delete/delete_non_existing_file.hvm @@ -0,0 +1,110 @@ +@IO/Call = (a (b (c (d ((@IO/Call/tag (a (b (c (d e))))) e))))) + +@IO/Call/tag = 1 + +@IO/Done = (a (b ((@IO/Done/tag (a (b c))) c))) + +@IO/Done/tag = 0 + +@IO/FS/delete_file = l + & @call ~ (k l) + & @String/Cons ~ (68 (j k)) + & @String/Cons ~ (69 (i j)) + & @String/Cons ~ (76 (h i)) + & @String/Cons ~ (69 (g h)) + & @String/Cons ~ (84 (f g)) + & @String/Cons ~ (69 (e f)) + & @String/Cons ~ (95 (d e)) + & @String/Cons ~ (70 (c d)) + & @String/Cons ~ (73 (b c)) + & @String/Cons ~ (76 (a b)) + & @String/Cons ~ (69 (@String/Nil a)) + +@IO/MAGIC = (13683217 16719857) + +@IO/bind = ((@IO/bind__C2 a) a) + +@IO/bind__C0 = (* (b (a c))) + & @undefer ~ (a (b c)) + +@IO/bind__C1 = (* (* (a (b ((c d) (e g)))))) + & @IO/Call ~ (@IO/MAGIC (a (b ((c f) g)))) + & @IO/bind ~ (d (e f)) + +@IO/bind__C2 = (?((@IO/bind__C0 @IO/bind__C1) a) a) + +@IO/wrap = a + & @IO/Done ~ (@IO/MAGIC a) + +@String/Cons = (a (b ((@String/Cons/tag (a (b c))) c))) + +@String/Cons/tag = 1 + +@String/Nil = ((@String/Nil/tag a) a) + +@String/Nil/tag = 0 + +@call = (a (b c)) + & @IO/Call ~ (@IO/MAGIC (a (b (@call__C0 c)))) + +@call__C0 = a + & @IO/Done ~ (@IO/MAGIC a) + +@main = bc + & @IO/bind ~ (xb ((((yb yb) (@IO/wrap ac)) ac) bc)) + & @IO/FS/delete_file ~ (wb xb) + & @String/Cons ~ (46 (vb wb)) + & @String/Cons ~ (47 (ub vb)) + & @String/Cons ~ (116 (tb ub)) + & @String/Cons ~ (101 (sb tb)) + & @String/Cons ~ (115 (rb sb)) + & @String/Cons ~ (116 (qb rb)) + & @String/Cons ~ (115 (pb qb)) + & @String/Cons ~ (47 (ob pb)) + & @String/Cons ~ (112 (nb ob)) + & @String/Cons ~ (114 (mb nb)) + & @String/Cons ~ (111 (lb mb)) + & @String/Cons ~ (103 (kb lb)) + & @String/Cons ~ (114 (jb kb)) + & @String/Cons ~ (97 (ib jb)) + & @String/Cons ~ (109 (hb ib)) + & @String/Cons ~ (115 (gb hb)) + & @String/Cons ~ (47 (fb gb)) + & @String/Cons ~ (105 (eb fb)) + & @String/Cons ~ (111 (db eb)) + & @String/Cons ~ (95 (cb db)) + & @String/Cons ~ (114 (bb cb)) + & @String/Cons ~ (101 (ab bb)) + & @String/Cons ~ (109 (z ab)) + & @String/Cons ~ (111 (y z)) + & @String/Cons ~ (118 (x y)) + & @String/Cons ~ (101 (w x)) + & @String/Cons ~ (47 (v w)) + & @String/Cons ~ (102 (u v)) + & @String/Cons ~ (105 (t u)) + & @String/Cons ~ (108 (s t)) + & @String/Cons ~ (101 (r s)) + & @String/Cons ~ (115 (q r)) + & @String/Cons ~ (47 (p q)) + & @String/Cons ~ (110 (o p)) + & @String/Cons ~ (111 (n o)) + & @String/Cons ~ (110 (m n)) + & @String/Cons ~ (95 (l m)) + & @String/Cons ~ (101 (k l)) + & @String/Cons ~ (120 (j k)) + & @String/Cons ~ (105 (i j)) + & @String/Cons ~ (115 (h i)) + & @String/Cons ~ (116 (g h)) + & @String/Cons ~ (105 (f g)) + & @String/Cons ~ (110 (e f)) + & @String/Cons ~ (103 (d e)) + & @String/Cons ~ (46 (c d)) + & @String/Cons ~ (116 (b c)) + & @String/Cons ~ (120 (a b)) + & @String/Cons ~ (116 (@String/Nil a)) + +@test-io = 1 + +@undefer = (((a a) b) b) + + From 49c9662d43b7144868a4d230720876cf5263ff9a Mon Sep 17 00:00:00 2001 From: imaqtkatt Date: Thu, 22 Aug 2024 14:11:55 -0300 Subject: [PATCH 02/10] #420 add function to create directories --- src/hvm.c | 4 +- src/run.c | 21 +- tests/programs/io/create_directory.bend | 21 ++ tests/programs/io/create_directory.hvm | 86 ++++++ tests/programs/io/delete_dir_file.bend | 16 ++ tests/programs/io/delete_dir_file.hvm | 90 ++++++ tests/programs/io/delete_dir_recursive.bend | 32 +++ tests/programs/io/delete_dir_recursive.hvm | 261 ++++++++++++++++++ tests/programs/io/delete_empty_dir.bend | 18 ++ tests/programs/io/delete_empty_dir.hvm | 79 ++++++ tests/programs/io/delete_file.bend | 16 ++ tests/programs/io/delete_file.hvm | 208 ++++++++++++++ .../delete_non_existing_file.bend | 6 +- .../delete_non_existing_file.hvm | 39 +-- tests/programs/io_delete/delete_file.bend | 11 - tests/programs/io_delete/delete_file.hvm | 109 -------- 16 files changed, 856 insertions(+), 161 deletions(-) create mode 100644 tests/programs/io/create_directory.bend create mode 100644 tests/programs/io/create_directory.hvm create mode 100644 tests/programs/io/delete_dir_file.bend create mode 100644 tests/programs/io/delete_dir_file.hvm create mode 100644 tests/programs/io/delete_dir_recursive.bend create mode 100644 tests/programs/io/delete_dir_recursive.hvm create mode 100644 tests/programs/io/delete_empty_dir.bend create mode 100644 tests/programs/io/delete_empty_dir.hvm create mode 100644 tests/programs/io/delete_file.bend create mode 100644 tests/programs/io/delete_file.hvm rename tests/programs/{io_delete => io}/delete_non_existing_file.bend (64%) rename tests/programs/{io_delete => io}/delete_non_existing_file.hvm (60%) delete mode 100644 tests/programs/io_delete/delete_file.bend delete mode 100644 tests/programs/io_delete/delete_file.hvm diff --git a/src/hvm.c b/src/hvm.c index 8d116de9..3a68857c 100644 --- a/src/hvm.c +++ b/src/hvm.c @@ -809,7 +809,7 @@ static inline Port enter(Net* net, Port var) { } // Atomically Links `A ~ B`. -static inline void link(Net* net, TM* tm, Port A, Port B) { +static inline void link_ports(Net* net, TM* tm, Port A, Port B) { // Attempts to directionally point `A ~> B` while (true) { // If `A` is NODE: swap `A` and `B`, and continue @@ -842,7 +842,7 @@ static inline void link(Net* net, TM* tm, Port A, Port B) { // Links `A ~ B` (as a pair). static inline void link_pair(Net* net, TM* tm, Pair AB) { - link(net, tm, get_fst(AB), get_snd(AB)); + link_ports(net, tm, get_fst(AB), get_snd(AB)); } // Interactions diff --git a/src/run.c b/src/run.c index e331fdbe..09352d00 100644 --- a/src/run.c +++ b/src/run.c @@ -3,7 +3,7 @@ #include #include #include -// #include +#include #include "hvm.c" // Readback: λ-Encoded Ctr @@ -780,7 +780,7 @@ int delete_directory_recursive(const char* path) { } if (!r) { - r = remove(path); + r = rmdir(path); } return r; @@ -806,7 +806,7 @@ Port io_delete_directory(Net* net, Book* book, Port argm) { res = delete_directory_recursive(path.buf); free(path.buf); } else { - res = remove(path.buf); + res = rmdir(path.buf); free(path.buf); } @@ -817,6 +817,20 @@ Port io_delete_directory(Net* net, Book* book, Port argm) { } } +Port io_mkdir(Net* net, Book* book, Port argm) { + Str name = readback_str(net, book, argm); + + const mode_t mode = 0777; + int status = mkdir(name.buf, mode); + free(name.buf); + + if (status) { + return inject_io_err_inner(net, new_port(NUM, new_i24(errno))); + } else { + return inject_ok(net, new_port(ERA, 0)); + } +} + // Book Loader // ----------- @@ -834,6 +848,7 @@ void book_init(Book* book) { book->ffns_buf[book->ffns_len++] = (FFn){"DL_CLOSE", io_dl_open}; book->ffns_buf[book->ffns_len++] = (FFn){"DELETE_FILE", io_delete_file}; book->ffns_buf[book->ffns_len++] = (FFn){"DELETE_DIRECTORY", io_delete_directory}; + book->ffns_buf[book->ffns_len++] = (FFn){"MKDIR", io_mkdir}; } // Monadic IO Evaluator diff --git a/tests/programs/io/create_directory.bend b/tests/programs/io/create_directory.bend new file mode 100644 index 00000000..e88b4ee9 --- /dev/null +++ b/tests/programs/io/create_directory.bend @@ -0,0 +1,21 @@ +#{ + Creates the batata directory and then deletes it. +#} + +test-io = 1 + +IO/FS/mkdir path = + (call "MKDIR" path) + +IO/FS/delete_directory path recursive = + (call "DELETE_DIRECTORY" (path, recursive)) + +False = 0 + +main = + let path = "./batata" + with IO { + ask * = (IO/FS/mkdir path) + ask s = (IO/FS/delete_directory path False) + (wrap s) + } diff --git a/tests/programs/io/create_directory.hvm b/tests/programs/io/create_directory.hvm new file mode 100644 index 00000000..a1baab58 --- /dev/null +++ b/tests/programs/io/create_directory.hvm @@ -0,0 +1,86 @@ +@False = 0 + +@IO/Call = (a (b (c (d ((@IO/Call/tag (a (b (c (d e))))) e))))) + +@IO/Call/tag = 1 + +@IO/Done = (a (b ((@IO/Done/tag (a (b c))) c))) + +@IO/Done/tag = 0 + +@IO/FS/delete_directory = (q (r s)) + & @call ~ (p ((q r) s)) + & @String/Cons ~ (68 (o p)) + & @String/Cons ~ (69 (n o)) + & @String/Cons ~ (76 (m n)) + & @String/Cons ~ (69 (l m)) + & @String/Cons ~ (84 (k l)) + & @String/Cons ~ (69 (j k)) + & @String/Cons ~ (95 (i j)) + & @String/Cons ~ (68 (h i)) + & @String/Cons ~ (73 (g h)) + & @String/Cons ~ (82 (f g)) + & @String/Cons ~ (69 (e f)) + & @String/Cons ~ (67 (d e)) + & @String/Cons ~ (84 (c d)) + & @String/Cons ~ (79 (b c)) + & @String/Cons ~ (82 (a b)) + & @String/Cons ~ (89 (@String/Nil a)) + +@IO/FS/mkdir = f + & @call ~ (e f) + & @String/Cons ~ (77 (d e)) + & @String/Cons ~ (75 (c d)) + & @String/Cons ~ (68 (b c)) + & @String/Cons ~ (73 (a b)) + & @String/Cons ~ (82 (@String/Nil a)) + +@IO/MAGIC = (13683217 16719857) + +@IO/bind = ((@IO/bind__C2 a) a) + +@IO/bind__C0 = (* (b (a c))) + & @undefer ~ (a (b c)) + +@IO/bind__C1 = (* (* (a (b ((c d) (e g)))))) + & @IO/Call ~ (@IO/MAGIC (a (b ((c f) g)))) + & @IO/bind ~ (d (e f)) + +@IO/bind__C2 = (?((@IO/bind__C0 @IO/bind__C1) a) a) + +@IO/wrap = a + & @IO/Done ~ (@IO/MAGIC a) + +@String/Cons = (a (b ((@String/Cons/tag (a (b c))) c))) + +@String/Cons/tag = 1 + +@String/Nil = ((@String/Nil/tag a) a) + +@String/Nil/tag = 0 + +@call = (a (b c)) + & @IO/Call ~ (@IO/MAGIC (a (b (@call__C0 c)))) + +@call__C0 = a + & @IO/Done ~ (@IO/MAGIC a) + +@main = s + & @IO/bind ~ (i ((((j (n (* p))) (q (@IO/wrap r))) r) s)) + & @String/Cons ~ (46 (g {h q})) + & @String/Cons ~ (47 (f g)) + & @String/Cons ~ (98 (e f)) + & @String/Cons ~ (97 (d e)) + & @String/Cons ~ (116 (c d)) + & @String/Cons ~ (97 (b c)) + & @String/Cons ~ (116 (a b)) + & @String/Cons ~ (97 (@String/Nil a)) + & @IO/FS/mkdir ~ (h i) + & @IO/bind ~ (k ((((l l) (n o)) o) p)) + & @IO/FS/delete_directory ~ (j (@False k)) + +@test-io = 1 + +@undefer = (((a a) b) b) + + diff --git a/tests/programs/io/delete_dir_file.bend b/tests/programs/io/delete_dir_file.bend new file mode 100644 index 00000000..537e95c6 --- /dev/null +++ b/tests/programs/io/delete_dir_file.bend @@ -0,0 +1,16 @@ +#{ + Calls the delete_directory function with a file path as argument. +#} + +test-io = 1 + +IO/FS/delete_directory path recursive = + (call "DELETE_DIRECTORY" (path, recursive)) + +False = 0 + +main = + with IO { + ask s = (IO/FS/delete_directory "./delete_dir_file.bend" False) + (wrap s) + } diff --git a/tests/programs/io/delete_dir_file.hvm b/tests/programs/io/delete_dir_file.hvm new file mode 100644 index 00000000..887f18d8 --- /dev/null +++ b/tests/programs/io/delete_dir_file.hvm @@ -0,0 +1,90 @@ +@False = 0 + +@IO/Call = (a (b (c (d ((@IO/Call/tag (a (b (c (d e))))) e))))) + +@IO/Call/tag = 1 + +@IO/Done = (a (b ((@IO/Done/tag (a (b c))) c))) + +@IO/Done/tag = 0 + +@IO/FS/delete_directory = (q (r s)) + & @call ~ (p ((q r) s)) + & @String/Cons ~ (68 (o p)) + & @String/Cons ~ (69 (n o)) + & @String/Cons ~ (76 (m n)) + & @String/Cons ~ (69 (l m)) + & @String/Cons ~ (84 (k l)) + & @String/Cons ~ (69 (j k)) + & @String/Cons ~ (95 (i j)) + & @String/Cons ~ (68 (h i)) + & @String/Cons ~ (73 (g h)) + & @String/Cons ~ (82 (f g)) + & @String/Cons ~ (69 (e f)) + & @String/Cons ~ (67 (d e)) + & @String/Cons ~ (84 (c d)) + & @String/Cons ~ (79 (b c)) + & @String/Cons ~ (82 (a b)) + & @String/Cons ~ (89 (@String/Nil a)) + +@IO/MAGIC = (13683217 16719857) + +@IO/bind = ((@IO/bind__C2 a) a) + +@IO/bind__C0 = (* (b (a c))) + & @undefer ~ (a (b c)) + +@IO/bind__C1 = (* (* (a (b ((c d) (e g)))))) + & @IO/Call ~ (@IO/MAGIC (a (b ((c f) g)))) + & @IO/bind ~ (d (e f)) + +@IO/bind__C2 = (?((@IO/bind__C0 @IO/bind__C1) a) a) + +@IO/wrap = a + & @IO/Done ~ (@IO/MAGIC a) + +@String/Cons = (a (b ((@String/Cons/tag (a (b c))) c))) + +@String/Cons/tag = 1 + +@String/Nil = ((@String/Nil/tag a) a) + +@String/Nil/tag = 0 + +@call = (a (b c)) + & @IO/Call ~ (@IO/MAGIC (a (b (@call__C0 c)))) + +@call__C0 = a + & @IO/Done ~ (@IO/MAGIC a) + +@main = ab + & @IO/bind ~ (w ((((x x) (@IO/wrap z)) z) ab)) + & @IO/FS/delete_directory ~ (v (@False w)) + & @String/Cons ~ (46 (u v)) + & @String/Cons ~ (47 (t u)) + & @String/Cons ~ (100 (s t)) + & @String/Cons ~ (101 (r s)) + & @String/Cons ~ (108 (q r)) + & @String/Cons ~ (101 (p q)) + & @String/Cons ~ (116 (o p)) + & @String/Cons ~ (101 (n o)) + & @String/Cons ~ (95 (m n)) + & @String/Cons ~ (100 (l m)) + & @String/Cons ~ (105 (k l)) + & @String/Cons ~ (114 (j k)) + & @String/Cons ~ (95 (i j)) + & @String/Cons ~ (102 (h i)) + & @String/Cons ~ (105 (g h)) + & @String/Cons ~ (108 (f g)) + & @String/Cons ~ (101 (e f)) + & @String/Cons ~ (46 (d e)) + & @String/Cons ~ (98 (c d)) + & @String/Cons ~ (101 (b c)) + & @String/Cons ~ (110 (a b)) + & @String/Cons ~ (100 (@String/Nil a)) + +@test-io = 1 + +@undefer = (((a a) b) b) + + diff --git a/tests/programs/io/delete_dir_recursive.bend b/tests/programs/io/delete_dir_recursive.bend new file mode 100644 index 00000000..6e9a859a --- /dev/null +++ b/tests/programs/io/delete_dir_recursive.bend @@ -0,0 +1,32 @@ +#{ + Creates the following tree structure and then deletes A and its children. + A + |-- a.txt + |-- AA + | `-- aa.txt + `-- AB + `-- ab.txt +#} + +test-io = 1 + +IO/FS/mkdir path = + (call "MKDIR" path) + +IO/FS/delete_directory path recursive = + (call "DELETE_DIRECTORY" (path, recursive)) + +True = 1 + +main = + with IO { + ask * = (IO/FS/mkdir "A") + ask * = (IO/FS/mkdir "A/AA") + ask * = (IO/FS/mkdir "A/AB") + ask * = (IO/FS/write_file "A/a.txt" (String/encode_utf8 "a")) + ask * = (IO/FS/write_file "A/AA/aa.txt" (String/encode_utf8 "aa")) + ask * = (IO/FS/write_file "A/AB/ab.txt" (String/encode_utf8 "ab")) + + ask s = (IO/FS/delete_directory "A" True) + (wrap s) + } diff --git a/tests/programs/io/delete_dir_recursive.hvm b/tests/programs/io/delete_dir_recursive.hvm new file mode 100644 index 00000000..a940ae0e --- /dev/null +++ b/tests/programs/io/delete_dir_recursive.hvm @@ -0,0 +1,261 @@ +@IO/Call = (a (b (c (d ((@IO/Call/tag (a (b (c (d e))))) e))))) + +@IO/Call/tag = 1 + +@IO/Done = (a (b ((@IO/Done/tag (a (b c))) c))) + +@IO/Done/tag = 0 + +@IO/FS/close = (f g) + & @IO/Call ~ (@IO/MAGIC (e (f (@IO/wrap g)))) + & @String/Cons ~ (67 (d e)) + & @String/Cons ~ (76 (c d)) + & @String/Cons ~ (79 (b c)) + & @String/Cons ~ (83 (a b)) + & @String/Cons ~ (69 (@String/Nil a)) + +@IO/FS/delete_directory = (q (r s)) + & @call ~ (p ((q r) s)) + & @String/Cons ~ (68 (o p)) + & @String/Cons ~ (69 (n o)) + & @String/Cons ~ (76 (m n)) + & @String/Cons ~ (69 (l m)) + & @String/Cons ~ (84 (k l)) + & @String/Cons ~ (69 (j k)) + & @String/Cons ~ (95 (i j)) + & @String/Cons ~ (68 (h i)) + & @String/Cons ~ (73 (g h)) + & @String/Cons ~ (82 (f g)) + & @String/Cons ~ (69 (e f)) + & @String/Cons ~ (67 (d e)) + & @String/Cons ~ (84 (c d)) + & @String/Cons ~ (79 (b c)) + & @String/Cons ~ (82 (a b)) + & @String/Cons ~ (89 (@String/Nil a)) + +@IO/FS/mkdir = f + & @call ~ (e f) + & @String/Cons ~ (77 (d e)) + & @String/Cons ~ (75 (c d)) + & @String/Cons ~ (68 (b c)) + & @String/Cons ~ (73 (a b)) + & @String/Cons ~ (82 (@String/Nil a)) + +@IO/FS/open = (e (f g)) + & @IO/Call ~ (@IO/MAGIC (d ((e f) (@IO/wrap g)))) + & @String/Cons ~ (79 (c d)) + & @String/Cons ~ (80 (b c)) + & @String/Cons ~ (69 (a b)) + & @String/Cons ~ (78 (@String/Nil a)) + +@IO/FS/write = (f (g h)) + & @IO/Call ~ (@IO/MAGIC (e ((f g) (@IO/wrap h)))) + & @String/Cons ~ (87 (d e)) + & @String/Cons ~ (82 (c d)) + & @String/Cons ~ (73 (b c)) + & @String/Cons ~ (84 (a b)) + & @String/Cons ~ (69 (@String/Nil a)) + +@IO/FS/write_file = (a (d f)) + & @IO/bind ~ (c (((@IO/FS/write_file__C5 (d (@IO/wrap e))) e) f)) + & @IO/FS/open ~ (a (b c)) + & @String/Cons ~ (119 (@String/Nil b)) + +@IO/FS/write_file__C0 = ((b c) (a (* c))) + & @Result/Ok ~ (a b) + +@IO/FS/write_file__C1 = (a (d (e (* g)))) + & @IO/bind ~ (c (((@IO/FS/write_file__C0 (d (e f))) f) g)) + & @IO/done_on_err ~ (b c) + & @IO/FS/close ~ (a b) + +@IO/FS/write_file__C2 = ({a e} ({b g} (f i))) + & @IO/bind ~ (d (((@IO/FS/write_file__C1 (e (f (g h)))) h) i)) + & @IO/done_on_err ~ (c d) + & @IO/FS/write ~ (a (b c)) + +@IO/FS/write_file__C3 = (* (a (* ((b c) c)))) + & @Result/Err ~ (a b) + +@IO/FS/write_file__C4 = (?((@IO/FS/write_file__C2 @IO/FS/write_file__C3) a) a) + +@IO/FS/write_file__C5 = (a (b ((@IO/FS/write_file__C4 (a (b c))) c))) + +@IO/MAGIC = (13683217 16719857) + +@IO/bind = ((@IO/bind__C2 a) a) + +@IO/bind__C0 = (* (b (a c))) + & @undefer ~ (a (b c)) + +@IO/bind__C1 = (* (* (a (b ((c d) (e g)))))) + & @IO/Call ~ (@IO/MAGIC (a (b ((c f) g)))) + & @IO/bind ~ (d (e f)) + +@IO/bind__C2 = (?((@IO/bind__C0 @IO/bind__C1) a) a) + +@IO/done_on_err = ((@IO/done_on_err__C5 a) a) + +@IO/done_on_err__C0 = (a ((a b) b)) + +@IO/done_on_err__C1 = (* (a (* c))) + & @IO/Done ~ (@IO/MAGIC (b c)) + & @Result/Err ~ (a b) + +@IO/done_on_err__C2 = (?((@IO/done_on_err__C0 @IO/done_on_err__C1) a) a) + +@IO/done_on_err__C3 = a + & @IO/Done ~ a + +@IO/done_on_err__C4 = (* (a (b (c (d f))))) + & @IO/Call ~ (a (b (c (((@IO/done_on_err__C2 (d e)) e) f)))) + +@IO/done_on_err__C5 = (?((@IO/done_on_err__C3 @IO/done_on_err__C4) a) a) + +@IO/wrap = a + & @IO/Done ~ (@IO/MAGIC a) + +@List/Cons = (a (b ((@List/Cons/tag (a (b c))) c))) + +@List/Cons/tag = 1 + +@List/Nil = ((@List/Nil/tag a) a) + +@List/Nil/tag = 0 + +@Result/Err = (a ((@Result/Err/tag (a b)) b)) + +@Result/Err/tag = 1 + +@Result/Ok = (a ((@Result/Ok/tag (a b)) b)) + +@Result/Ok/tag = 0 + +@String/Cons = (a (b ((@String/Cons/tag (a (b c))) c))) + +@String/Cons/tag = 1 + +@String/Nil = ((@String/Nil/tag a) a) + +@String/Nil/tag = 0 + +@String/encode_utf8 = ((@String/encode_utf8__C7 a) a) + +@String/encode_utf8__C0 = ({$([&0x000003F] g) {$([:>>0x0000006] $([&0x000003F] e)) {$([:>>0x000000C] $([&0x000003F] c)) $([:>>0x0000012] a)}}} (i n)) + & @List/Cons ~ (b (m n)) + & $(a b) ~ [|0x00000F0] + & @List/Cons ~ (d (l m)) + & $(c d) ~ [|0x0000080] + & @List/Cons ~ (f (k l)) + & $(e f) ~ [|0x0000080] + & @List/Cons ~ (h (j k)) + & $(g h) ~ [|0x0000080] + & @String/encode_utf8 ~ (i j) + +@String/encode_utf8__C1 = (* ({$([&0x000003F] e) {$([:>>0x0000006] $([&0x000003F] c)) $([:>>0x000000C] a)}} (g k))) + & @List/Cons ~ (b (j k)) + & $(a b) ~ [|0x00000E0] + & @List/Cons ~ (d (i j)) + & $(c d) ~ [|0x0000080] + & @List/Cons ~ (f (h i)) + & $(e f) ~ [|0x0000080] + & @String/encode_utf8 ~ (g h) + +@String/encode_utf8__C2 = ({$([<0x000FFFF] a) b} c) + & $(a ?((@String/encode_utf8__C0 @String/encode_utf8__C1) (b c))) ~ [=0x0000000] + +@String/encode_utf8__C3 = (* ({$([&0x000003F] c) $([:>>0x0000006] a)} (e h))) + & @List/Cons ~ (b (g h)) + & $(a b) ~ [|0x00000C0] + & @List/Cons ~ (d (f g)) + & $(c d) ~ [|0x0000080] + & @String/encode_utf8 ~ (e f) + +@String/encode_utf8__C4 = ({$([<0x00007FF] a) b} c) + & $(a ?((@String/encode_utf8__C2 @String/encode_utf8__C3) (b c))) ~ [=0x0000000] + +@String/encode_utf8__C5 = (* (a (b d))) + & @List/Cons ~ (a (c d)) + & @String/encode_utf8 ~ (b c) + +@String/encode_utf8__C6 = (* ({$([<0x000007F] a) b} c)) + & $(a ?((@String/encode_utf8__C4 @String/encode_utf8__C5) (b c))) ~ [=0x0000000] + +@String/encode_utf8__C7 = (?((@List/Nil @String/encode_utf8__C6) a) a) + +@True = 1 + +@call = (a (b c)) + & @IO/Call ~ (@IO/MAGIC (a (b (@call__C0 c)))) + +@call__C0 = a + & @IO/Done ~ (@IO/MAGIC a) + +@main = xc + & @IO/bind ~ (b ((((tc (* vc)) (@IO/wrap wc)) wc) xc)) + & @IO/FS/mkdir ~ (a b) + & @String/Cons ~ (65 (@String/Nil a)) + & @IO/bind ~ (g ((((qc (* sc)) (tc uc)) uc) vc)) + & @IO/FS/mkdir ~ (f g) + & @String/Cons ~ (65 (e f)) + & @String/Cons ~ (47 (d e)) + & @String/Cons ~ (65 (c d)) + & @String/Cons ~ (65 (@String/Nil c)) + & @IO/bind ~ (l ((((nc (* pc)) (qc rc)) rc) sc)) + & @IO/FS/mkdir ~ (k l) + & @String/Cons ~ (65 (j k)) + & @String/Cons ~ (47 (i j)) + & @String/Cons ~ (65 (h i)) + & @String/Cons ~ (66 (@String/Nil h)) + & @IO/bind ~ (v ((((kc (* mc)) (nc oc)) oc) pc)) + & @IO/FS/write_file ~ (s (u v)) + & @String/Cons ~ (65 (r s)) + & @String/Cons ~ (47 (q r)) + & @String/Cons ~ (97 (p q)) + & @String/Cons ~ (46 (o p)) + & @String/Cons ~ (116 (n o)) + & @String/Cons ~ (120 (m n)) + & @String/Cons ~ (116 (@String/Nil m)) + & @String/encode_utf8 ~ (t u) + & @String/Cons ~ (97 (@String/Nil t)) + & @IO/bind ~ (kb ((((hc (* jc)) (kc lc)) lc) mc)) + & @IO/FS/write_file ~ (gb (jb kb)) + & @String/Cons ~ (65 (fb gb)) + & @String/Cons ~ (47 (eb fb)) + & @String/Cons ~ (65 (db eb)) + & @String/Cons ~ (65 (cb db)) + & @String/Cons ~ (47 (bb cb)) + & @String/Cons ~ (97 (ab bb)) + & @String/Cons ~ (97 (z ab)) + & @String/Cons ~ (46 (y z)) + & @String/Cons ~ (116 (x y)) + & @String/Cons ~ (120 (w x)) + & @String/Cons ~ (116 (@String/Nil w)) + & @String/encode_utf8 ~ (ib jb) + & @String/Cons ~ (97 (hb ib)) + & @String/Cons ~ (97 (@String/Nil hb)) + & @IO/bind ~ (zb ((((ec (* gc)) (hc ic)) ic) jc)) + & @IO/FS/write_file ~ (vb (yb zb)) + & @String/Cons ~ (65 (ub vb)) + & @String/Cons ~ (47 (tb ub)) + & @String/Cons ~ (65 (sb tb)) + & @String/Cons ~ (66 (rb sb)) + & @String/Cons ~ (47 (qb rb)) + & @String/Cons ~ (97 (pb qb)) + & @String/Cons ~ (98 (ob pb)) + & @String/Cons ~ (46 (nb ob)) + & @String/Cons ~ (116 (mb nb)) + & @String/Cons ~ (120 (lb mb)) + & @String/Cons ~ (116 (@String/Nil lb)) + & @String/encode_utf8 ~ (xb yb) + & @String/Cons ~ (97 (wb xb)) + & @String/Cons ~ (98 (@String/Nil wb)) + & @IO/bind ~ (bc ((((cc cc) (ec fc)) fc) gc)) + & @IO/FS/delete_directory ~ (ac (@True bc)) + & @String/Cons ~ (65 (@String/Nil ac)) + +@test-io = 1 + +@undefer = (((a a) b) b) + + diff --git a/tests/programs/io/delete_empty_dir.bend b/tests/programs/io/delete_empty_dir.bend new file mode 100644 index 00000000..9e50d2d1 --- /dev/null +++ b/tests/programs/io/delete_empty_dir.bend @@ -0,0 +1,18 @@ +#{ + Uses the delete_file function to delete an empty directory. +#} + +test-io = 1 + +IO/FS/mkdir path = + (call "MKDIR" path) + +IO/FS/delete_file path = + (call "DELETE_FILE" path) + +main = + with IO { + ask * = (IO/FS/mkdir "temp") + ask s = (IO/FS/delete_file "temp") + (wrap s) + } diff --git a/tests/programs/io/delete_empty_dir.hvm b/tests/programs/io/delete_empty_dir.hvm new file mode 100644 index 00000000..587c20a3 --- /dev/null +++ b/tests/programs/io/delete_empty_dir.hvm @@ -0,0 +1,79 @@ +@IO/Call = (a (b (c (d ((@IO/Call/tag (a (b (c (d e))))) e))))) + +@IO/Call/tag = 1 + +@IO/Done = (a (b ((@IO/Done/tag (a (b c))) c))) + +@IO/Done/tag = 0 + +@IO/FS/delete_file = l + & @call ~ (k l) + & @String/Cons ~ (68 (j k)) + & @String/Cons ~ (69 (i j)) + & @String/Cons ~ (76 (h i)) + & @String/Cons ~ (69 (g h)) + & @String/Cons ~ (84 (f g)) + & @String/Cons ~ (69 (e f)) + & @String/Cons ~ (95 (d e)) + & @String/Cons ~ (70 (c d)) + & @String/Cons ~ (73 (b c)) + & @String/Cons ~ (76 (a b)) + & @String/Cons ~ (69 (@String/Nil a)) + +@IO/FS/mkdir = f + & @call ~ (e f) + & @String/Cons ~ (77 (d e)) + & @String/Cons ~ (75 (c d)) + & @String/Cons ~ (68 (b c)) + & @String/Cons ~ (73 (a b)) + & @String/Cons ~ (82 (@String/Nil a)) + +@IO/MAGIC = (13683217 16719857) + +@IO/bind = ((@IO/bind__C2 a) a) + +@IO/bind__C0 = (* (b (a c))) + & @undefer ~ (a (b c)) + +@IO/bind__C1 = (* (* (a (b ((c d) (e g)))))) + & @IO/Call ~ (@IO/MAGIC (a (b ((c f) g)))) + & @IO/bind ~ (d (e f)) + +@IO/bind__C2 = (?((@IO/bind__C0 @IO/bind__C1) a) a) + +@IO/wrap = a + & @IO/Done ~ (@IO/MAGIC a) + +@String/Cons = (a (b ((@String/Cons/tag (a (b c))) c))) + +@String/Cons/tag = 1 + +@String/Nil = ((@String/Nil/tag a) a) + +@String/Nil/tag = 0 + +@call = (a (b c)) + & @IO/Call ~ (@IO/MAGIC (a (b (@call__C0 c)))) + +@call__C0 = a + & @IO/Done ~ (@IO/MAGIC a) + +@main = q + & @IO/bind ~ (e ((((m (* o)) (@IO/wrap p)) p) q)) + & @IO/FS/mkdir ~ (d e) + & @String/Cons ~ (116 (c d)) + & @String/Cons ~ (101 (b c)) + & @String/Cons ~ (109 (a b)) + & @String/Cons ~ (112 (@String/Nil a)) + & @IO/bind ~ (j ((((k k) (m n)) n) o)) + & @IO/FS/delete_file ~ (i j) + & @String/Cons ~ (116 (h i)) + & @String/Cons ~ (101 (g h)) + & @String/Cons ~ (109 (f g)) + & @String/Cons ~ (112 (@String/Nil f)) + +@test-io = 1 + +@undefer = (((a a) b) b) + + diff --git a/tests/programs/io/delete_file.bend b/tests/programs/io/delete_file.bend new file mode 100644 index 00000000..6f47ed29 --- /dev/null +++ b/tests/programs/io/delete_file.bend @@ -0,0 +1,16 @@ +#{ + Creates a temporary file and then deletes it. +#} + +test-io = 1 + +IO/FS/delete_file path = + (call "DELETE_FILE" path) + +main = + let path = "./temp.txt" + with IO { + ask * = (IO/FS/write_file path (String/encode_utf8 "Contents")) + ask s = (IO/FS/delete_file path) + (wrap s) + } diff --git a/tests/programs/io/delete_file.hvm b/tests/programs/io/delete_file.hvm new file mode 100644 index 00000000..d14615aa --- /dev/null +++ b/tests/programs/io/delete_file.hvm @@ -0,0 +1,208 @@ +@IO/Call = (a (b (c (d ((@IO/Call/tag (a (b (c (d e))))) e))))) + +@IO/Call/tag = 1 + +@IO/Done = (a (b ((@IO/Done/tag (a (b c))) c))) + +@IO/Done/tag = 0 + +@IO/FS/close = (f g) + & @IO/Call ~ (@IO/MAGIC (e (f (@IO/wrap g)))) + & @String/Cons ~ (67 (d e)) + & @String/Cons ~ (76 (c d)) + & @String/Cons ~ (79 (b c)) + & @String/Cons ~ (83 (a b)) + & @String/Cons ~ (69 (@String/Nil a)) + +@IO/FS/delete_file = l + & @call ~ (k l) + & @String/Cons ~ (68 (j k)) + & @String/Cons ~ (69 (i j)) + & @String/Cons ~ (76 (h i)) + & @String/Cons ~ (69 (g h)) + & @String/Cons ~ (84 (f g)) + & @String/Cons ~ (69 (e f)) + & @String/Cons ~ (95 (d e)) + & @String/Cons ~ (70 (c d)) + & @String/Cons ~ (73 (b c)) + & @String/Cons ~ (76 (a b)) + & @String/Cons ~ (69 (@String/Nil a)) + +@IO/FS/open = (e (f g)) + & @IO/Call ~ (@IO/MAGIC (d ((e f) (@IO/wrap g)))) + & @String/Cons ~ (79 (c d)) + & @String/Cons ~ (80 (b c)) + & @String/Cons ~ (69 (a b)) + & @String/Cons ~ (78 (@String/Nil a)) + +@IO/FS/write = (f (g h)) + & @IO/Call ~ (@IO/MAGIC (e ((f g) (@IO/wrap h)))) + & @String/Cons ~ (87 (d e)) + & @String/Cons ~ (82 (c d)) + & @String/Cons ~ (73 (b c)) + & @String/Cons ~ (84 (a b)) + & @String/Cons ~ (69 (@String/Nil a)) + +@IO/FS/write_file = (a (d f)) + & @IO/bind ~ (c (((@IO/FS/write_file__C5 (d (@IO/wrap e))) e) f)) + & @IO/FS/open ~ (a (b c)) + & @String/Cons ~ (119 (@String/Nil b)) + +@IO/FS/write_file__C0 = ((b c) (a (* c))) + & @Result/Ok ~ (a b) + +@IO/FS/write_file__C1 = (a (d (e (* g)))) + & @IO/bind ~ (c (((@IO/FS/write_file__C0 (d (e f))) f) g)) + & @IO/done_on_err ~ (b c) + & @IO/FS/close ~ (a b) + +@IO/FS/write_file__C2 = ({a e} ({b g} (f i))) + & @IO/bind ~ (d (((@IO/FS/write_file__C1 (e (f (g h)))) h) i)) + & @IO/done_on_err ~ (c d) + & @IO/FS/write ~ (a (b c)) + +@IO/FS/write_file__C3 = (* (a (* ((b c) c)))) + & @Result/Err ~ (a b) + +@IO/FS/write_file__C4 = (?((@IO/FS/write_file__C2 @IO/FS/write_file__C3) a) a) + +@IO/FS/write_file__C5 = (a (b ((@IO/FS/write_file__C4 (a (b c))) c))) + +@IO/MAGIC = (13683217 16719857) + +@IO/bind = ((@IO/bind__C2 a) a) + +@IO/bind__C0 = (* (b (a c))) + & @undefer ~ (a (b c)) + +@IO/bind__C1 = (* (* (a (b ((c d) (e g)))))) + & @IO/Call ~ (@IO/MAGIC (a (b ((c f) g)))) + & @IO/bind ~ (d (e f)) + +@IO/bind__C2 = (?((@IO/bind__C0 @IO/bind__C1) a) a) + +@IO/done_on_err = ((@IO/done_on_err__C5 a) a) + +@IO/done_on_err__C0 = (a ((a b) b)) + +@IO/done_on_err__C1 = (* (a (* c))) + & @IO/Done ~ (@IO/MAGIC (b c)) + & @Result/Err ~ (a b) + +@IO/done_on_err__C2 = (?((@IO/done_on_err__C0 @IO/done_on_err__C1) a) a) + +@IO/done_on_err__C3 = a + & @IO/Done ~ a + +@IO/done_on_err__C4 = (* (a (b (c (d f))))) + & @IO/Call ~ (a (b (c (((@IO/done_on_err__C2 (d e)) e) f)))) + +@IO/done_on_err__C5 = (?((@IO/done_on_err__C3 @IO/done_on_err__C4) a) a) + +@IO/wrap = a + & @IO/Done ~ (@IO/MAGIC a) + +@List/Cons = (a (b ((@List/Cons/tag (a (b c))) c))) + +@List/Cons/tag = 1 + +@List/Nil = ((@List/Nil/tag a) a) + +@List/Nil/tag = 0 + +@Result/Err = (a ((@Result/Err/tag (a b)) b)) + +@Result/Err/tag = 1 + +@Result/Ok = (a ((@Result/Ok/tag (a b)) b)) + +@Result/Ok/tag = 0 + +@String/Cons = (a (b ((@String/Cons/tag (a (b c))) c))) + +@String/Cons/tag = 1 + +@String/Nil = ((@String/Nil/tag a) a) + +@String/Nil/tag = 0 + +@String/encode_utf8 = ((@String/encode_utf8__C7 a) a) + +@String/encode_utf8__C0 = ({$([&0x000003F] g) {$([:>>0x0000006] $([&0x000003F] e)) {$([:>>0x000000C] $([&0x000003F] c)) $([:>>0x0000012] a)}}} (i n)) + & @List/Cons ~ (b (m n)) + & $(a b) ~ [|0x00000F0] + & @List/Cons ~ (d (l m)) + & $(c d) ~ [|0x0000080] + & @List/Cons ~ (f (k l)) + & $(e f) ~ [|0x0000080] + & @List/Cons ~ (h (j k)) + & $(g h) ~ [|0x0000080] + & @String/encode_utf8 ~ (i j) + +@String/encode_utf8__C1 = (* ({$([&0x000003F] e) {$([:>>0x0000006] $([&0x000003F] c)) $([:>>0x000000C] a)}} (g k))) + & @List/Cons ~ (b (j k)) + & $(a b) ~ [|0x00000E0] + & @List/Cons ~ (d (i j)) + & $(c d) ~ [|0x0000080] + & @List/Cons ~ (f (h i)) + & $(e f) ~ [|0x0000080] + & @String/encode_utf8 ~ (g h) + +@String/encode_utf8__C2 = ({$([<0x000FFFF] a) b} c) + & $(a ?((@String/encode_utf8__C0 @String/encode_utf8__C1) (b c))) ~ [=0x0000000] + +@String/encode_utf8__C3 = (* ({$([&0x000003F] c) $([:>>0x0000006] a)} (e h))) + & @List/Cons ~ (b (g h)) + & $(a b) ~ [|0x00000C0] + & @List/Cons ~ (d (f g)) + & $(c d) ~ [|0x0000080] + & @String/encode_utf8 ~ (e f) + +@String/encode_utf8__C4 = ({$([<0x00007FF] a) b} c) + & $(a ?((@String/encode_utf8__C2 @String/encode_utf8__C3) (b c))) ~ [=0x0000000] + +@String/encode_utf8__C5 = (* (a (b d))) + & @List/Cons ~ (a (c d)) + & @String/encode_utf8 ~ (b c) + +@String/encode_utf8__C6 = (* ({$([<0x000007F] a) b} c)) + & $(a ?((@String/encode_utf8__C4 @String/encode_utf8__C5) (b c))) ~ [=0x0000000] + +@String/encode_utf8__C7 = (?((@List/Nil @String/encode_utf8__C6) a) a) + +@call = (a (b c)) + & @IO/Call ~ (@IO/MAGIC (a (b (@call__C0 c)))) + +@call__C0 = a + & @IO/Done ~ (@IO/MAGIC a) + +@main = db + & @IO/bind ~ (t ((((u (y (* ab))) (bb (@IO/wrap cb))) cb) db)) + & @String/Cons ~ (46 (i {j bb})) + & @String/Cons ~ (47 (h i)) + & @String/Cons ~ (116 (g h)) + & @String/Cons ~ (101 (f g)) + & @String/Cons ~ (109 (e f)) + & @String/Cons ~ (112 (d e)) + & @String/Cons ~ (46 (c d)) + & @String/Cons ~ (116 (b c)) + & @String/Cons ~ (120 (a b)) + & @String/Cons ~ (116 (@String/Nil a)) + & @IO/FS/write_file ~ (j (s t)) + & @String/encode_utf8 ~ (r s) + & @String/Cons ~ (67 (q r)) + & @String/Cons ~ (111 (p q)) + & @String/Cons ~ (110 (o p)) + & @String/Cons ~ (116 (n o)) + & @String/Cons ~ (101 (m n)) + & @String/Cons ~ (110 (l m)) + & @String/Cons ~ (116 (k l)) + & @String/Cons ~ (115 (@String/Nil k)) + & @IO/bind ~ (v ((((w w) (y z)) z) ab)) + & @IO/FS/delete_file ~ (u v) + +@test-io = 1 + +@undefer = (((a a) b) b) + + diff --git a/tests/programs/io_delete/delete_non_existing_file.bend b/tests/programs/io/delete_non_existing_file.bend similarity index 64% rename from tests/programs/io_delete/delete_non_existing_file.bend rename to tests/programs/io/delete_non_existing_file.bend index b79f34ce..219d5972 100644 --- a/tests/programs/io_delete/delete_non_existing_file.bend +++ b/tests/programs/io/delete_non_existing_file.bend @@ -1,10 +1,14 @@ +#{ + Tries to delete a non existing file. +#} + test-io = 1 IO/FS/delete_file path = (call "DELETE_FILE" path) main = - use path = "./tests/programs/io_remove/files/non_existing.txt" + use path = "./non_existing.txt" with IO { ask s = (IO/FS/delete_file path) (wrap s) diff --git a/tests/programs/io_delete/delete_non_existing_file.hvm b/tests/programs/io/delete_non_existing_file.hvm similarity index 60% rename from tests/programs/io_delete/delete_non_existing_file.hvm rename to tests/programs/io/delete_non_existing_file.hvm index cd749e09..11d6c365 100644 --- a/tests/programs/io_delete/delete_non_existing_file.hvm +++ b/tests/programs/io/delete_non_existing_file.hvm @@ -50,41 +50,10 @@ @call__C0 = a & @IO/Done ~ (@IO/MAGIC a) -@main = bc - & @IO/bind ~ (xb ((((yb yb) (@IO/wrap ac)) ac) bc)) - & @IO/FS/delete_file ~ (wb xb) - & @String/Cons ~ (46 (vb wb)) - & @String/Cons ~ (47 (ub vb)) - & @String/Cons ~ (116 (tb ub)) - & @String/Cons ~ (101 (sb tb)) - & @String/Cons ~ (115 (rb sb)) - & @String/Cons ~ (116 (qb rb)) - & @String/Cons ~ (115 (pb qb)) - & @String/Cons ~ (47 (ob pb)) - & @String/Cons ~ (112 (nb ob)) - & @String/Cons ~ (114 (mb nb)) - & @String/Cons ~ (111 (lb mb)) - & @String/Cons ~ (103 (kb lb)) - & @String/Cons ~ (114 (jb kb)) - & @String/Cons ~ (97 (ib jb)) - & @String/Cons ~ (109 (hb ib)) - & @String/Cons ~ (115 (gb hb)) - & @String/Cons ~ (47 (fb gb)) - & @String/Cons ~ (105 (eb fb)) - & @String/Cons ~ (111 (db eb)) - & @String/Cons ~ (95 (cb db)) - & @String/Cons ~ (114 (bb cb)) - & @String/Cons ~ (101 (ab bb)) - & @String/Cons ~ (109 (z ab)) - & @String/Cons ~ (111 (y z)) - & @String/Cons ~ (118 (x y)) - & @String/Cons ~ (101 (w x)) - & @String/Cons ~ (47 (v w)) - & @String/Cons ~ (102 (u v)) - & @String/Cons ~ (105 (t u)) - & @String/Cons ~ (108 (s t)) - & @String/Cons ~ (101 (r s)) - & @String/Cons ~ (115 (q r)) +@main = w + & @IO/bind ~ (s ((((t t) (@IO/wrap v)) v) w)) + & @IO/FS/delete_file ~ (r s) + & @String/Cons ~ (46 (q r)) & @String/Cons ~ (47 (p q)) & @String/Cons ~ (110 (o p)) & @String/Cons ~ (111 (n o)) diff --git a/tests/programs/io_delete/delete_file.bend b/tests/programs/io_delete/delete_file.bend deleted file mode 100644 index 2d36b517..00000000 --- a/tests/programs/io_delete/delete_file.bend +++ /dev/null @@ -1,11 +0,0 @@ -test-io = 1 - -IO/FS/delete_file path = - (call "DELETE_FILE" path) - -main = - use path = "./tests/programs/io_remove/files/remove_file.txt" - with IO { - ask s = (IO/FS/delete_file path) - (wrap s) - } diff --git a/tests/programs/io_delete/delete_file.hvm b/tests/programs/io_delete/delete_file.hvm deleted file mode 100644 index 64d3ba7c..00000000 --- a/tests/programs/io_delete/delete_file.hvm +++ /dev/null @@ -1,109 +0,0 @@ -@IO/Call = (a (b (c (d ((@IO/Call/tag (a (b (c (d e))))) e))))) - -@IO/Call/tag = 1 - -@IO/Done = (a (b ((@IO/Done/tag (a (b c))) c))) - -@IO/Done/tag = 0 - -@IO/FS/delete_file = l - & @call ~ (k l) - & @String/Cons ~ (68 (j k)) - & @String/Cons ~ (69 (i j)) - & @String/Cons ~ (76 (h i)) - & @String/Cons ~ (69 (g h)) - & @String/Cons ~ (84 (f g)) - & @String/Cons ~ (69 (e f)) - & @String/Cons ~ (95 (d e)) - & @String/Cons ~ (70 (c d)) - & @String/Cons ~ (73 (b c)) - & @String/Cons ~ (76 (a b)) - & @String/Cons ~ (69 (@String/Nil a)) - -@IO/MAGIC = (13683217 16719857) - -@IO/bind = ((@IO/bind__C2 a) a) - -@IO/bind__C0 = (* (b (a c))) - & @undefer ~ (a (b c)) - -@IO/bind__C1 = (* (* (a (b ((c d) (e g)))))) - & @IO/Call ~ (@IO/MAGIC (a (b ((c f) g)))) - & @IO/bind ~ (d (e f)) - -@IO/bind__C2 = (?((@IO/bind__C0 @IO/bind__C1) a) a) - -@IO/wrap = a - & @IO/Done ~ (@IO/MAGIC a) - -@String/Cons = (a (b ((@String/Cons/tag (a (b c))) c))) - -@String/Cons/tag = 1 - -@String/Nil = ((@String/Nil/tag a) a) - -@String/Nil/tag = 0 - -@call = (a (b c)) - & @IO/Call ~ (@IO/MAGIC (a (b (@call__C0 c)))) - -@call__C0 = a - & @IO/Done ~ (@IO/MAGIC a) - -@main = ac - & @IO/bind ~ (wb ((((xb xb) (@IO/wrap zb)) zb) ac)) - & @IO/FS/delete_file ~ (vb wb) - & @String/Cons ~ (46 (ub vb)) - & @String/Cons ~ (47 (tb ub)) - & @String/Cons ~ (116 (sb tb)) - & @String/Cons ~ (101 (rb sb)) - & @String/Cons ~ (115 (qb rb)) - & @String/Cons ~ (116 (pb qb)) - & @String/Cons ~ (115 (ob pb)) - & @String/Cons ~ (47 (nb ob)) - & @String/Cons ~ (112 (mb nb)) - & @String/Cons ~ (114 (lb mb)) - & @String/Cons ~ (111 (kb lb)) - & @String/Cons ~ (103 (jb kb)) - & @String/Cons ~ (114 (ib jb)) - & @String/Cons ~ (97 (hb ib)) - & @String/Cons ~ (109 (gb hb)) - & @String/Cons ~ (115 (fb gb)) - & @String/Cons ~ (47 (eb fb)) - & @String/Cons ~ (105 (db eb)) - & @String/Cons ~ (111 (cb db)) - & @String/Cons ~ (95 (bb cb)) - & @String/Cons ~ (114 (ab bb)) - & @String/Cons ~ (101 (z ab)) - & @String/Cons ~ (109 (y z)) - & @String/Cons ~ (111 (x y)) - & @String/Cons ~ (118 (w x)) - & @String/Cons ~ (101 (v w)) - & @String/Cons ~ (47 (u v)) - & @String/Cons ~ (102 (t u)) - & @String/Cons ~ (105 (s t)) - & @String/Cons ~ (108 (r s)) - & @String/Cons ~ (101 (q r)) - & @String/Cons ~ (115 (p q)) - & @String/Cons ~ (47 (o p)) - & @String/Cons ~ (114 (n o)) - & @String/Cons ~ (101 (m n)) - & @String/Cons ~ (109 (l m)) - & @String/Cons ~ (111 (k l)) - & @String/Cons ~ (118 (j k)) - & @String/Cons ~ (101 (i j)) - & @String/Cons ~ (95 (h i)) - & @String/Cons ~ (102 (g h)) - & @String/Cons ~ (105 (f g)) - & @String/Cons ~ (108 (e f)) - & @String/Cons ~ (101 (d e)) - & @String/Cons ~ (46 (c d)) - & @String/Cons ~ (116 (b c)) - & @String/Cons ~ (120 (a b)) - & @String/Cons ~ (116 (@String/Nil a)) - -@test-io = 1 - -@undefer = (((a a) b) b) - - From 6a6391a9bf3f3c93e1379302e6ae288bd8acbf62 Mon Sep 17 00:00:00 2001 From: imaqtkatt Date: Thu, 22 Aug 2024 14:28:20 -0300 Subject: [PATCH 03/10] update test snapshots --- tests/snapshots/run__io_file@io__create_directory.hvm.snap | 6 ++++++ tests/snapshots/run__io_file@io__delete_dir_file.hvm.snap | 6 ++++++ .../run__io_file@io__delete_dir_recursive.hvm.snap | 6 ++++++ tests/snapshots/run__io_file@io__delete_empty_dir.hvm.snap | 6 ++++++ tests/snapshots/run__io_file@io__delete_file.hvm.snap | 6 ++++++ .../run__io_file@io__delete_non_existing_file.hvm.snap | 6 ++++++ 6 files changed, 36 insertions(+) create mode 100644 tests/snapshots/run__io_file@io__create_directory.hvm.snap create mode 100644 tests/snapshots/run__io_file@io__delete_dir_file.hvm.snap create mode 100644 tests/snapshots/run__io_file@io__delete_dir_recursive.hvm.snap create mode 100644 tests/snapshots/run__io_file@io__delete_empty_dir.hvm.snap create mode 100644 tests/snapshots/run__io_file@io__delete_file.hvm.snap create mode 100644 tests/snapshots/run__io_file@io__delete_non_existing_file.hvm.snap diff --git a/tests/snapshots/run__io_file@io__create_directory.hvm.snap b/tests/snapshots/run__io_file@io__create_directory.hvm.snap new file mode 100644 index 00000000..e15e0457 --- /dev/null +++ b/tests/snapshots/run__io_file@io__create_directory.hvm.snap @@ -0,0 +1,6 @@ +--- +source: tests/run.rs +expression: c_output +input_file: tests/programs/io/create_directory.hvm +--- +Result: ((@IO/Done/tag (@IO/MAGIC (((0 (* x0)) x0) x1))) x1) diff --git a/tests/snapshots/run__io_file@io__delete_dir_file.hvm.snap b/tests/snapshots/run__io_file@io__delete_dir_file.hvm.snap new file mode 100644 index 00000000..6435af8a --- /dev/null +++ b/tests/snapshots/run__io_file@io__delete_dir_file.hvm.snap @@ -0,0 +1,6 @@ +--- +source: tests/run.rs +expression: c_output +input_file: tests/programs/io/delete_dir_file.hvm +--- +Result: ((@IO/Done/tag (@IO/MAGIC (((1 (((2 (+2 x0)) x0) x1)) x1) x2))) x2) diff --git a/tests/snapshots/run__io_file@io__delete_dir_recursive.hvm.snap b/tests/snapshots/run__io_file@io__delete_dir_recursive.hvm.snap new file mode 100644 index 00000000..abd18921 --- /dev/null +++ b/tests/snapshots/run__io_file@io__delete_dir_recursive.hvm.snap @@ -0,0 +1,6 @@ +--- +source: tests/run.rs +expression: c_output +input_file: tests/programs/io/delete_dir_recursive.hvm +--- +Result: ((@IO/Done/tag (@IO/MAGIC (((0 (* x0)) x0) x1))) x1) diff --git a/tests/snapshots/run__io_file@io__delete_empty_dir.hvm.snap b/tests/snapshots/run__io_file@io__delete_empty_dir.hvm.snap new file mode 100644 index 00000000..97e8e204 --- /dev/null +++ b/tests/snapshots/run__io_file@io__delete_empty_dir.hvm.snap @@ -0,0 +1,6 @@ +--- +source: tests/run.rs +expression: c_output +input_file: tests/programs/io/delete_empty_dir.hvm +--- +Result: ((@IO/Done/tag (@IO/MAGIC (((0 (* x0)) x0) x1))) x1) diff --git a/tests/snapshots/run__io_file@io__delete_file.hvm.snap b/tests/snapshots/run__io_file@io__delete_file.hvm.snap new file mode 100644 index 00000000..4af58b20 --- /dev/null +++ b/tests/snapshots/run__io_file@io__delete_file.hvm.snap @@ -0,0 +1,6 @@ +--- +source: tests/run.rs +expression: c_output +input_file: tests/programs/io/delete_file.hvm +--- +Result: ((@IO/Done/tag (@IO/MAGIC (((0 (* x0)) x0) x1))) x1) diff --git a/tests/snapshots/run__io_file@io__delete_non_existing_file.hvm.snap b/tests/snapshots/run__io_file@io__delete_non_existing_file.hvm.snap new file mode 100644 index 00000000..f26692d1 --- /dev/null +++ b/tests/snapshots/run__io_file@io__delete_non_existing_file.hvm.snap @@ -0,0 +1,6 @@ +--- +source: tests/run.rs +expression: c_output +input_file: tests/programs/io/delete_non_existing_file.hvm +--- +Result: ((@IO/Done/tag (@IO/MAGIC (((1 (((2 (+2 x0)) x0) x1)) x1) x2))) x2) From 7387ec321f4e4cdf55401bc6b6a7ac2a3130e44d Mon Sep 17 00:00:00 2001 From: imaqtkatt Date: Thu, 22 Aug 2024 16:28:14 -0300 Subject: [PATCH 04/10] add comment to io_mkdir and remove added tests --- src/run.c | 6 +- tests/programs/io/create_directory.hvm | 86 ------ tests/programs/io/delete_dir_file.hvm | 90 ------ tests/programs/io/delete_dir_recursive.hvm | 261 ------------------ tests/programs/io/delete_empty_dir.hvm | 79 ------ tests/programs/io/delete_file.hvm | 208 -------------- .../programs/io/delete_non_existing_file.hvm | 79 ------ ...run__io_file@io__create_directory.hvm.snap | 6 - .../run__io_file@io__delete_dir_file.hvm.snap | 6 - ..._io_file@io__delete_dir_recursive.hvm.snap | 6 - ...run__io_file@io__delete_empty_dir.hvm.snap | 6 - .../run__io_file@io__delete_file.hvm.snap | 6 - ...file@io__delete_non_existing_file.hvm.snap | 6 - 13 files changed, 4 insertions(+), 841 deletions(-) delete mode 100644 tests/programs/io/create_directory.hvm delete mode 100644 tests/programs/io/delete_dir_file.hvm delete mode 100644 tests/programs/io/delete_dir_recursive.hvm delete mode 100644 tests/programs/io/delete_empty_dir.hvm delete mode 100644 tests/programs/io/delete_file.hvm delete mode 100644 tests/programs/io/delete_non_existing_file.hvm delete mode 100644 tests/snapshots/run__io_file@io__create_directory.hvm.snap delete mode 100644 tests/snapshots/run__io_file@io__delete_dir_file.hvm.snap delete mode 100644 tests/snapshots/run__io_file@io__delete_dir_recursive.hvm.snap delete mode 100644 tests/snapshots/run__io_file@io__delete_empty_dir.hvm.snap delete mode 100644 tests/snapshots/run__io_file@io__delete_file.hvm.snap delete mode 100644 tests/snapshots/run__io_file@io__delete_non_existing_file.hvm.snap diff --git a/src/run.c b/src/run.c index 09352d00..623c8997 100644 --- a/src/run.c +++ b/src/run.c @@ -804,11 +804,10 @@ Port io_delete_directory(Net* net, Book* book, Port argm) { int res; if (rec) { res = delete_directory_recursive(path.buf); - free(path.buf); } else { res = rmdir(path.buf); - free(path.buf); } + free(path.buf); if (0 == res) { return inject_ok(net, new_port(ERA, 0)); @@ -817,6 +816,9 @@ Port io_delete_directory(Net* net, Book* book, Port argm) { } } +// Creates a new directory with the given path. +// Returns Ok(None) if sucessfull, or Err(reason) if an error occurs. +// Returns: Result<*, IOError> Port io_mkdir(Net* net, Book* book, Port argm) { Str name = readback_str(net, book, argm); diff --git a/tests/programs/io/create_directory.hvm b/tests/programs/io/create_directory.hvm deleted file mode 100644 index a1baab58..00000000 --- a/tests/programs/io/create_directory.hvm +++ /dev/null @@ -1,86 +0,0 @@ -@False = 0 - -@IO/Call = (a (b (c (d ((@IO/Call/tag (a (b (c (d e))))) e))))) - -@IO/Call/tag = 1 - -@IO/Done = (a (b ((@IO/Done/tag (a (b c))) c))) - -@IO/Done/tag = 0 - -@IO/FS/delete_directory = (q (r s)) - & @call ~ (p ((q r) s)) - & @String/Cons ~ (68 (o p)) - & @String/Cons ~ (69 (n o)) - & @String/Cons ~ (76 (m n)) - & @String/Cons ~ (69 (l m)) - & @String/Cons ~ (84 (k l)) - & @String/Cons ~ (69 (j k)) - & @String/Cons ~ (95 (i j)) - & @String/Cons ~ (68 (h i)) - & @String/Cons ~ (73 (g h)) - & @String/Cons ~ (82 (f g)) - & @String/Cons ~ (69 (e f)) - & @String/Cons ~ (67 (d e)) - & @String/Cons ~ (84 (c d)) - & @String/Cons ~ (79 (b c)) - & @String/Cons ~ (82 (a b)) - & @String/Cons ~ (89 (@String/Nil a)) - -@IO/FS/mkdir = f - & @call ~ (e f) - & @String/Cons ~ (77 (d e)) - & @String/Cons ~ (75 (c d)) - & @String/Cons ~ (68 (b c)) - & @String/Cons ~ (73 (a b)) - & @String/Cons ~ (82 (@String/Nil a)) - -@IO/MAGIC = (13683217 16719857) - -@IO/bind = ((@IO/bind__C2 a) a) - -@IO/bind__C0 = (* (b (a c))) - & @undefer ~ (a (b c)) - -@IO/bind__C1 = (* (* (a (b ((c d) (e g)))))) - & @IO/Call ~ (@IO/MAGIC (a (b ((c f) g)))) - & @IO/bind ~ (d (e f)) - -@IO/bind__C2 = (?((@IO/bind__C0 @IO/bind__C1) a) a) - -@IO/wrap = a - & @IO/Done ~ (@IO/MAGIC a) - -@String/Cons = (a (b ((@String/Cons/tag (a (b c))) c))) - -@String/Cons/tag = 1 - -@String/Nil = ((@String/Nil/tag a) a) - -@String/Nil/tag = 0 - -@call = (a (b c)) - & @IO/Call ~ (@IO/MAGIC (a (b (@call__C0 c)))) - -@call__C0 = a - & @IO/Done ~ (@IO/MAGIC a) - -@main = s - & @IO/bind ~ (i ((((j (n (* p))) (q (@IO/wrap r))) r) s)) - & @String/Cons ~ (46 (g {h q})) - & @String/Cons ~ (47 (f g)) - & @String/Cons ~ (98 (e f)) - & @String/Cons ~ (97 (d e)) - & @String/Cons ~ (116 (c d)) - & @String/Cons ~ (97 (b c)) - & @String/Cons ~ (116 (a b)) - & @String/Cons ~ (97 (@String/Nil a)) - & @IO/FS/mkdir ~ (h i) - & @IO/bind ~ (k ((((l l) (n o)) o) p)) - & @IO/FS/delete_directory ~ (j (@False k)) - -@test-io = 1 - -@undefer = (((a a) b) b) - - diff --git a/tests/programs/io/delete_dir_file.hvm b/tests/programs/io/delete_dir_file.hvm deleted file mode 100644 index 887f18d8..00000000 --- a/tests/programs/io/delete_dir_file.hvm +++ /dev/null @@ -1,90 +0,0 @@ -@False = 0 - -@IO/Call = (a (b (c (d ((@IO/Call/tag (a (b (c (d e))))) e))))) - -@IO/Call/tag = 1 - -@IO/Done = (a (b ((@IO/Done/tag (a (b c))) c))) - -@IO/Done/tag = 0 - -@IO/FS/delete_directory = (q (r s)) - & @call ~ (p ((q r) s)) - & @String/Cons ~ (68 (o p)) - & @String/Cons ~ (69 (n o)) - & @String/Cons ~ (76 (m n)) - & @String/Cons ~ (69 (l m)) - & @String/Cons ~ (84 (k l)) - & @String/Cons ~ (69 (j k)) - & @String/Cons ~ (95 (i j)) - & @String/Cons ~ (68 (h i)) - & @String/Cons ~ (73 (g h)) - & @String/Cons ~ (82 (f g)) - & @String/Cons ~ (69 (e f)) - & @String/Cons ~ (67 (d e)) - & @String/Cons ~ (84 (c d)) - & @String/Cons ~ (79 (b c)) - & @String/Cons ~ (82 (a b)) - & @String/Cons ~ (89 (@String/Nil a)) - -@IO/MAGIC = (13683217 16719857) - -@IO/bind = ((@IO/bind__C2 a) a) - -@IO/bind__C0 = (* (b (a c))) - & @undefer ~ (a (b c)) - -@IO/bind__C1 = (* (* (a (b ((c d) (e g)))))) - & @IO/Call ~ (@IO/MAGIC (a (b ((c f) g)))) - & @IO/bind ~ (d (e f)) - -@IO/bind__C2 = (?((@IO/bind__C0 @IO/bind__C1) a) a) - -@IO/wrap = a - & @IO/Done ~ (@IO/MAGIC a) - -@String/Cons = (a (b ((@String/Cons/tag (a (b c))) c))) - -@String/Cons/tag = 1 - -@String/Nil = ((@String/Nil/tag a) a) - -@String/Nil/tag = 0 - -@call = (a (b c)) - & @IO/Call ~ (@IO/MAGIC (a (b (@call__C0 c)))) - -@call__C0 = a - & @IO/Done ~ (@IO/MAGIC a) - -@main = ab - & @IO/bind ~ (w ((((x x) (@IO/wrap z)) z) ab)) - & @IO/FS/delete_directory ~ (v (@False w)) - & @String/Cons ~ (46 (u v)) - & @String/Cons ~ (47 (t u)) - & @String/Cons ~ (100 (s t)) - & @String/Cons ~ (101 (r s)) - & @String/Cons ~ (108 (q r)) - & @String/Cons ~ (101 (p q)) - & @String/Cons ~ (116 (o p)) - & @String/Cons ~ (101 (n o)) - & @String/Cons ~ (95 (m n)) - & @String/Cons ~ (100 (l m)) - & @String/Cons ~ (105 (k l)) - & @String/Cons ~ (114 (j k)) - & @String/Cons ~ (95 (i j)) - & @String/Cons ~ (102 (h i)) - & @String/Cons ~ (105 (g h)) - & @String/Cons ~ (108 (f g)) - & @String/Cons ~ (101 (e f)) - & @String/Cons ~ (46 (d e)) - & @String/Cons ~ (98 (c d)) - & @String/Cons ~ (101 (b c)) - & @String/Cons ~ (110 (a b)) - & @String/Cons ~ (100 (@String/Nil a)) - -@test-io = 1 - -@undefer = (((a a) b) b) - - diff --git a/tests/programs/io/delete_dir_recursive.hvm b/tests/programs/io/delete_dir_recursive.hvm deleted file mode 100644 index a940ae0e..00000000 --- a/tests/programs/io/delete_dir_recursive.hvm +++ /dev/null @@ -1,261 +0,0 @@ -@IO/Call = (a (b (c (d ((@IO/Call/tag (a (b (c (d e))))) e))))) - -@IO/Call/tag = 1 - -@IO/Done = (a (b ((@IO/Done/tag (a (b c))) c))) - -@IO/Done/tag = 0 - -@IO/FS/close = (f g) - & @IO/Call ~ (@IO/MAGIC (e (f (@IO/wrap g)))) - & @String/Cons ~ (67 (d e)) - & @String/Cons ~ (76 (c d)) - & @String/Cons ~ (79 (b c)) - & @String/Cons ~ (83 (a b)) - & @String/Cons ~ (69 (@String/Nil a)) - -@IO/FS/delete_directory = (q (r s)) - & @call ~ (p ((q r) s)) - & @String/Cons ~ (68 (o p)) - & @String/Cons ~ (69 (n o)) - & @String/Cons ~ (76 (m n)) - & @String/Cons ~ (69 (l m)) - & @String/Cons ~ (84 (k l)) - & @String/Cons ~ (69 (j k)) - & @String/Cons ~ (95 (i j)) - & @String/Cons ~ (68 (h i)) - & @String/Cons ~ (73 (g h)) - & @String/Cons ~ (82 (f g)) - & @String/Cons ~ (69 (e f)) - & @String/Cons ~ (67 (d e)) - & @String/Cons ~ (84 (c d)) - & @String/Cons ~ (79 (b c)) - & @String/Cons ~ (82 (a b)) - & @String/Cons ~ (89 (@String/Nil a)) - -@IO/FS/mkdir = f - & @call ~ (e f) - & @String/Cons ~ (77 (d e)) - & @String/Cons ~ (75 (c d)) - & @String/Cons ~ (68 (b c)) - & @String/Cons ~ (73 (a b)) - & @String/Cons ~ (82 (@String/Nil a)) - -@IO/FS/open = (e (f g)) - & @IO/Call ~ (@IO/MAGIC (d ((e f) (@IO/wrap g)))) - & @String/Cons ~ (79 (c d)) - & @String/Cons ~ (80 (b c)) - & @String/Cons ~ (69 (a b)) - & @String/Cons ~ (78 (@String/Nil a)) - -@IO/FS/write = (f (g h)) - & @IO/Call ~ (@IO/MAGIC (e ((f g) (@IO/wrap h)))) - & @String/Cons ~ (87 (d e)) - & @String/Cons ~ (82 (c d)) - & @String/Cons ~ (73 (b c)) - & @String/Cons ~ (84 (a b)) - & @String/Cons ~ (69 (@String/Nil a)) - -@IO/FS/write_file = (a (d f)) - & @IO/bind ~ (c (((@IO/FS/write_file__C5 (d (@IO/wrap e))) e) f)) - & @IO/FS/open ~ (a (b c)) - & @String/Cons ~ (119 (@String/Nil b)) - -@IO/FS/write_file__C0 = ((b c) (a (* c))) - & @Result/Ok ~ (a b) - -@IO/FS/write_file__C1 = (a (d (e (* g)))) - & @IO/bind ~ (c (((@IO/FS/write_file__C0 (d (e f))) f) g)) - & @IO/done_on_err ~ (b c) - & @IO/FS/close ~ (a b) - -@IO/FS/write_file__C2 = ({a e} ({b g} (f i))) - & @IO/bind ~ (d (((@IO/FS/write_file__C1 (e (f (g h)))) h) i)) - & @IO/done_on_err ~ (c d) - & @IO/FS/write ~ (a (b c)) - -@IO/FS/write_file__C3 = (* (a (* ((b c) c)))) - & @Result/Err ~ (a b) - -@IO/FS/write_file__C4 = (?((@IO/FS/write_file__C2 @IO/FS/write_file__C3) a) a) - -@IO/FS/write_file__C5 = (a (b ((@IO/FS/write_file__C4 (a (b c))) c))) - -@IO/MAGIC = (13683217 16719857) - -@IO/bind = ((@IO/bind__C2 a) a) - -@IO/bind__C0 = (* (b (a c))) - & @undefer ~ (a (b c)) - -@IO/bind__C1 = (* (* (a (b ((c d) (e g)))))) - & @IO/Call ~ (@IO/MAGIC (a (b ((c f) g)))) - & @IO/bind ~ (d (e f)) - -@IO/bind__C2 = (?((@IO/bind__C0 @IO/bind__C1) a) a) - -@IO/done_on_err = ((@IO/done_on_err__C5 a) a) - -@IO/done_on_err__C0 = (a ((a b) b)) - -@IO/done_on_err__C1 = (* (a (* c))) - & @IO/Done ~ (@IO/MAGIC (b c)) - & @Result/Err ~ (a b) - -@IO/done_on_err__C2 = (?((@IO/done_on_err__C0 @IO/done_on_err__C1) a) a) - -@IO/done_on_err__C3 = a - & @IO/Done ~ a - -@IO/done_on_err__C4 = (* (a (b (c (d f))))) - & @IO/Call ~ (a (b (c (((@IO/done_on_err__C2 (d e)) e) f)))) - -@IO/done_on_err__C5 = (?((@IO/done_on_err__C3 @IO/done_on_err__C4) a) a) - -@IO/wrap = a - & @IO/Done ~ (@IO/MAGIC a) - -@List/Cons = (a (b ((@List/Cons/tag (a (b c))) c))) - -@List/Cons/tag = 1 - -@List/Nil = ((@List/Nil/tag a) a) - -@List/Nil/tag = 0 - -@Result/Err = (a ((@Result/Err/tag (a b)) b)) - -@Result/Err/tag = 1 - -@Result/Ok = (a ((@Result/Ok/tag (a b)) b)) - -@Result/Ok/tag = 0 - -@String/Cons = (a (b ((@String/Cons/tag (a (b c))) c))) - -@String/Cons/tag = 1 - -@String/Nil = ((@String/Nil/tag a) a) - -@String/Nil/tag = 0 - -@String/encode_utf8 = ((@String/encode_utf8__C7 a) a) - -@String/encode_utf8__C0 = ({$([&0x000003F] g) {$([:>>0x0000006] $([&0x000003F] e)) {$([:>>0x000000C] $([&0x000003F] c)) $([:>>0x0000012] a)}}} (i n)) - & @List/Cons ~ (b (m n)) - & $(a b) ~ [|0x00000F0] - & @List/Cons ~ (d (l m)) - & $(c d) ~ [|0x0000080] - & @List/Cons ~ (f (k l)) - & $(e f) ~ [|0x0000080] - & @List/Cons ~ (h (j k)) - & $(g h) ~ [|0x0000080] - & @String/encode_utf8 ~ (i j) - -@String/encode_utf8__C1 = (* ({$([&0x000003F] e) {$([:>>0x0000006] $([&0x000003F] c)) $([:>>0x000000C] a)}} (g k))) - & @List/Cons ~ (b (j k)) - & $(a b) ~ [|0x00000E0] - & @List/Cons ~ (d (i j)) - & $(c d) ~ [|0x0000080] - & @List/Cons ~ (f (h i)) - & $(e f) ~ [|0x0000080] - & @String/encode_utf8 ~ (g h) - -@String/encode_utf8__C2 = ({$([<0x000FFFF] a) b} c) - & $(a ?((@String/encode_utf8__C0 @String/encode_utf8__C1) (b c))) ~ [=0x0000000] - -@String/encode_utf8__C3 = (* ({$([&0x000003F] c) $([:>>0x0000006] a)} (e h))) - & @List/Cons ~ (b (g h)) - & $(a b) ~ [|0x00000C0] - & @List/Cons ~ (d (f g)) - & $(c d) ~ [|0x0000080] - & @String/encode_utf8 ~ (e f) - -@String/encode_utf8__C4 = ({$([<0x00007FF] a) b} c) - & $(a ?((@String/encode_utf8__C2 @String/encode_utf8__C3) (b c))) ~ [=0x0000000] - -@String/encode_utf8__C5 = (* (a (b d))) - & @List/Cons ~ (a (c d)) - & @String/encode_utf8 ~ (b c) - -@String/encode_utf8__C6 = (* ({$([<0x000007F] a) b} c)) - & $(a ?((@String/encode_utf8__C4 @String/encode_utf8__C5) (b c))) ~ [=0x0000000] - -@String/encode_utf8__C7 = (?((@List/Nil @String/encode_utf8__C6) a) a) - -@True = 1 - -@call = (a (b c)) - & @IO/Call ~ (@IO/MAGIC (a (b (@call__C0 c)))) - -@call__C0 = a - & @IO/Done ~ (@IO/MAGIC a) - -@main = xc - & @IO/bind ~ (b ((((tc (* vc)) (@IO/wrap wc)) wc) xc)) - & @IO/FS/mkdir ~ (a b) - & @String/Cons ~ (65 (@String/Nil a)) - & @IO/bind ~ (g ((((qc (* sc)) (tc uc)) uc) vc)) - & @IO/FS/mkdir ~ (f g) - & @String/Cons ~ (65 (e f)) - & @String/Cons ~ (47 (d e)) - & @String/Cons ~ (65 (c d)) - & @String/Cons ~ (65 (@String/Nil c)) - & @IO/bind ~ (l ((((nc (* pc)) (qc rc)) rc) sc)) - & @IO/FS/mkdir ~ (k l) - & @String/Cons ~ (65 (j k)) - & @String/Cons ~ (47 (i j)) - & @String/Cons ~ (65 (h i)) - & @String/Cons ~ (66 (@String/Nil h)) - & @IO/bind ~ (v ((((kc (* mc)) (nc oc)) oc) pc)) - & @IO/FS/write_file ~ (s (u v)) - & @String/Cons ~ (65 (r s)) - & @String/Cons ~ (47 (q r)) - & @String/Cons ~ (97 (p q)) - & @String/Cons ~ (46 (o p)) - & @String/Cons ~ (116 (n o)) - & @String/Cons ~ (120 (m n)) - & @String/Cons ~ (116 (@String/Nil m)) - & @String/encode_utf8 ~ (t u) - & @String/Cons ~ (97 (@String/Nil t)) - & @IO/bind ~ (kb ((((hc (* jc)) (kc lc)) lc) mc)) - & @IO/FS/write_file ~ (gb (jb kb)) - & @String/Cons ~ (65 (fb gb)) - & @String/Cons ~ (47 (eb fb)) - & @String/Cons ~ (65 (db eb)) - & @String/Cons ~ (65 (cb db)) - & @String/Cons ~ (47 (bb cb)) - & @String/Cons ~ (97 (ab bb)) - & @String/Cons ~ (97 (z ab)) - & @String/Cons ~ (46 (y z)) - & @String/Cons ~ (116 (x y)) - & @String/Cons ~ (120 (w x)) - & @String/Cons ~ (116 (@String/Nil w)) - & @String/encode_utf8 ~ (ib jb) - & @String/Cons ~ (97 (hb ib)) - & @String/Cons ~ (97 (@String/Nil hb)) - & @IO/bind ~ (zb ((((ec (* gc)) (hc ic)) ic) jc)) - & @IO/FS/write_file ~ (vb (yb zb)) - & @String/Cons ~ (65 (ub vb)) - & @String/Cons ~ (47 (tb ub)) - & @String/Cons ~ (65 (sb tb)) - & @String/Cons ~ (66 (rb sb)) - & @String/Cons ~ (47 (qb rb)) - & @String/Cons ~ (97 (pb qb)) - & @String/Cons ~ (98 (ob pb)) - & @String/Cons ~ (46 (nb ob)) - & @String/Cons ~ (116 (mb nb)) - & @String/Cons ~ (120 (lb mb)) - & @String/Cons ~ (116 (@String/Nil lb)) - & @String/encode_utf8 ~ (xb yb) - & @String/Cons ~ (97 (wb xb)) - & @String/Cons ~ (98 (@String/Nil wb)) - & @IO/bind ~ (bc ((((cc cc) (ec fc)) fc) gc)) - & @IO/FS/delete_directory ~ (ac (@True bc)) - & @String/Cons ~ (65 (@String/Nil ac)) - -@test-io = 1 - -@undefer = (((a a) b) b) - - diff --git a/tests/programs/io/delete_empty_dir.hvm b/tests/programs/io/delete_empty_dir.hvm deleted file mode 100644 index 587c20a3..00000000 --- a/tests/programs/io/delete_empty_dir.hvm +++ /dev/null @@ -1,79 +0,0 @@ -@IO/Call = (a (b (c (d ((@IO/Call/tag (a (b (c (d e))))) e))))) - -@IO/Call/tag = 1 - -@IO/Done = (a (b ((@IO/Done/tag (a (b c))) c))) - -@IO/Done/tag = 0 - -@IO/FS/delete_file = l - & @call ~ (k l) - & @String/Cons ~ (68 (j k)) - & @String/Cons ~ (69 (i j)) - & @String/Cons ~ (76 (h i)) - & @String/Cons ~ (69 (g h)) - & @String/Cons ~ (84 (f g)) - & @String/Cons ~ (69 (e f)) - & @String/Cons ~ (95 (d e)) - & @String/Cons ~ (70 (c d)) - & @String/Cons ~ (73 (b c)) - & @String/Cons ~ (76 (a b)) - & @String/Cons ~ (69 (@String/Nil a)) - -@IO/FS/mkdir = f - & @call ~ (e f) - & @String/Cons ~ (77 (d e)) - & @String/Cons ~ (75 (c d)) - & @String/Cons ~ (68 (b c)) - & @String/Cons ~ (73 (a b)) - & @String/Cons ~ (82 (@String/Nil a)) - -@IO/MAGIC = (13683217 16719857) - -@IO/bind = ((@IO/bind__C2 a) a) - -@IO/bind__C0 = (* (b (a c))) - & @undefer ~ (a (b c)) - -@IO/bind__C1 = (* (* (a (b ((c d) (e g)))))) - & @IO/Call ~ (@IO/MAGIC (a (b ((c f) g)))) - & @IO/bind ~ (d (e f)) - -@IO/bind__C2 = (?((@IO/bind__C0 @IO/bind__C1) a) a) - -@IO/wrap = a - & @IO/Done ~ (@IO/MAGIC a) - -@String/Cons = (a (b ((@String/Cons/tag (a (b c))) c))) - -@String/Cons/tag = 1 - -@String/Nil = ((@String/Nil/tag a) a) - -@String/Nil/tag = 0 - -@call = (a (b c)) - & @IO/Call ~ (@IO/MAGIC (a (b (@call__C0 c)))) - -@call__C0 = a - & @IO/Done ~ (@IO/MAGIC a) - -@main = q - & @IO/bind ~ (e ((((m (* o)) (@IO/wrap p)) p) q)) - & @IO/FS/mkdir ~ (d e) - & @String/Cons ~ (116 (c d)) - & @String/Cons ~ (101 (b c)) - & @String/Cons ~ (109 (a b)) - & @String/Cons ~ (112 (@String/Nil a)) - & @IO/bind ~ (j ((((k k) (m n)) n) o)) - & @IO/FS/delete_file ~ (i j) - & @String/Cons ~ (116 (h i)) - & @String/Cons ~ (101 (g h)) - & @String/Cons ~ (109 (f g)) - & @String/Cons ~ (112 (@String/Nil f)) - -@test-io = 1 - -@undefer = (((a a) b) b) - - diff --git a/tests/programs/io/delete_file.hvm b/tests/programs/io/delete_file.hvm deleted file mode 100644 index d14615aa..00000000 --- a/tests/programs/io/delete_file.hvm +++ /dev/null @@ -1,208 +0,0 @@ -@IO/Call = (a (b (c (d ((@IO/Call/tag (a (b (c (d e))))) e))))) - -@IO/Call/tag = 1 - -@IO/Done = (a (b ((@IO/Done/tag (a (b c))) c))) - -@IO/Done/tag = 0 - -@IO/FS/close = (f g) - & @IO/Call ~ (@IO/MAGIC (e (f (@IO/wrap g)))) - & @String/Cons ~ (67 (d e)) - & @String/Cons ~ (76 (c d)) - & @String/Cons ~ (79 (b c)) - & @String/Cons ~ (83 (a b)) - & @String/Cons ~ (69 (@String/Nil a)) - -@IO/FS/delete_file = l - & @call ~ (k l) - & @String/Cons ~ (68 (j k)) - & @String/Cons ~ (69 (i j)) - & @String/Cons ~ (76 (h i)) - & @String/Cons ~ (69 (g h)) - & @String/Cons ~ (84 (f g)) - & @String/Cons ~ (69 (e f)) - & @String/Cons ~ (95 (d e)) - & @String/Cons ~ (70 (c d)) - & @String/Cons ~ (73 (b c)) - & @String/Cons ~ (76 (a b)) - & @String/Cons ~ (69 (@String/Nil a)) - -@IO/FS/open = (e (f g)) - & @IO/Call ~ (@IO/MAGIC (d ((e f) (@IO/wrap g)))) - & @String/Cons ~ (79 (c d)) - & @String/Cons ~ (80 (b c)) - & @String/Cons ~ (69 (a b)) - & @String/Cons ~ (78 (@String/Nil a)) - -@IO/FS/write = (f (g h)) - & @IO/Call ~ (@IO/MAGIC (e ((f g) (@IO/wrap h)))) - & @String/Cons ~ (87 (d e)) - & @String/Cons ~ (82 (c d)) - & @String/Cons ~ (73 (b c)) - & @String/Cons ~ (84 (a b)) - & @String/Cons ~ (69 (@String/Nil a)) - -@IO/FS/write_file = (a (d f)) - & @IO/bind ~ (c (((@IO/FS/write_file__C5 (d (@IO/wrap e))) e) f)) - & @IO/FS/open ~ (a (b c)) - & @String/Cons ~ (119 (@String/Nil b)) - -@IO/FS/write_file__C0 = ((b c) (a (* c))) - & @Result/Ok ~ (a b) - -@IO/FS/write_file__C1 = (a (d (e (* g)))) - & @IO/bind ~ (c (((@IO/FS/write_file__C0 (d (e f))) f) g)) - & @IO/done_on_err ~ (b c) - & @IO/FS/close ~ (a b) - -@IO/FS/write_file__C2 = ({a e} ({b g} (f i))) - & @IO/bind ~ (d (((@IO/FS/write_file__C1 (e (f (g h)))) h) i)) - & @IO/done_on_err ~ (c d) - & @IO/FS/write ~ (a (b c)) - -@IO/FS/write_file__C3 = (* (a (* ((b c) c)))) - & @Result/Err ~ (a b) - -@IO/FS/write_file__C4 = (?((@IO/FS/write_file__C2 @IO/FS/write_file__C3) a) a) - -@IO/FS/write_file__C5 = (a (b ((@IO/FS/write_file__C4 (a (b c))) c))) - -@IO/MAGIC = (13683217 16719857) - -@IO/bind = ((@IO/bind__C2 a) a) - -@IO/bind__C0 = (* (b (a c))) - & @undefer ~ (a (b c)) - -@IO/bind__C1 = (* (* (a (b ((c d) (e g)))))) - & @IO/Call ~ (@IO/MAGIC (a (b ((c f) g)))) - & @IO/bind ~ (d (e f)) - -@IO/bind__C2 = (?((@IO/bind__C0 @IO/bind__C1) a) a) - -@IO/done_on_err = ((@IO/done_on_err__C5 a) a) - -@IO/done_on_err__C0 = (a ((a b) b)) - -@IO/done_on_err__C1 = (* (a (* c))) - & @IO/Done ~ (@IO/MAGIC (b c)) - & @Result/Err ~ (a b) - -@IO/done_on_err__C2 = (?((@IO/done_on_err__C0 @IO/done_on_err__C1) a) a) - -@IO/done_on_err__C3 = a - & @IO/Done ~ a - -@IO/done_on_err__C4 = (* (a (b (c (d f))))) - & @IO/Call ~ (a (b (c (((@IO/done_on_err__C2 (d e)) e) f)))) - -@IO/done_on_err__C5 = (?((@IO/done_on_err__C3 @IO/done_on_err__C4) a) a) - -@IO/wrap = a - & @IO/Done ~ (@IO/MAGIC a) - -@List/Cons = (a (b ((@List/Cons/tag (a (b c))) c))) - -@List/Cons/tag = 1 - -@List/Nil = ((@List/Nil/tag a) a) - -@List/Nil/tag = 0 - -@Result/Err = (a ((@Result/Err/tag (a b)) b)) - -@Result/Err/tag = 1 - -@Result/Ok = (a ((@Result/Ok/tag (a b)) b)) - -@Result/Ok/tag = 0 - -@String/Cons = (a (b ((@String/Cons/tag (a (b c))) c))) - -@String/Cons/tag = 1 - -@String/Nil = ((@String/Nil/tag a) a) - -@String/Nil/tag = 0 - -@String/encode_utf8 = ((@String/encode_utf8__C7 a) a) - -@String/encode_utf8__C0 = ({$([&0x000003F] g) {$([:>>0x0000006] $([&0x000003F] e)) {$([:>>0x000000C] $([&0x000003F] c)) $([:>>0x0000012] a)}}} (i n)) - & @List/Cons ~ (b (m n)) - & $(a b) ~ [|0x00000F0] - & @List/Cons ~ (d (l m)) - & $(c d) ~ [|0x0000080] - & @List/Cons ~ (f (k l)) - & $(e f) ~ [|0x0000080] - & @List/Cons ~ (h (j k)) - & $(g h) ~ [|0x0000080] - & @String/encode_utf8 ~ (i j) - -@String/encode_utf8__C1 = (* ({$([&0x000003F] e) {$([:>>0x0000006] $([&0x000003F] c)) $([:>>0x000000C] a)}} (g k))) - & @List/Cons ~ (b (j k)) - & $(a b) ~ [|0x00000E0] - & @List/Cons ~ (d (i j)) - & $(c d) ~ [|0x0000080] - & @List/Cons ~ (f (h i)) - & $(e f) ~ [|0x0000080] - & @String/encode_utf8 ~ (g h) - -@String/encode_utf8__C2 = ({$([<0x000FFFF] a) b} c) - & $(a ?((@String/encode_utf8__C0 @String/encode_utf8__C1) (b c))) ~ [=0x0000000] - -@String/encode_utf8__C3 = (* ({$([&0x000003F] c) $([:>>0x0000006] a)} (e h))) - & @List/Cons ~ (b (g h)) - & $(a b) ~ [|0x00000C0] - & @List/Cons ~ (d (f g)) - & $(c d) ~ [|0x0000080] - & @String/encode_utf8 ~ (e f) - -@String/encode_utf8__C4 = ({$([<0x00007FF] a) b} c) - & $(a ?((@String/encode_utf8__C2 @String/encode_utf8__C3) (b c))) ~ [=0x0000000] - -@String/encode_utf8__C5 = (* (a (b d))) - & @List/Cons ~ (a (c d)) - & @String/encode_utf8 ~ (b c) - -@String/encode_utf8__C6 = (* ({$([<0x000007F] a) b} c)) - & $(a ?((@String/encode_utf8__C4 @String/encode_utf8__C5) (b c))) ~ [=0x0000000] - -@String/encode_utf8__C7 = (?((@List/Nil @String/encode_utf8__C6) a) a) - -@call = (a (b c)) - & @IO/Call ~ (@IO/MAGIC (a (b (@call__C0 c)))) - -@call__C0 = a - & @IO/Done ~ (@IO/MAGIC a) - -@main = db - & @IO/bind ~ (t ((((u (y (* ab))) (bb (@IO/wrap cb))) cb) db)) - & @String/Cons ~ (46 (i {j bb})) - & @String/Cons ~ (47 (h i)) - & @String/Cons ~ (116 (g h)) - & @String/Cons ~ (101 (f g)) - & @String/Cons ~ (109 (e f)) - & @String/Cons ~ (112 (d e)) - & @String/Cons ~ (46 (c d)) - & @String/Cons ~ (116 (b c)) - & @String/Cons ~ (120 (a b)) - & @String/Cons ~ (116 (@String/Nil a)) - & @IO/FS/write_file ~ (j (s t)) - & @String/encode_utf8 ~ (r s) - & @String/Cons ~ (67 (q r)) - & @String/Cons ~ (111 (p q)) - & @String/Cons ~ (110 (o p)) - & @String/Cons ~ (116 (n o)) - & @String/Cons ~ (101 (m n)) - & @String/Cons ~ (110 (l m)) - & @String/Cons ~ (116 (k l)) - & @String/Cons ~ (115 (@String/Nil k)) - & @IO/bind ~ (v ((((w w) (y z)) z) ab)) - & @IO/FS/delete_file ~ (u v) - -@test-io = 1 - -@undefer = (((a a) b) b) - - diff --git a/tests/programs/io/delete_non_existing_file.hvm b/tests/programs/io/delete_non_existing_file.hvm deleted file mode 100644 index 11d6c365..00000000 --- a/tests/programs/io/delete_non_existing_file.hvm +++ /dev/null @@ -1,79 +0,0 @@ -@IO/Call = (a (b (c (d ((@IO/Call/tag (a (b (c (d e))))) e))))) - -@IO/Call/tag = 1 - -@IO/Done = (a (b ((@IO/Done/tag (a (b c))) c))) - -@IO/Done/tag = 0 - -@IO/FS/delete_file = l - & @call ~ (k l) - & @String/Cons ~ (68 (j k)) - & @String/Cons ~ (69 (i j)) - & @String/Cons ~ (76 (h i)) - & @String/Cons ~ (69 (g h)) - & @String/Cons ~ (84 (f g)) - & @String/Cons ~ (69 (e f)) - & @String/Cons ~ (95 (d e)) - & @String/Cons ~ (70 (c d)) - & @String/Cons ~ (73 (b c)) - & @String/Cons ~ (76 (a b)) - & @String/Cons ~ (69 (@String/Nil a)) - -@IO/MAGIC = (13683217 16719857) - -@IO/bind = ((@IO/bind__C2 a) a) - -@IO/bind__C0 = (* (b (a c))) - & @undefer ~ (a (b c)) - -@IO/bind__C1 = (* (* (a (b ((c d) (e g)))))) - & @IO/Call ~ (@IO/MAGIC (a (b ((c f) g)))) - & @IO/bind ~ (d (e f)) - -@IO/bind__C2 = (?((@IO/bind__C0 @IO/bind__C1) a) a) - -@IO/wrap = a - & @IO/Done ~ (@IO/MAGIC a) - -@String/Cons = (a (b ((@String/Cons/tag (a (b c))) c))) - -@String/Cons/tag = 1 - -@String/Nil = ((@String/Nil/tag a) a) - -@String/Nil/tag = 0 - -@call = (a (b c)) - & @IO/Call ~ (@IO/MAGIC (a (b (@call__C0 c)))) - -@call__C0 = a - & @IO/Done ~ (@IO/MAGIC a) - -@main = w - & @IO/bind ~ (s ((((t t) (@IO/wrap v)) v) w)) - & @IO/FS/delete_file ~ (r s) - & @String/Cons ~ (46 (q r)) - & @String/Cons ~ (47 (p q)) - & @String/Cons ~ (110 (o p)) - & @String/Cons ~ (111 (n o)) - & @String/Cons ~ (110 (m n)) - & @String/Cons ~ (95 (l m)) - & @String/Cons ~ (101 (k l)) - & @String/Cons ~ (120 (j k)) - & @String/Cons ~ (105 (i j)) - & @String/Cons ~ (115 (h i)) - & @String/Cons ~ (116 (g h)) - & @String/Cons ~ (105 (f g)) - & @String/Cons ~ (110 (e f)) - & @String/Cons ~ (103 (d e)) - & @String/Cons ~ (46 (c d)) - & @String/Cons ~ (116 (b c)) - & @String/Cons ~ (120 (a b)) - & @String/Cons ~ (116 (@String/Nil a)) - -@test-io = 1 - -@undefer = (((a a) b) b) - - diff --git a/tests/snapshots/run__io_file@io__create_directory.hvm.snap b/tests/snapshots/run__io_file@io__create_directory.hvm.snap deleted file mode 100644 index e15e0457..00000000 --- a/tests/snapshots/run__io_file@io__create_directory.hvm.snap +++ /dev/null @@ -1,6 +0,0 @@ ---- -source: tests/run.rs -expression: c_output -input_file: tests/programs/io/create_directory.hvm ---- -Result: ((@IO/Done/tag (@IO/MAGIC (((0 (* x0)) x0) x1))) x1) diff --git a/tests/snapshots/run__io_file@io__delete_dir_file.hvm.snap b/tests/snapshots/run__io_file@io__delete_dir_file.hvm.snap deleted file mode 100644 index 6435af8a..00000000 --- a/tests/snapshots/run__io_file@io__delete_dir_file.hvm.snap +++ /dev/null @@ -1,6 +0,0 @@ ---- -source: tests/run.rs -expression: c_output -input_file: tests/programs/io/delete_dir_file.hvm ---- -Result: ((@IO/Done/tag (@IO/MAGIC (((1 (((2 (+2 x0)) x0) x1)) x1) x2))) x2) diff --git a/tests/snapshots/run__io_file@io__delete_dir_recursive.hvm.snap b/tests/snapshots/run__io_file@io__delete_dir_recursive.hvm.snap deleted file mode 100644 index abd18921..00000000 --- a/tests/snapshots/run__io_file@io__delete_dir_recursive.hvm.snap +++ /dev/null @@ -1,6 +0,0 @@ ---- -source: tests/run.rs -expression: c_output -input_file: tests/programs/io/delete_dir_recursive.hvm ---- -Result: ((@IO/Done/tag (@IO/MAGIC (((0 (* x0)) x0) x1))) x1) diff --git a/tests/snapshots/run__io_file@io__delete_empty_dir.hvm.snap b/tests/snapshots/run__io_file@io__delete_empty_dir.hvm.snap deleted file mode 100644 index 97e8e204..00000000 --- a/tests/snapshots/run__io_file@io__delete_empty_dir.hvm.snap +++ /dev/null @@ -1,6 +0,0 @@ ---- -source: tests/run.rs -expression: c_output -input_file: tests/programs/io/delete_empty_dir.hvm ---- -Result: ((@IO/Done/tag (@IO/MAGIC (((0 (* x0)) x0) x1))) x1) diff --git a/tests/snapshots/run__io_file@io__delete_file.hvm.snap b/tests/snapshots/run__io_file@io__delete_file.hvm.snap deleted file mode 100644 index 4af58b20..00000000 --- a/tests/snapshots/run__io_file@io__delete_file.hvm.snap +++ /dev/null @@ -1,6 +0,0 @@ ---- -source: tests/run.rs -expression: c_output -input_file: tests/programs/io/delete_file.hvm ---- -Result: ((@IO/Done/tag (@IO/MAGIC (((0 (* x0)) x0) x1))) x1) diff --git a/tests/snapshots/run__io_file@io__delete_non_existing_file.hvm.snap b/tests/snapshots/run__io_file@io__delete_non_existing_file.hvm.snap deleted file mode 100644 index f26692d1..00000000 --- a/tests/snapshots/run__io_file@io__delete_non_existing_file.hvm.snap +++ /dev/null @@ -1,6 +0,0 @@ ---- -source: tests/run.rs -expression: c_output -input_file: tests/programs/io/delete_non_existing_file.hvm ---- -Result: ((@IO/Done/tag (@IO/MAGIC (((1 (((2 (+2 x0)) x0) x1)) x1) x2))) x2) From 7dab28a9a6c681874c05a5b5d7c16d0a2851449a Mon Sep 17 00:00:00 2001 From: imaqtkatt Date: Tue, 27 Aug 2024 09:24:59 -0300 Subject: [PATCH 05/10] WIP add functions to cuda --- src/run.cu | 122 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) diff --git a/src/run.cu b/src/run.cu index 970f8a01..c5333bc2 100644 --- a/src/run.cu +++ b/src/run.cu @@ -1,6 +1,10 @@ #include #include #include +#include +#include +#include +#include #include "hvm.cu" // Readback: λ-Encoded Ctr @@ -834,6 +838,121 @@ Port io_dl_close(GNet* gnet, Book* book, Port argm) { return gnet_inject_ok(gnet, new_port(ERA, 0)); } +// Deletes a single file or an empty directory at the specified path. +// Returns Ok(None) if successful, or Err(reason) if an error occurs. +// This function attempts to remove both files and empty directories without +// first checking the type of the path. +// Returns: Result<*, IOError> +Port io_delete_file(GNet* gnet, Port argm) { + Str s = gnet_readback_str(gnet, argm); + + int result = remove(s.buf); + free(s.buf); + + if (result == 0) { + return gnet_inject_ok(gnet, new_port(ERA, 0)); + } else { + return gnet_inject_io_err_inner(gnet, new_port(NUM, new_i24(errno))); + } +} + +int delete_directory_recursive(const char* path) { + DIR* d = opendir(path); + size_t path_len = strlen(path); + int r = -1; + + if (d) { + struct dirent *p; + r = 0; + + while (!r && (p = readdir(d))) { + int r2 = -1; + char* buf; + size_t len; + + if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, "..")) { + continue; + } + + len = path_len + strlen(p->d_name) + 2; + buf = malloc(len); + + if (buf) { + struct stat statbuf; + snprintf(buf, len, "%s/%s", path, p->d_name); + + if (!stat(buf, &statbuf)) { + if (S_ISDIR(statbuf.st_mode)) { + r2 = delete_directory_recursive(buf); + } else { + r2 = remove(buf); + } + } + + free(buf); + } + + r = r2; + } + + closedir(d); + } + + if (!r) { + r = rmdir(path); + } + + return r; +} + +// Deletes a directory at the specified path. If recursive is True, +// it will delete the directory and all its contents. +// Returns Ok(None) if successful, or Err(reason) if an error occurs. +// Note: For non-recursive deletion of an empty directory, +// this function behaves the same as delete_file(path). +// Returns: Result<*, IOError> +Port io_delete_directory(GNet* gnet, Port argm) { + Tup tup = gnet_readback_tup(gnet, argm, 2); + if (tup.elem_len != 2) { + fprintf(stderr, "io_delete_directory: expected tuple\n"); + + return gnet_inject_io_err_type(gnet); + } + + Str path = gnet_readback_str(gnet, tup.elem_buf[0]); + u32 rec = get_u24(get_val(tup.elem_buf[1])); + int res; + if (rec) { + res = delete_directory_recursive(path.buf); + } else { + res = rmdir(path.buf); + } + free(path.buf); + + if (res == 0) { + return gnet_inject_ok(gnet, new_port(ERA, 0)); + } else { + return gnet_inject_io_err_inner(gnet, new_port(NUM, new_i24(errno))); + } +} + +// Creates a new directory with the given path. +// Returns Ok(None) if sucessfull, or Err(reason) if an error occurs. +// Returns: Result<*, IOError> +Port io_mkdir(GNet* gnet, Port argm) { + Str name = gnet_readback_str(gnet, argm); + + const mode_t mode = 0777; + int result = mkdir(name.buf, mode); + free(name.buf); + + if (result) { + return gnet_inject_io_err_inner(gnet, new_port(NUM, new_i24(errno))); + } else { + return gnet_inject_ok(gnet, new_port(ERA, 0)); + } +} + void book_init(Book* book) { book->ffns_buf[book->ffns_len++] = (FFn){"READ", io_read}; book->ffns_buf[book->ffns_len++] = (FFn){"OPEN", io_open}; @@ -846,6 +965,9 @@ void book_init(Book* book) { book->ffns_buf[book->ffns_len++] = (FFn){"DL_OPEN", io_dl_open}; book->ffns_buf[book->ffns_len++] = (FFn){"DL_CALL", io_dl_call}; book->ffns_buf[book->ffns_len++] = (FFn){"DL_CLOSE", io_dl_open}; + book->ffns_buf[book->ffns_len++] = (FFn){"DELETE_FILE", io_delete_file}; + book->ffns_buf[book->ffns_len++] = (FFn){"DELETE_DIRECTORY", io_delete_directory}; + book->ffns_buf[book->ffns_len++] = (FFn){"MKDIR", io_mkdir}; cudaMemcpyToSymbol(BOOK, book, sizeof(Book)); } From c3cf50f5cf48c31118e65f029f8204af67ec8828 Mon Sep 17 00:00:00 2001 From: imaqtkatt Date: Tue, 27 Aug 2024 09:53:00 -0300 Subject: [PATCH 06/10] fix void cast --- src/run.cu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/run.cu b/src/run.cu index c5333bc2..5fae3ddd 100644 --- a/src/run.cu +++ b/src/run.cu @@ -875,7 +875,7 @@ int delete_directory_recursive(const char* path) { } len = path_len + strlen(p->d_name) + 2; - buf = malloc(len); + buf = (char*) malloc(len); if (buf) { struct stat statbuf; From 8ddc3aa5e2cd0570602becd45fe2580d4a5a8306 Mon Sep 17 00:00:00 2001 From: imaqtkatt Date: Tue, 27 Aug 2024 10:23:02 -0300 Subject: [PATCH 07/10] add flags to build.rs --- build.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.rs b/build.rs index dd72c946..0b0a2193 100644 --- a/build.rs +++ b/build.rs @@ -37,6 +37,8 @@ fn main() { .flag("-diag-suppress=177") // variable was declared but never referenced .flag("-diag-suppress=550") // variable was set but never used .flag("-diag-suppress=20039") // a __host__ function redeclared with __device__, hence treated as a __host__ __device__ function + .flag("-diag-suppress=68") // integer conversion resulted in a change of sign + .flag("-diag-suppress=2464") // conversion from a string literal to "char *" is deprecated .compile("hvm-cu"); println!("cargo:rustc-cfg=feature=\"cuda\""); From 38408af561e38ae620d1e889fca29919aecd219a Mon Sep 17 00:00:00 2001 From: imaqtkatt Date: Fri, 30 Aug 2024 09:56:09 -0300 Subject: [PATCH 08/10] refactor rename and use nftw function --- src/run.c | 82 ++++------------ src/run.cu | 93 +++++-------------- tests/programs/io/create_directory.bend | 21 ----- tests/programs/io/delete_dir_file.bend | 16 ---- tests/programs/io/delete_empty_dir.bend | 18 ---- .../programs/io/delete_non_existing_file.bend | 15 --- tests/programs/io/mkdir.bend | 19 ++++ tests/programs/io/remove_all_file.bend | 16 ++++ ...cursive.bend => remove_all_recursive.bend} | 27 +++--- tests/programs/io/remove_empty_dir.bend | 18 ++++ .../io/{delete_file.bend => remove_file.bend} | 8 +- .../programs/io/remove_non_existing_file.bend | 15 +++ 12 files changed, 130 insertions(+), 218 deletions(-) delete mode 100644 tests/programs/io/create_directory.bend delete mode 100644 tests/programs/io/delete_dir_file.bend delete mode 100644 tests/programs/io/delete_empty_dir.bend delete mode 100644 tests/programs/io/delete_non_existing_file.bend create mode 100644 tests/programs/io/mkdir.bend create mode 100644 tests/programs/io/remove_all_file.bend rename tests/programs/io/{delete_dir_recursive.bend => remove_all_recursive.bend} (53%) create mode 100644 tests/programs/io/remove_empty_dir.bend rename tests/programs/io/{delete_file.bend => remove_file.bend} (52%) create mode 100644 tests/programs/io/remove_non_existing_file.bend diff --git a/src/run.c b/src/run.c index 623c8997..e75dc409 100644 --- a/src/run.c +++ b/src/run.c @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include "hvm.c" // Readback: λ-Encoded Ctr @@ -724,7 +724,7 @@ Port io_dl_close(Net* net, Book* book, Port argm) { // This function attempts to remove both files and empty directories without // first checking the type of the path. // Returns: Result<*, IOError> -Port io_delete_file(Net* net, Book* book, Port argm) { +Port io_remove(Net* net, Book* book, Port argm) { Str path = readback_str(net, book, argm); int result = remove(path.buf); @@ -737,76 +737,32 @@ Port io_delete_file(Net* net, Book* book, Port argm) { } } -int delete_directory_recursive(const char* path) { - DIR *d = opendir(path); - size_t path_len = strlen(path); - int r = -1; - - if (d) { - struct dirent *p; - r = 0; - - while (!r && (p = readdir(d))) { - int r2 = -1; - char *buf; - size_t len; - - if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, "..")) { - continue; - } - - len = path_len + strlen(p->d_name) + 2; - buf = malloc(len); - - if (buf) { - struct stat statbuf; - snprintf(buf, len, "%s/%s", path, p->d_name); - - if (!stat(buf, &statbuf)) { - if (S_ISDIR(statbuf.st_mode)) { - r2 = delete_directory_recursive(buf); - } else { - r2 = remove(buf); - } - } - - free(buf); - } - - r = r2; - } +int remove_all_aux(const char* path, const struct stat* stat, int flags, struct FTW* ftw) { + return remove(path); +} - closedir(d); +int remove_all(const char* path) { + struct stat st; + if (stat(path, &st) != 0) { + return remove(path); } - - if (!r) { - r = rmdir(path); + if (S_ISDIR(st.st_mode)) { + return nftw(path, remove_all_aux, 32, FTW_DEPTH | FTW_PHYS); + } else { + return remove(path); } - - return r; } -// Deletes a directory at the specified path. If recursive is True, +// Removes any file or directory recursively at the specified path. // it will delete the directory and all its contents. // Returns Ok(None) if successful, or Err(reason) if an error occurs. // Note: For non-recursive deletion of an empty directory, // this function behaves the same as delete_file(path). // Returns: Result<*, IOError> -Port io_delete_directory(Net* net, Book* book, Port argm) { - Tup tup = readback_tup(net, book, argm, 2); - if (2 != tup.elem_len) { - return inject_io_err_type(net); - } - - Str path = readback_str(net, book, tup.elem_buf[0]); - u32 rec = get_u24(get_val(tup.elem_buf[1])); +Port io_remove_all(Net* net, Book* book, Port argm) { + Str path = readback_str(net, book, argm); - int res; - if (rec) { - res = delete_directory_recursive(path.buf); - } else { - res = rmdir(path.buf); - } + int res = remove_all(path.buf); free(path.buf); if (0 == res) { @@ -848,8 +804,8 @@ void book_init(Book* book) { book->ffns_buf[book->ffns_len++] = (FFn){"DL_OPEN", io_dl_open}; book->ffns_buf[book->ffns_len++] = (FFn){"DL_CALL", io_dl_call}; book->ffns_buf[book->ffns_len++] = (FFn){"DL_CLOSE", io_dl_open}; - book->ffns_buf[book->ffns_len++] = (FFn){"DELETE_FILE", io_delete_file}; - book->ffns_buf[book->ffns_len++] = (FFn){"DELETE_DIRECTORY", io_delete_directory}; + book->ffns_buf[book->ffns_len++] = (FFn){"RM", io_remove}; + book->ffns_buf[book->ffns_len++] = (FFn){"RM_ALL", io_remove_all}; book->ffns_buf[book->ffns_len++] = (FFn){"MKDIR", io_mkdir}; } diff --git a/src/run.cu b/src/run.cu index 5fae3ddd..2ebf4930 100644 --- a/src/run.cu +++ b/src/run.cu @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include "hvm.cu" // Readback: λ-Encoded Ctr @@ -838,12 +838,12 @@ Port io_dl_close(GNet* gnet, Book* book, Port argm) { return gnet_inject_ok(gnet, new_port(ERA, 0)); } -// Deletes a single file or an empty directory at the specified path. +// Removes a single file or an empty directory at the specified path. // Returns Ok(None) if successful, or Err(reason) if an error occurs. // This function attempts to remove both files and empty directories without // first checking the type of the path. // Returns: Result<*, IOError> -Port io_delete_file(GNet* gnet, Port argm) { +Port io_remove(GNet* gnet, Port argm) { Str s = gnet_readback_str(gnet, argm); int result = remove(s.buf); @@ -856,80 +856,35 @@ Port io_delete_file(GNet* gnet, Port argm) { } } -int delete_directory_recursive(const char* path) { - DIR* d = opendir(path); - size_t path_len = strlen(path); - int r = -1; - - if (d) { - struct dirent *p; - r = 0; - - while (!r && (p = readdir(d))) { - int r2 = -1; - char* buf; - size_t len; - - if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, "..")) { - continue; - } - - len = path_len + strlen(p->d_name) + 2; - buf = (char*) malloc(len); - - if (buf) { - struct stat statbuf; - snprintf(buf, len, "%s/%s", path, p->d_name); - - if (!stat(buf, &statbuf)) { - if (S_ISDIR(statbuf.st_mode)) { - r2 = delete_directory_recursive(buf); - } else { - r2 = remove(buf); - } - } - - free(buf); - } - - r = r2; - } +int remove_all_aux(const char* path, const struct stat* stat, int flags, struct FTW* ftw) { + return remove(path); +} - closedir(d); +int remove_all(const char* path) { + struct stat st; + if (stat(path, &st) != 0) { + return remove(path); } - - if (!r) { - r = rmdir(path); + if (S_ISDIR(st.st_mode)) { + return nftw(path, remove_all_aux, 32, FTW_DEPTH | FTW_PHYS); + } else { + return remove(path); } - - return r; } -// Deletes a directory at the specified path. If recursive is True, +// Removes any file or directory recursively at the specified path. // it will delete the directory and all its contents. // Returns Ok(None) if successful, or Err(reason) if an error occurs. // Note: For non-recursive deletion of an empty directory, // this function behaves the same as delete_file(path). // Returns: Result<*, IOError> -Port io_delete_directory(GNet* gnet, Port argm) { - Tup tup = gnet_readback_tup(gnet, argm, 2); - if (tup.elem_len != 2) { - fprintf(stderr, "io_delete_directory: expected tuple\n"); - - return gnet_inject_io_err_type(gnet); - } - - Str path = gnet_readback_str(gnet, tup.elem_buf[0]); - u32 rec = get_u24(get_val(tup.elem_buf[1])); - int res; - if (rec) { - res = delete_directory_recursive(path.buf); - } else { - res = rmdir(path.buf); - } +Port io_remove_all(GNet* gnet, Port argm) { + Str path = gnet_readback_str(gnet, argm); + + int res = remove_all(path.buf); free(path.buf); - if (res == 0) { + if (0 == res) { return gnet_inject_ok(gnet, new_port(ERA, 0)); } else { return gnet_inject_io_err_inner(gnet, new_port(NUM, new_i24(errno))); @@ -943,10 +898,10 @@ Port io_mkdir(GNet* gnet, Port argm) { Str name = gnet_readback_str(gnet, argm); const mode_t mode = 0777; - int result = mkdir(name.buf, mode); + int status = mkdir(name.buf, mode); free(name.buf); - if (result) { + if (status) { return gnet_inject_io_err_inner(gnet, new_port(NUM, new_i24(errno))); } else { return gnet_inject_ok(gnet, new_port(ERA, 0)); @@ -965,8 +920,8 @@ void book_init(Book* book) { book->ffns_buf[book->ffns_len++] = (FFn){"DL_OPEN", io_dl_open}; book->ffns_buf[book->ffns_len++] = (FFn){"DL_CALL", io_dl_call}; book->ffns_buf[book->ffns_len++] = (FFn){"DL_CLOSE", io_dl_open}; - book->ffns_buf[book->ffns_len++] = (FFn){"DELETE_FILE", io_delete_file}; - book->ffns_buf[book->ffns_len++] = (FFn){"DELETE_DIRECTORY", io_delete_directory}; + book->ffns_buf[book->ffns_len++] = (FFn){"RM", io_remove}; + book->ffns_buf[book->ffns_len++] = (FFn){"RM_ALL", io_remove_all}; book->ffns_buf[book->ffns_len++] = (FFn){"MKDIR", io_mkdir}; cudaMemcpyToSymbol(BOOK, book, sizeof(Book)); diff --git a/tests/programs/io/create_directory.bend b/tests/programs/io/create_directory.bend deleted file mode 100644 index e88b4ee9..00000000 --- a/tests/programs/io/create_directory.bend +++ /dev/null @@ -1,21 +0,0 @@ -#{ - Creates the batata directory and then deletes it. -#} - -test-io = 1 - -IO/FS/mkdir path = - (call "MKDIR" path) - -IO/FS/delete_directory path recursive = - (call "DELETE_DIRECTORY" (path, recursive)) - -False = 0 - -main = - let path = "./batata" - with IO { - ask * = (IO/FS/mkdir path) - ask s = (IO/FS/delete_directory path False) - (wrap s) - } diff --git a/tests/programs/io/delete_dir_file.bend b/tests/programs/io/delete_dir_file.bend deleted file mode 100644 index 537e95c6..00000000 --- a/tests/programs/io/delete_dir_file.bend +++ /dev/null @@ -1,16 +0,0 @@ -#{ - Calls the delete_directory function with a file path as argument. -#} - -test-io = 1 - -IO/FS/delete_directory path recursive = - (call "DELETE_DIRECTORY" (path, recursive)) - -False = 0 - -main = - with IO { - ask s = (IO/FS/delete_directory "./delete_dir_file.bend" False) - (wrap s) - } diff --git a/tests/programs/io/delete_empty_dir.bend b/tests/programs/io/delete_empty_dir.bend deleted file mode 100644 index 9e50d2d1..00000000 --- a/tests/programs/io/delete_empty_dir.bend +++ /dev/null @@ -1,18 +0,0 @@ -#{ - Uses the delete_file function to delete an empty directory. -#} - -test-io = 1 - -IO/FS/mkdir path = - (call "MKDIR" path) - -IO/FS/delete_file path = - (call "DELETE_FILE" path) - -main = - with IO { - ask * = (IO/FS/mkdir "temp") - ask s = (IO/FS/delete_file "temp") - (wrap s) - } diff --git a/tests/programs/io/delete_non_existing_file.bend b/tests/programs/io/delete_non_existing_file.bend deleted file mode 100644 index 219d5972..00000000 --- a/tests/programs/io/delete_non_existing_file.bend +++ /dev/null @@ -1,15 +0,0 @@ -#{ - Tries to delete a non existing file. -#} - -test-io = 1 - -IO/FS/delete_file path = - (call "DELETE_FILE" path) - -main = - use path = "./non_existing.txt" - with IO { - ask s = (IO/FS/delete_file path) - (wrap s) - } diff --git a/tests/programs/io/mkdir.bend b/tests/programs/io/mkdir.bend new file mode 100644 index 00000000..38f2ba7b --- /dev/null +++ b/tests/programs/io/mkdir.bend @@ -0,0 +1,19 @@ +#{ + Creates the batata directory and then removes it. +#} + +test-io = 1 + +mkdir path = + (call "MKDIR" path) + +rm_all path = + (call "RM_ALL" path) + +main = + let path = "./batata" + with IO { + ask * = (mkdir path) + ask s = (rm_all path) + (wrap s) + } diff --git a/tests/programs/io/remove_all_file.bend b/tests/programs/io/remove_all_file.bend new file mode 100644 index 00000000..ca2d96bf --- /dev/null +++ b/tests/programs/io/remove_all_file.bend @@ -0,0 +1,16 @@ +#{ + Calls the rm_all function with a file path as argument. +#} + +test-io = 1 + +rm_all path = + (call "RM_ALL" path) + +main = + let temp = "./temp.txt" + with IO { + ask * = (IO/FS/write_file temp (String/encode_utf8 "Contents")) + ask s = (rm_all temp) + (wrap s) + } diff --git a/tests/programs/io/delete_dir_recursive.bend b/tests/programs/io/remove_all_recursive.bend similarity index 53% rename from tests/programs/io/delete_dir_recursive.bend rename to tests/programs/io/remove_all_recursive.bend index 6e9a859a..17c3a709 100644 --- a/tests/programs/io/delete_dir_recursive.bend +++ b/tests/programs/io/remove_all_recursive.bend @@ -1,5 +1,5 @@ #{ - Creates the following tree structure and then deletes A and its children. + Creates the following tree structure and then removes A and its children. A |-- a.txt |-- AA @@ -10,23 +10,26 @@ test-io = 1 -IO/FS/mkdir path = +mkdir path = (call "MKDIR" path) -IO/FS/delete_directory path recursive = - (call "DELETE_DIRECTORY" (path, recursive)) +rm_all path = + (call "RM_ALL" path) -True = 1 - -main = +test = with IO { - ask * = (IO/FS/mkdir "A") - ask * = (IO/FS/mkdir "A/AA") - ask * = (IO/FS/mkdir "A/AB") + ask * = (mkdir "A") + ask * = (mkdir "A/AA") + ask * = (mkdir "A/AB") ask * = (IO/FS/write_file "A/a.txt" (String/encode_utf8 "a")) ask * = (IO/FS/write_file "A/AA/aa.txt" (String/encode_utf8 "aa")) ask * = (IO/FS/write_file "A/AB/ab.txt" (String/encode_utf8 "ab")) - - ask s = (IO/FS/delete_directory "A" True) + ask s = (rm_all "./A") (wrap s) } + +main = + with IO { + ask res = (test) + (wrap res) + } diff --git a/tests/programs/io/remove_empty_dir.bend b/tests/programs/io/remove_empty_dir.bend new file mode 100644 index 00000000..94f9507e --- /dev/null +++ b/tests/programs/io/remove_empty_dir.bend @@ -0,0 +1,18 @@ +#{ + Uses the rm function to remove an empty directory. +#} + +test-io = 1 + +mkdir path = + (call "MKDIR" path) + +rm path = + (call "RM" path) + +main = + with IO { + ask * = (mkdir "temp") + ask s = (rm "temp") + (wrap s) + } diff --git a/tests/programs/io/delete_file.bend b/tests/programs/io/remove_file.bend similarity index 52% rename from tests/programs/io/delete_file.bend rename to tests/programs/io/remove_file.bend index 6f47ed29..e36fe6f5 100644 --- a/tests/programs/io/delete_file.bend +++ b/tests/programs/io/remove_file.bend @@ -1,16 +1,16 @@ #{ - Creates a temporary file and then deletes it. + Creates a temporary file and then removes it. #} test-io = 1 -IO/FS/delete_file path = - (call "DELETE_FILE" path) +rm path = + (call "RM" path) main = let path = "./temp.txt" with IO { ask * = (IO/FS/write_file path (String/encode_utf8 "Contents")) - ask s = (IO/FS/delete_file path) + ask s = (rm path) (wrap s) } diff --git a/tests/programs/io/remove_non_existing_file.bend b/tests/programs/io/remove_non_existing_file.bend new file mode 100644 index 00000000..5072b091 --- /dev/null +++ b/tests/programs/io/remove_non_existing_file.bend @@ -0,0 +1,15 @@ +#{ + Tries to remove a non existing file. +#} + +test-io = 1 + +rm path = + (call "RM" path) + +main = + use path = "./non_existing.txt" + with IO { + ask s = (rm path) + (wrap s) + } From e303e04072141e20905fa707f3b85b23a77faf18 Mon Sep 17 00:00:00 2001 From: imaqtkatt Date: Fri, 30 Aug 2024 13:30:26 -0300 Subject: [PATCH 09/10] remove unused header file and remove suppress flags --- build.rs | 2 -- src/run.cu | 1 - 2 files changed, 3 deletions(-) diff --git a/build.rs b/build.rs index 0b0a2193..dd72c946 100644 --- a/build.rs +++ b/build.rs @@ -37,8 +37,6 @@ fn main() { .flag("-diag-suppress=177") // variable was declared but never referenced .flag("-diag-suppress=550") // variable was set but never used .flag("-diag-suppress=20039") // a __host__ function redeclared with __device__, hence treated as a __host__ __device__ function - .flag("-diag-suppress=68") // integer conversion resulted in a change of sign - .flag("-diag-suppress=2464") // conversion from a string literal to "char *" is deprecated .compile("hvm-cu"); println!("cargo:rustc-cfg=feature=\"cuda\""); diff --git a/src/run.cu b/src/run.cu index 2ebf4930..24b74ecd 100644 --- a/src/run.cu +++ b/src/run.cu @@ -3,7 +3,6 @@ #include #include #include -#include #include #include "hvm.cu" From 4a4167064177025b059428ed367ea1d490b4aa37 Mon Sep 17 00:00:00 2001 From: imaqtkatt Date: Tue, 3 Sep 2024 12:09:31 -0300 Subject: [PATCH 10/10] conditionally define _XOPEN_SOURCE --- src/run.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/run.c b/src/run.c index e75dc409..8512c30c 100644 --- a/src/run.c +++ b/src/run.c @@ -1,3 +1,7 @@ +#ifndef __APPLE__ +#define _XOPEN_SOURCE 500 +#endif + #include #include #include