From 49c9662d43b7144868a4d230720876cf5263ff9a Mon Sep 17 00:00:00 2001 From: imaqtkatt Date: Thu, 22 Aug 2024 14:11:55 -0300 Subject: [PATCH] #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) - -