@@ -174,7 +174,92 @@ extern "C" fn roc_crashed_fn(roc_crashed: *const RocCrashed, _env: *mut c_void)
174174// Hosted Functions (sorted alphabetically by fully-qualified name)
175175// ============================================================================
176176
177- /// Hosted function: Env.cwd! (index 0)
177+ /// Hosted function: Dir.create! (index 0)
178+ /// Takes Str, returns {}
179+ extern "C" fn hosted_dir_create (
180+ _ops : * const RocOps ,
181+ _ret_ptr : * mut c_void ,
182+ args_ptr : * mut c_void ,
183+ ) {
184+ unsafe {
185+ let path = args_ptr as * const RocStr ;
186+ let _ = fs:: create_dir ( ( * path) . as_str ( ) ) ;
187+ }
188+ }
189+
190+ /// Hosted function: Dir.create_all! (index 1)
191+ /// Takes Str, returns {}
192+ extern "C" fn hosted_dir_create_all (
193+ _ops : * const RocOps ,
194+ _ret_ptr : * mut c_void ,
195+ args_ptr : * mut c_void ,
196+ ) {
197+ unsafe {
198+ let path = args_ptr as * const RocStr ;
199+ let _ = fs:: create_dir_all ( ( * path) . as_str ( ) ) ;
200+ }
201+ }
202+
203+ /// Hosted function: Dir.delete_all! (index 2)
204+ /// Takes Str, returns {}
205+ extern "C" fn hosted_dir_delete_all (
206+ _ops : * const RocOps ,
207+ _ret_ptr : * mut c_void ,
208+ args_ptr : * mut c_void ,
209+ ) {
210+ unsafe {
211+ let path = args_ptr as * const RocStr ;
212+ let _ = fs:: remove_dir_all ( ( * path) . as_str ( ) ) ;
213+ }
214+ }
215+
216+ /// Hosted function: Dir.delete_empty! (index 3)
217+ /// Takes Str, returns {}
218+ extern "C" fn hosted_dir_delete_empty (
219+ _ops : * const RocOps ,
220+ _ret_ptr : * mut c_void ,
221+ args_ptr : * mut c_void ,
222+ ) {
223+ unsafe {
224+ let path = args_ptr as * const RocStr ;
225+ let _ = fs:: remove_dir ( ( * path) . as_str ( ) ) ;
226+ }
227+ }
228+
229+ /// Hosted function: Dir.list! (index 4)
230+ /// Takes Str, returns List(Str)
231+ extern "C" fn hosted_dir_list (
232+ ops : * const RocOps ,
233+ ret_ptr : * mut c_void ,
234+ args_ptr : * mut c_void ,
235+ ) {
236+ let roc_ops = unsafe { & * ops } ;
237+ let path = unsafe {
238+ let args = args_ptr as * const RocStr ;
239+ ( * args) . as_str ( ) . to_string ( )
240+ } ;
241+
242+ let entries: Vec < String > = fs:: read_dir ( & path)
243+ . map ( |rd| {
244+ rd. filter_map ( |entry| {
245+ entry. ok ( ) . map ( |e| e. path ( ) . to_string_lossy ( ) . into_owned ( ) )
246+ } )
247+ . collect ( )
248+ } )
249+ . unwrap_or_default ( ) ;
250+
251+ let mut list = RocList :: with_capacity ( entries. len ( ) , roc_ops) ;
252+ for entry in entries {
253+ let roc_str = RocStr :: from_str ( & entry, roc_ops) ;
254+ list. push ( roc_str, roc_ops) ;
255+ }
256+
257+ unsafe {
258+ * ( ret_ptr as * mut RocList < RocStr > ) = list;
259+ }
260+ }
261+
262+ /// Hosted function: Env.cwd! (index 5)
178263/// Takes {}, returns Str
179264extern "C" fn hosted_env_cwd (
180265 ops : * const RocOps ,
@@ -191,7 +276,7 @@ extern "C" fn hosted_env_cwd(
191276 }
192277}
193278
194- /// Hosted function: Env.exe_path! (index 1 )
279+ /// Hosted function: Env.exe_path! (index 6 )
195280/// Takes {}, returns Str
196281extern "C" fn hosted_env_exe_path (
197282 ops : * const RocOps ,
@@ -208,7 +293,7 @@ extern "C" fn hosted_env_exe_path(
208293 }
209294}
210295
211- /// Hosted function: Env.var! (index 2 )
296+ /// Hosted function: Env.var! (index 7 )
212297/// Takes Str, returns Str
213298extern "C" fn hosted_env_var (
214299 ops : * const RocOps ,
@@ -227,7 +312,7 @@ extern "C" fn hosted_env_var(
227312 }
228313}
229314
230- /// Hosted function: File.delete! (index 3 )
315+ /// Hosted function: File.delete! (index 8 )
231316/// Takes Str (path), returns {}
232317extern "C" fn hosted_file_delete (
233318 _ops : * const RocOps ,
@@ -241,7 +326,7 @@ extern "C" fn hosted_file_delete(
241326 let _ = fs:: remove_file ( path) ;
242327}
243328
244- /// Hosted function: File.read_bytes! (index 4 )
329+ /// Hosted function: File.read_bytes! (index 9 )
245330/// Takes Str (path), returns List(U8)
246331extern "C" fn hosted_file_read_bytes (
247332 ops : * const RocOps ,
@@ -263,7 +348,7 @@ extern "C" fn hosted_file_read_bytes(
263348 }
264349}
265350
266- /// Hosted function: File.read_utf8! (index 5 )
351+ /// Hosted function: File.read_utf8! (index 10 )
267352/// Takes Str (path), returns Str
268353extern "C" fn hosted_file_read_utf8 (
269354 ops : * const RocOps ,
@@ -282,7 +367,7 @@ extern "C" fn hosted_file_read_utf8(
282367 }
283368}
284369
285- /// Hosted function: File.write_bytes! (index 6 )
370+ /// Hosted function: File.write_bytes! (index 11 )
286371/// Takes (Str, List(U8)), returns {}
287372extern "C" fn hosted_file_write_bytes (
288373 _ops : * const RocOps ,
@@ -297,7 +382,7 @@ extern "C" fn hosted_file_write_bytes(
297382 }
298383}
299384
300- /// Hosted function: File.write_utf8! (index 7 )
385+ /// Hosted function: File.write_utf8! (index 12 )
301386/// Takes (Str, Str), returns {}
302387extern "C" fn hosted_file_write_utf8 (
303388 _ops : * const RocOps ,
@@ -312,7 +397,7 @@ extern "C" fn hosted_file_write_utf8(
312397 }
313398}
314399
315- /// Hosted function: Stderr.line! (index 8 )
400+ /// Hosted function: Stderr.line! (index 13 )
316401/// Takes Str, returns {}
317402extern "C" fn hosted_stderr_line (
318403 _ops : * const RocOps ,
@@ -329,7 +414,7 @@ extern "C" fn hosted_stderr_line(
329414 }
330415}
331416
332- /// Hosted function: Stderr.write! (index 9 )
417+ /// Hosted function: Stderr.write! (index 14 )
333418/// Takes Str, returns {}
334419extern "C" fn hosted_stderr_write (
335420 _ops : * const RocOps ,
@@ -346,7 +431,7 @@ extern "C" fn hosted_stderr_write(
346431 }
347432}
348433
349- /// Hosted function: Stdin.line! (index 10 )
434+ /// Hosted function: Stdin.line! (index 15 )
350435/// Takes {}, returns Str
351436extern "C" fn hosted_stdin_line (
352437 ops : * const RocOps ,
@@ -367,7 +452,7 @@ extern "C" fn hosted_stdin_line(
367452 }
368453}
369454
370- /// Hosted function: Stdout.line! (index 11 )
455+ /// Hosted function: Stdout.line! (index 16 )
371456/// Takes Str, returns {}
372457extern "C" fn hosted_stdout_line (
373458 _ops : * const RocOps ,
@@ -384,7 +469,7 @@ extern "C" fn hosted_stdout_line(
384469 }
385470}
386471
387- /// Hosted function: Stdout.write! (index 12 )
472+ /// Hosted function: Stdout.write! (index 17 )
388473/// Takes Str, returns {}
389474extern "C" fn hosted_stdout_write (
390475 _ops : * const RocOps ,
@@ -402,20 +487,25 @@ extern "C" fn hosted_stdout_write(
402487}
403488
404489/// Array of hosted function pointers, sorted alphabetically by fully-qualified name.
405- static HOSTED_FNS : [ HostedFn ; 13 ] = [
406- hosted_env_cwd, // Env.cwd! (index 0)
407- hosted_env_exe_path, // Env.exe_path! (index 1)
408- hosted_env_var, // Env.var! (index 2)
409- hosted_file_delete, // File.delete! (index 3)
410- hosted_file_read_bytes, // File.read_bytes! (index 4)
411- hosted_file_read_utf8, // File.read_utf8! (index 5)
412- hosted_file_write_bytes, // File.write_bytes! (index 6)
413- hosted_file_write_utf8, // File.write_utf8! (index 7)
414- hosted_stderr_line, // Stderr.line! (index 8)
415- hosted_stderr_write, // Stderr.write! (index 9)
416- hosted_stdin_line, // Stdin.line! (index 10)
417- hosted_stdout_line, // Stdout.line! (index 11)
418- hosted_stdout_write, // Stdout.write! (index 12)
490+ static HOSTED_FNS : [ HostedFn ; 18 ] = [
491+ hosted_dir_create, // Dir.create! (index 0)
492+ hosted_dir_create_all, // Dir.create_all! (index 1)
493+ hosted_dir_delete_all, // Dir.delete_all! (index 2)
494+ hosted_dir_delete_empty, // Dir.delete_empty! (index 3)
495+ hosted_dir_list, // Dir.list! (index 4)
496+ hosted_env_cwd, // Env.cwd! (index 5)
497+ hosted_env_exe_path, // Env.exe_path! (index 6)
498+ hosted_env_var, // Env.var! (index 7)
499+ hosted_file_delete, // File.delete! (index 8)
500+ hosted_file_read_bytes, // File.read_bytes! (index 9)
501+ hosted_file_read_utf8, // File.read_utf8! (index 10)
502+ hosted_file_write_bytes, // File.write_bytes! (index 11)
503+ hosted_file_write_utf8, // File.write_utf8! (index 12)
504+ hosted_stderr_line, // Stderr.line! (index 13)
505+ hosted_stderr_write, // Stderr.write! (index 14)
506+ hosted_stdin_line, // Stdin.line! (index 15)
507+ hosted_stdout_line, // Stdout.line! (index 16)
508+ hosted_stdout_write, // Stdout.write! (index 17)
419509] ;
420510
421511/// Build a RocList<RocStr> from command-line arguments.
0 commit comments