# abstract system layer < sys .linux "+" via { # ==directory "\0" cat 511 +mkdir 0 neq { ??io.dir.mk } rep } /mkdir sys .deff { # ==directory "\0" cat +ORDONLY +ODIRECTORY bor 0 +open ==fd fd 0 lt { ??io.dir.ls.open } { [ [ { fd +getdents64 _ 0 lt { ??io.dir.ls.getdents } rep } { _ len dearray } loop ] { .dname } each ] fd +close 0 lt { ??io.dir.ls.close } rep } ? * } /readdir sys .deff { # ==directory sys .readdir { 0 -01 * 0 "." * neq } grep } /ls sys .deff { _ ==pattern 0 ==prefixWithDir "^(.*)/([^/]*)$" regex { ==dir =pattern 1 =prefixWithDir }" { "." ==dir }" ? * [ pattern { ==c [ # FIXME: [, ] escapes in regexes { c 0 "." * eq } { "\\." { } each } { c 0 "*" * eq } { ".*" { } each } { c 0 "?" * eq } { "." { } each } { 1 } { c } ] conds } each ] str .fromArray "^" -01 cat "$" cat ==rx dir sys .readdir { rx regex } grep prefixWithDir { { dir "/" cat -01 cat } '*0.0 } rep } /glob sys .deff { "\0" cat -01 "\0" cat -01 +rename 0 neq { ??io.rename } rep } /rename sys .deff # 0 -> an array of strings determining argv # 1 -> path to executable { -01 "\0" cat -01 [ ] +execve ??proc.exec } /exec sys .deff # 0 -> a shell command { ==cmd "/bin/sh\0" [ "sh" "-c" cmd ] "\0" |cat '*00.0 [ ] +execve ??proc.exec } /shell sys .deff # 0 -> function to execute in the child # 0 <- scope describing child, available members: # .pid # .wait (will return some status code) # TODO decompose this according to man 2 waitpid # .kill # .in - child stdin # .out - child stdout # .err - child stderr (maybe inject some polling on this one per default) # # Example: # { "wget 'http://drahflow.name/' -O -" sys .shell } sys .spawn _ |dump -01 .out .eachLine .wait -- { =*f +pipe 0 neq { ??proc.spawn.pipe } rep ==readA ==writeA +pipe 0 neq { ??proc.spawn.pipe } rep ==readB ==writeB +pipe 0 neq { ??proc.spawn.pipe } rep ==readC ==writeC +fork _ ==child not { [ writeA readB readC 0 1 2 ] { +close } '*0.0 -- [ readA writeB writeC ] [ 0 1 2 ] { +dup2 } '*00.0 -- f 0 sys .exit } rep child 1 neg eq { ??proc.spawn.fork } { readA +close { ??proc.spawn.close } rep writeB +close { ??proc.spawn.close } rep writeC +close { ??proc.spawn.close } rep child < ==pid { pid 0 +waitpid -- } =*wait { pid -01 +kill -- } =*kill writeA _ ==inFd sys .fdToFile _ .writeonly ==in readB _ ==outFd sys .fdToFile _ .readonly ==out readC _ ==errFd sys .fdToFile _ .readonly ==err > } ? * } /spawn sys .deff > -- # vim: syn=elymas