1///|
2pub extern "c" fn disable_stdio_inheritance() = "moonbit_uv_disable_stdio_inheritance"
3
4///|
5type Process
6
7///|
8pub impl trait ToHandle {
to_handle(Self) -> Handle
of_handle(Handle) -> Self
close(Self, (Self) -> Unit) -> Unit
is_closing(Self) -> Bool
}
ToHandle for type Process
Process with to_handle(self) = "%identity"
9
10///|
11pub impl trait ToHandle {
to_handle(Self) -> Handle
of_handle(Handle) -> Self
close(Self, (Self) -> Unit) -> Unit
is_closing(Self) -> Bool
}
ToHandle for type Process
Process with of_handle(handle) = "%identity"
12
13///|
14extern "c" fn uv_process_get_pid(process : type Process
Process) -> Int
Int = "moonbit_uv_process_get_pid"
15
16///|
17pub fn type Process
Process::(self : Process) -> Int
pid(Process
self : type Process
Process) -> Int
Int {
18 return (process : Process) -> Int
uv_process_get_pid(Process
self)
19}
20
21///|
22extern "c" fn uv_process_make() -> type Process
Process = "moonbit_uv_process_make"
23
24///|
25type ProcessOptions
26
27///|
28priv enum ProcessFlag {
29 ProcessFlag
SetUID = 1
30 ProcessFlag
SetGID = 2
31 ProcessFlag
WindowsVerbatimArguments = 4
32 ProcessFlag
Detached = 8
33 ProcessFlag
WindowsHide = 16
34 ProcessFlag
WindowsHideConsole = 32
35 ProcessFlag
WindowsHideGui = 64
36 ProcessFlag
WindowsFilePathExactName = 128
37}
38
39///|
40fn enum ProcessFlag {
SetUID
SetGID
WindowsVerbatimArguments
Detached
WindowsHide
WindowsHideConsole
WindowsHideGui
WindowsFilePathExactName
}
ProcessFlag::to_int(self : enum ProcessFlag {
SetUID
SetGID
WindowsVerbatimArguments
Detached
WindowsHide
WindowsHideConsole
WindowsHideGui
WindowsFilePathExactName
}
ProcessFlag) -> UInt
UInt = "%identity"
41
42///|
43extern "c" fn uv_process_options_make() -> type ProcessOptions
ProcessOptions = "moonbit_uv_process_options_make"
44
45///|
46extern "c" fn uv_process_options_set_exit_cb(
47 process_options : type ProcessOptions
ProcessOptions,
48 exit_cb : (type Process
Process, Int64
Int64, Int
Int) -> Unit
Unit
49) = "moonbit_uv_process_options_set_exit_cb"
50
51///|
52extern "c" fn uv_process_options_set_file(
53 process_options : type ProcessOptions
ProcessOptions,
54 file : Bytes
Bytes
55) = "moonbit_uv_process_options_set_file"
56
57///|
58extern "c" fn uv_process_options_set_args(
59 process_options : type ProcessOptions
ProcessOptions,
60 args : type FixedArray[A]
FixedArray[Bytes
Bytes?]
61) = "moonbit_uv_process_options_set_args"
62
63///|
64extern "c" fn uv_process_options_set_env(
65 process_options : type ProcessOptions
ProcessOptions,
66 env : type FixedArray[A]
FixedArray[Bytes
Bytes?]
67) = "moonbit_uv_process_options_set_env"
68
69///|
70extern "c" fn uv_process_options_set_cwd(
71 process_options : type ProcessOptions
ProcessOptions,
72 cwd : Bytes
Bytes
73) = "moonbit_uv_process_options_set_cwd"
74
75///|
76extern "c" fn uv_process_options_set_flags(
77 process_options : type ProcessOptions
ProcessOptions,
78 flags : UInt
UInt
79) = "moonbit_uv_process_options_set_flags"
80
81///|
82extern "c" fn uv_process_options_set_stdio(
83 process_options : type ProcessOptions
ProcessOptions,
84 stdio : type FixedArray[A]
FixedArray[type StdioContainer Bytes
StdioContainer]
85) = "moonbit_uv_process_options_set_stdio"
86
87///|
88extern "c" fn uv_process_options_set_uid(
89 process_options : type ProcessOptions
ProcessOptions,
90 uid : type Uid Int
Uid
91) = "moonbit_uv_process_options_set_uid"
92
93///|
94extern "c" fn uv_process_options_set_gid(
95 process_options : type ProcessOptions
ProcessOptions,
96 gid : type Gid Int
Gid
97) = "moonbit_uv_process_options_set_gid"
98
99///|
100pub fn[Ntbs : trait ToNtbs {
to_ntbs(Self) -> Bytes
}
ToNtbs] type ProcessOptions
ProcessOptions::(file : Ntbs, args : Array[@string.StringView], env? : Array[@string.StringView], cwd? : @string.StringView, stdio? : Array[StdioContainer], uid? : Uid, gid? : Gid, exit_cb : (Process, Int64, Int) -> Unit) -> ProcessOptions
new(
101 Ntbs
file : type parameter Ntbs
Ntbs,
102 Array[@string.StringView]
args : type Array[T]
An Array is a collection of values that supports random access and can
grow in size.
Array[type @string.StringView
A @string.View represents a view of a String that maintains proper Unicode
character boundaries. It allows safe access to a substring while handling
multi-byte characters correctly.
@string.View],
103 Array[@string.StringView]?
env? : type Array[T]
An Array is a collection of values that supports random access and can
grow in size.
Array[type @string.StringView
A @string.View represents a view of a String that maintains proper Unicode
character boundaries. It allows safe access to a substring while handling
multi-byte characters correctly.
@string.View],
104 @string.StringView?
cwd? : type @string.StringView
A @string.View represents a view of a String that maintains proper Unicode
character boundaries. It allows safe access to a substring while handling
multi-byte characters correctly.
@string.View,
105 Array[StdioContainer]?
stdio? : type Array[T]
An Array is a collection of values that supports random access and can
grow in size.
Array[type StdioContainer Bytes
StdioContainer],
106 Uid?
uid? : type Uid Int
Uid,
107 Gid?
gid? : type Gid Int
Gid,
108 (Process, Int64, Int) -> Unit
exit_cb : (type Process
Process, Int64
Int64, Int
Int) -> Unit
Unit
109) -> type ProcessOptions
ProcessOptions {
110 let mut UInt
flags = 0U
111 let ProcessOptions
options = () -> ProcessOptions
uv_process_options_make()
112 (process_options : ProcessOptions, exit_cb : (Process, Int64, Int) -> Unit) -> Unit
uv_process_options_set_exit_cb(ProcessOptions
options, (Process, Int64, Int) -> Unit
exit_cb)
113 let Bytes
file = Ntbs
file.(Ntbs) -> Bytes
to_ntbs()
114 (process_options : ProcessOptions, file : Bytes) -> Unit
uv_process_options_set_file(ProcessOptions
options, Bytes
file)
115 let FixedArray[Bytes?]
args = type FixedArray[A]
FixedArray::(length : Int, value : (Int) -> Bytes?) -> FixedArray[Bytes?]
Creates a new fixed-size array of the specified length, where each element is
initialized using a function that maps indices to values.
Parameters:
length : The length of the array to create. If length is less than or
equal to 0, returns an empty array.
initializer : A function that takes an index (from 0 to length - 1) and
returns a value of type T for that position.
Returns a new fixed array containing the values produced by applying the
initializer function to each index.
Example:
test "FixedArray::makei" {
let arr = FixedArray::makei(3, fn(i) { i * 2 })
inspect(arr, content="[0, 2, 4]")
}
makei(Array[@string.StringView]
args.(self : Array[@string.StringView]) -> Int
Returns the number of elements in the array.
Parameters:
array : The array whose length is to be determined.
Returns the number of elements in the array as an integer.
Example:
test "Array::length" {
let arr = [1, 2, 3]
inspect(arr.length(), content="3")
let empty : Array[Int] = []
inspect(empty.length(), content="0")
}
length() (self : Int, other : Int) -> Int
Adds two 32-bit signed integers. Performs two's complement arithmetic, which
means the operation will wrap around if the result exceeds the range of a
32-bit integer.
Parameters:
self : The first integer operand.
other : The second integer operand.
Returns a new integer that is the sum of the two operands. If the
mathematical sum exceeds the range of a 32-bit integer (-2,147,483,648 to
2,147,483,647), the result wraps around according to two's complement rules.
Example:
test "Int::op_add" {
inspect(42 + 1, content="43")
inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
}
+ 1, fn(Int
i) {
116 if Int
i (self : Int, other : Int) -> Bool
Compares two integers for equality.
Parameters:
self : The first integer to compare.
other : The second integer to compare.
Returns true if both integers have the same value, false otherwise.
Example:
test "Int::op_equal" {
inspect(42 == 42, content="true")
inspect(42 == -42, content="false")
}
== Array[@string.StringView]
args.(self : Array[@string.StringView]) -> Int
Returns the number of elements in the array.
Parameters:
array : The array whose length is to be determined.
Returns the number of elements in the array as an integer.
Example:
test "Array::length" {
let arr = [1, 2, 3]
inspect(arr.length(), content="3")
let empty : Array[Int] = []
inspect(empty.length(), content="0")
}
length() {
117 return Bytes?
None
118 } else {
119 return (Bytes) -> Bytes?
Some(Array[@string.StringView]
args(Array[@string.StringView], Int) -> @string.StringView
Retrieves an element from the array at the specified index.
Parameters:
array : The array to get the element from.
index : The position in the array from which to retrieve the element.
Returns the element at the specified index.
Throws a panic if the index is negative or greater than or equal to the
length of the array.
Example:
test "Array::op_get" {
let arr = [1, 2, 3]
inspect(arr[1], content="2")
}
test "panic Array::op_get/out_of_bounds" {
let arr = [1, 2, 3]
ignore(arr[3]) // Index out of bounds
}
[i].(self : @string.StringView) -> Bytes
to_ntbs())
120 }
121 })
122 (process_options : ProcessOptions, args : FixedArray[Bytes?]) -> Unit
uv_process_options_set_args(ProcessOptions
options, FixedArray[Bytes?]
args)
123 if Array[@string.StringView]?
env is (Array[@string.StringView]) -> Array[@string.StringView]?
Some(Array[@string.StringView]
env) {
124 let FixedArray[Bytes?]
env = type FixedArray[A]
FixedArray::(length : Int, value : (Int) -> Bytes?) -> FixedArray[Bytes?]
Creates a new fixed-size array of the specified length, where each element is
initialized using a function that maps indices to values.
Parameters:
length : The length of the array to create. If length is less than or
equal to 0, returns an empty array.
initializer : A function that takes an index (from 0 to length - 1) and
returns a value of type T for that position.
Returns a new fixed array containing the values produced by applying the
initializer function to each index.
Example:
test "FixedArray::makei" {
let arr = FixedArray::makei(3, fn(i) { i * 2 })
inspect(arr, content="[0, 2, 4]")
}
makei(Array[@string.StringView]
env.(self : Array[@string.StringView]) -> Int
Returns the number of elements in the array.
Parameters:
array : The array whose length is to be determined.
Returns the number of elements in the array as an integer.
Example:
test "Array::length" {
let arr = [1, 2, 3]
inspect(arr.length(), content="3")
let empty : Array[Int] = []
inspect(empty.length(), content="0")
}
length() (self : Int, other : Int) -> Int
Adds two 32-bit signed integers. Performs two's complement arithmetic, which
means the operation will wrap around if the result exceeds the range of a
32-bit integer.
Parameters:
self : The first integer operand.
other : The second integer operand.
Returns a new integer that is the sum of the two operands. If the
mathematical sum exceeds the range of a 32-bit integer (-2,147,483,648 to
2,147,483,647), the result wraps around according to two's complement rules.
Example:
test "Int::op_add" {
inspect(42 + 1, content="43")
inspect(2147483647 + 1, content="-2147483648") // Overflow wraps around to minimum value
}
+ 1, fn(Int
i) {
125 if Int
i (self : Int, other : Int) -> Bool
Compares two integers for equality.
Parameters:
self : The first integer to compare.
other : The second integer to compare.
Returns true if both integers have the same value, false otherwise.
Example:
test "Int::op_equal" {
inspect(42 == 42, content="true")
inspect(42 == -42, content="false")
}
== Array[@string.StringView]
env.(self : Array[@string.StringView]) -> Int
Returns the number of elements in the array.
Parameters:
array : The array whose length is to be determined.
Returns the number of elements in the array as an integer.
Example:
test "Array::length" {
let arr = [1, 2, 3]
inspect(arr.length(), content="3")
let empty : Array[Int] = []
inspect(empty.length(), content="0")
}
length() {
126 return Bytes?
None
127 } else {
128 return (Bytes) -> Bytes?
Some(Array[@string.StringView]
env(Array[@string.StringView], Int) -> @string.StringView
Retrieves an element from the array at the specified index.
Parameters:
array : The array to get the element from.
index : The position in the array from which to retrieve the element.
Returns the element at the specified index.
Throws a panic if the index is negative or greater than or equal to the
length of the array.
Example:
test "Array::op_get" {
let arr = [1, 2, 3]
inspect(arr[1], content="2")
}
test "panic Array::op_get/out_of_bounds" {
let arr = [1, 2, 3]
ignore(arr[3]) // Index out of bounds
}
[i].(self : @string.StringView) -> Bytes
to_ntbs())
129 }
130 })
131 (process_options : ProcessOptions, env : FixedArray[Bytes?]) -> Unit
uv_process_options_set_env(ProcessOptions
options, FixedArray[Bytes?]
env)
132 }
133 if @string.StringView?
cwd is (@string.StringView) -> @string.StringView?
Some(@string.StringView
cwd) {
134 let Bytes
cwd = @string.StringView
cwd.(self : @string.StringView) -> Bytes
to_ntbs()
135 (process_options : ProcessOptions, cwd : Bytes) -> Unit
uv_process_options_set_cwd(ProcessOptions
options, Bytes
cwd)
136 }
137 if Array[StdioContainer]?
stdio is (Array[StdioContainer]) -> Array[StdioContainer]?
Some(Array[StdioContainer]
stdio) {
138 let FixedArray[StdioContainer]
stdio = type FixedArray[A]
FixedArray::(length : Int, value : (Int) -> StdioContainer) -> FixedArray[StdioContainer]
Creates a new fixed-size array of the specified length, where each element is
initialized using a function that maps indices to values.
Parameters:
length : The length of the array to create. If length is less than or
equal to 0, returns an empty array.
initializer : A function that takes an index (from 0 to length - 1) and
returns a value of type T for that position.
Returns a new fixed array containing the values produced by applying the
initializer function to each index.
Example:
test "FixedArray::makei" {
let arr = FixedArray::makei(3, fn(i) { i * 2 })
inspect(arr, content="[0, 2, 4]")
}
makei(Array[StdioContainer]
stdio.(self : Array[StdioContainer]) -> Int
Returns the number of elements in the array.
Parameters:
array : The array whose length is to be determined.
Returns the number of elements in the array as an integer.
Example:
test "Array::length" {
let arr = [1, 2, 3]
inspect(arr.length(), content="3")
let empty : Array[Int] = []
inspect(empty.length(), content="0")
}
length(), fn(Int
i) { return Array[StdioContainer]
stdio(Array[StdioContainer], Int) -> StdioContainer
Retrieves an element from the array at the specified index.
Parameters:
array : The array to get the element from.
index : The position in the array from which to retrieve the element.
Returns the element at the specified index.
Throws a panic if the index is negative or greater than or equal to the
length of the array.
Example:
test "Array::op_get" {
let arr = [1, 2, 3]
inspect(arr[1], content="2")
}
test "panic Array::op_get/out_of_bounds" {
let arr = [1, 2, 3]
ignore(arr[3]) // Index out of bounds
}
[i] })
139 (process_options : ProcessOptions, stdio : FixedArray[StdioContainer]) -> Unit
uv_process_options_set_stdio(ProcessOptions
options, FixedArray[StdioContainer]
stdio)
140 }
141 if Uid?
uid is (Uid) -> Uid?
Some(Uid
uid) {
142 UInt
flags = UInt
flags (UInt, UInt) -> UInt
| ProcessFlag
SetUID.(self : ProcessFlag) -> UInt
to_int()
143 (process_options : ProcessOptions, uid : Uid) -> Unit
uv_process_options_set_uid(ProcessOptions
options, Uid
uid)
144 }
145 if Gid?
gid is (Gid) -> Gid?
Some(Gid
gid) {
146 UInt
flags = UInt
flags (UInt, UInt) -> UInt
| ProcessFlag
SetGID.(self : ProcessFlag) -> UInt
to_int()
147 (process_options : ProcessOptions, gid : Gid) -> Unit
uv_process_options_set_gid(ProcessOptions
options, Gid
gid)
148 }
149 (process_options : ProcessOptions, flags : UInt) -> Unit
uv_process_options_set_flags(ProcessOptions
options, UInt
flags)
150 return ProcessOptions
options
151}
152
153///|
154type StdioContainer Bytes
Bytes
155
156///|
157pub extern "c" fn type StdioContainer Bytes
StdioContainer::ignore() -> type StdioContainer Bytes
StdioContainer = "moonbit_uv_stdio_container_ignore"
158
159///|
160extern "c" fn uv_stdio_container_create_pipe(
161 stream : type Stream
Stream,
162 readable~ : Bool
Bool = false,
163 writable~ : Bool
Bool = false,
164 non_block~ : Bool
Bool = false
165) -> type StdioContainer Bytes
StdioContainer = "moonbit_uv_stdio_container_create_pipe"
166
167///|
168pub fn[Stream : trait ToStream {
to_stream(Self) -> Stream
of_stream(Stream) -> Self
read_start(Self, (Self, Int) -> @bytes.View, (Self, Int, @bytes.View) -> Unit, (Self, Errno) -> Unit) -> Unit!Errno
read_stop(Self) -> Unit!Errno
write(Self, Array[@bytes.View], (Write) -> Unit, (Write, Errno) -> Unit) -> Unit!Errno
listen(Self, Int, (Self) -> Unit, (Self, Errno) -> Unit) -> Unit!Errno
is_readable(Self) -> Bool
is_writable(Self) -> Bool
shutdown(Self, (Shutdown) -> Unit, (Shutdown, Errno) -> Unit) -> Unit!Errno
}
ToStream] type StdioContainer Bytes
StdioContainer::(stream : Stream, readable~ : Bool = .., writable~ : Bool = .., non_block~ : Bool = ..) -> StdioContainer
create_pipe(
169 Stream
stream : type parameter Stream
Stream,
170 Bool
readable~ : Bool
Bool = false,
171 Bool
writable~ : Bool
Bool = false,
172 Bool
non_block~ : Bool
Bool = false
173) -> type StdioContainer Bytes
StdioContainer {
174 return (stream : Stream, readable~ : Bool, writable~ : Bool, non_block~ : Bool) -> StdioContainer
uv_stdio_container_create_pipe(
175 Stream
stream.(Stream) -> Stream
to_stream(),
176 Bool
readable~,
177 Bool
writable~,
178 Bool
non_block~,
179 )
180}
181
182///|
183extern "c" fn uv_stdio_container_inherit_fd(fd : Int
Int) -> type StdioContainer Bytes
StdioContainer = "moonbit_uv_stdio_container_inherit_fd"
184
185///|
186pub fn type StdioContainer Bytes
StdioContainer::(file : File) -> StdioContainer
inherit_file(File
file : type File Int
File) -> type StdioContainer Bytes
StdioContainer {
187 return (fd : Int) -> StdioContainer
uv_stdio_container_inherit_fd(File
file.Int
_)
188}
189
190///|
191pub extern "c" fn type StdioContainer Bytes
StdioContainer::inherit_stream(
192 stream : type Stream
Stream
193) -> type StdioContainer Bytes
StdioContainer = "moonbit_uv_stdio_container_inherit_stream"
194
195///|
196type Uid Int
Int
197
198///|
199type Gid Int
Int
200
201///|
202extern "c" fn uv_spawn(
203 uv : type Loop Bytes
Loop,
204 process : type Process
Process,
205 options : type ProcessOptions
ProcessOptions
206) -> Int
Int = "moonbit_uv_spawn"
207
208///|
209pub fn (self : Loop, options : ProcessOptions) -> Process!Errno
spawn(Loop
self : type Loop Bytes
Loop, ProcessOptions
options : type ProcessOptions
ProcessOptions) -> type Process
Process!type! Errno Status
Errno {
210 let Process
process = () -> Process
uv_process_make()
211 let Int
status = (uv : Loop, process : Process, options : ProcessOptions) -> Int
uv_spawn(Loop
self, Process
process, ProcessOptions
options)
212 if Int
status (self_ : Int, other : Int) -> Bool
< 0 {
213 raise type! Errno Status
Errno::(errno : Int) -> Errno
of_int(Int
status)
214 }
215 return Process
process
216}
217
218///|
219extern "c" fn uv_process_kill(process : type Process
Process, signum : Int
Int) -> Int
Int = "moonbit_uv_process_kill"
220
221///|
222pub fn type Process
Process::(self : Process, signum : Signum) -> Unit!Errno
kill(Process
self : type Process
Process, Signum
signum : type Signum Int
Signum) -> Unit
Unit!type! Errno Status
Errno {
223 let Int
status = (process : Process, signum : Int) -> Int
uv_process_kill(Process
self, Signum
signum.Int
_)
224 if Int
status (self_ : Int, other : Int) -> Bool
< 0 {
225 raise type! Errno Status
Errno::(errno : Int) -> Errno
of_int(Int
status)
226 }
227}
228