Simon Janssen pushed to branch SimonJ at Stefan / Typer
Commits: b0bb526c by JanssenSimon at 2022-08-26T11:56:51-04:00 Adds final crucial unix commands
- - - - -
3 changed files:
- btl/builtins.typer - btl/unix.typer - src/tunix.ml
Changes:
===================================== btl/builtins.typer ===================================== @@ -325,16 +325,19 @@ unix = load "btl/unix.typer"; %%constr = datacons (decltype unix) cons; %%Elab_nth-arg "constr" n ctx; %%% mais il faut un ctx
-File_unlink = unix.File_unlink; -File_link = unix.File_link; -File_symlink = unix.File_symlink; -File_rename = unix.File_rename; -File_stdin = unix.File_stdin; -File_stderr = unix.File_stderr; -Sys_getcwd = unix.Sys_getcwd; -Proc_fork = unix.Proc_fork; -Proc_execvp = unix.Proc_execvp; -Proc_wait = unix.Proc_wait; +File_unlink = unix.File_unlink; +File_link = unix.File_link; +File_symlink = unix.File_symlink; +File_rename = unix.File_rename; +File_stdin = unix.File_stdin; +File_stderr = unix.File_stderr; +Sys_getcwd = unix.Sys_getcwd; +Proc_fork = unix.Proc_fork; +Proc_execvp = unix.Proc_execvp; +Proc_wait = unix.Proc_wait; +Proc_kill = unix.Proc_kill; +File_truncate = unix.File_truncate; +File_readlink = unix.File_readlink;
%% %% Ref (modifiable value)
===================================== btl/unix.typer ===================================== @@ -1,15 +1,18 @@ %%% unix.typer --- Unix api for typer
-File_unlink = Built-in "File.unlink" : String -> IO Unit; -File_link = Built-in "File.link" : String -> String -> IO Unit; -File_symlink = Built-in "File.symlink" : String -> String -> IO Unit; -File_rename = Built-in "File.rename" : String -> String -> IO Unit; -Proc_fork = Built-in "Proc.fork" : Unit -> Int; -Proc_execvp = Built-in "Proc.execvp" : List String -> IO Unit; +File_unlink = Built-in "File.unlink" : String -> IO Unit; +File_link = Built-in "File.link" : String -> String -> IO Unit; +File_symlink = Built-in "File.symlink" : String -> String -> IO Unit; +File_readlink = Built-in "File.readlink" : String -> IO String; +File_rename = Built-in "File.rename" : String -> String -> IO Unit; +File_truncate = Built-in "File.truncate" : String -> Int -> IO Unit; +Proc_fork = Built-in "Proc.fork" : Unit -> IO Int; +Proc_execvp = Built-in "Proc.execvp" : List String -> IO Unit; +Proc_kill = Built-in "Proc.kill" : Int -> Int -> IO Unit;
File_stdin = Built-in "File.stdin" : Unit -> FileHandle; File_stderr = Built-in "File.stderr" : Unit -> FileHandle; Sys_getcwd = Built-in "Sys.getcwd" : Unit -> IO String; -Proc_wait = Built-in "Proc.wait" : Unit -> Int; +Proc_wait = Built-in "Proc.wait" : Unit -> IO Int;
===================================== src/tunix.ml ===================================== @@ -62,11 +62,20 @@ let file_symlink loc _depth args_val = match args_val with -> Vcommand (fun () -> Unix.symlink f1 f2; tunit) | _ -> error loc "File.symlink expects 2 String arguments (file paths)."
+let file_readlink loc _depth args_val = match args_val with + | [Vstring path] -> Vstring (Unix.readlink path) + | _ -> error loc "File.symlink expects 2 String arguments (file paths)." + let file_rename loc _depth args_val = match args_val with | [Vstring f1; Vstring f2] -> Vcommand (fun () -> Sys.rename f1 f2; tunit) | _ -> error loc "File.rename expects 2 String arguments (file paths)."
+let file_truncate loc _depth args_val = match args_val with + | [Vstring file; Vint size] + -> Vcommand (fun () -> Unix.truncate file size; tunit) + | _ -> error loc "File.rename expects 2 arguments (String file path and Int size)." + let proc_fork loc _depth args_val = match args_val with | [_v] -> Vint (Unix.fork ()) | _ -> error loc "Unix.fork takes a Unit as argument" @@ -91,13 +100,20 @@ let proc_execvp loc _depth args_val = match args_val with | _ -> error loc "Proc.execvp expects a list of >String arguments<.") | _ -> error loc "Proc.execvp expects a >list< of String arguments."
+let proc_kill loc _depth args_val = match args_val with + | [Vint pid; Vint signal] -> Vcommand (fun () -> Unix.kill pid signal; tunit) + | _ -> error loc "Unix.kill takes 2 Ints as arguments" + let builtin_functions = [ ("File.unlink" , file_unlink,1); ("File.link" , file_link,2); ("File.symlink" , file_symlink,2); + ("File.readlink" , file_readlink,1); ("File.rename" , file_rename,2); + ("File.truncate" , file_truncate,2); ("Proc.fork" , proc_fork,1); ("Proc.execvp" , proc_execvp,1); + ("Proc.kill" , proc_kill,2); ]
let builtin_constants = [
View it on GitLab: https://gitlab.com/monnier/typer/-/commit/b0bb526c20f3c835741e2ed344319ab0c5...