@effekt-lang/effekt 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +36 -0
- package/bin/effekt +0 -0
- package/bin/effekt.sh +2 -0
- package/libraries/chez/THIRD-PARTY.txt +11 -0
- package/libraries/chez/callcc/datatype.ss +188 -0
- package/libraries/chez/callcc/effekt.ss +31 -0
- package/libraries/chez/callcc/seq.ss +44 -0
- package/libraries/chez/callcc/seq0.ss +69 -0
- package/libraries/chez/callcc/tail.ss +76 -0
- package/libraries/chez/callcc/tail0.ss +89 -0
- package/libraries/chez/common/effekt_primitives.ss +105 -0
- package/libraries/chez/common/immutable/cslist.effekt +37 -0
- package/libraries/chez/common/mutable/dict.effekt +28 -0
- package/libraries/chez/common/text/pregexp.scm +772 -0
- package/libraries/chez/common/text/regex.effekt +31 -0
- package/libraries/chez/lift/effekt.ss +118 -0
- package/libraries/chez/monadic/effekt.ss +84 -0
- package/libraries/chez/monadic/seq0.ss +76 -0
- package/libraries/common/args.effekt +95 -0
- package/libraries/common/array.effekt +225 -0
- package/libraries/common/bench.effekt +60 -0
- package/libraries/common/buffer.effekt +123 -0
- package/libraries/common/bytes.effekt +125 -0
- package/libraries/common/dequeue.effekt +92 -0
- package/libraries/common/effekt.effekt +764 -0
- package/libraries/common/exception.effekt +122 -0
- package/libraries/common/io/console.effekt +66 -0
- package/libraries/common/io/error.effekt +365 -0
- package/libraries/common/io/files.effekt +282 -0
- package/libraries/common/io/network.effekt +105 -0
- package/libraries/common/io/time.effekt +15 -0
- package/libraries/common/io.effekt +158 -0
- package/libraries/common/list.effekt +687 -0
- package/libraries/common/option.effekt +72 -0
- package/libraries/common/process.effekt +10 -0
- package/libraries/common/queue.effekt +140 -0
- package/libraries/common/ref.effekt +63 -0
- package/libraries/common/result.effekt +45 -0
- package/libraries/common/seq.effekt +914 -0
- package/libraries/common/string.effekt +395 -0
- package/libraries/common/test.effekt +98 -0
- package/libraries/js/effekt_builtins.js +57 -0
- package/libraries/js/effekt_runtime.js +385 -0
- package/libraries/js/io.js +143 -0
- package/libraries/js/mutable/map.effekt +31 -0
- package/libraries/js/text/regex.effekt +33 -0
- package/libraries/js/unsafe/cont.effekt +11 -0
- package/libraries/js/web/dom.effekt +45 -0
- package/libraries/llvm/array.c +53 -0
- package/libraries/llvm/buffer.c +286 -0
- package/libraries/llvm/forward-declare-c.ll +43 -0
- package/libraries/llvm/hole.c +11 -0
- package/libraries/llvm/io.c +566 -0
- package/libraries/llvm/io.ll +19 -0
- package/libraries/llvm/main.c +41 -0
- package/libraries/llvm/ref.c +45 -0
- package/libraries/llvm/rts.ll +761 -0
- package/libraries/llvm/sanity.c +16 -0
- package/libraries/llvm/types.c +43 -0
- package/libraries/ml/effekt.sml +65 -0
- package/libraries/ml/internal/mllist.effekt +9 -0
- package/libraries/ml/internal/mloption.effekt +18 -0
- package/libraries/ml/random.effekt +85 -0
- package/libraries/ml/text/regex.effekt +102 -0
- package/licenses/THIRD-PARTY.txt +21 -0
- package/licenses/apache-2.0 - license-2.0.txt +202 -0
- package/licenses/eclipse public license, version 2.0 - epl-2.0.html +61 -0
- package/licenses/kiama-license.txt +373 -0
- package/licenses/kiama-readme.txt +186 -0
- package/licenses/mit license - mit-license.html +1239 -0
- package/licenses/the apache software license, version 2.0 - license-2.0.txt +202 -0
- package/licenses/the bsd license - bsd-license.html +1237 -0
- package/licenses/the mit license - mit.html +1239 -0
- package/package.json +26 -18
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
module exception
|
|
2
|
+
|
|
3
|
+
import effekt
|
|
4
|
+
|
|
5
|
+
// Exceptions
|
|
6
|
+
// ==========
|
|
7
|
+
|
|
8
|
+
interface Exception[E] {
|
|
9
|
+
def raise(exception: E, msg: String): Nothing
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
def raise[A, E](exception: E, msg: String): A / Exception[E] =
|
|
13
|
+
do raise(exception, msg) match {}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Used as a type for `Exception` in functions which expect a non-empty
|
|
17
|
+
* container (e.g. option or list).
|
|
18
|
+
*/
|
|
19
|
+
record MissingValue()
|
|
20
|
+
|
|
21
|
+
def missingValue(): Nothing / Exception[MissingValue] =
|
|
22
|
+
do raise(MissingValue(), "Missing value.")
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Used as a type for `Exception` in functions where an index can be out of bounds.
|
|
26
|
+
*/
|
|
27
|
+
record OutOfBounds()
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Unexpected runtime exceptions that can be caught.
|
|
31
|
+
*/
|
|
32
|
+
record RuntimeError()
|
|
33
|
+
|
|
34
|
+
def raise[A](msg: String): A / Exception[RuntimeError] =
|
|
35
|
+
do raise(RuntimeError(), msg) match {}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Used as a type for `Exception` in functions which expect the input
|
|
39
|
+
* to be formatted in a specific way.
|
|
40
|
+
*/
|
|
41
|
+
record WrongFormat()
|
|
42
|
+
|
|
43
|
+
def wrongFormat(): Nothing / Exception[WrongFormat] =
|
|
44
|
+
do raise(WrongFormat(), "Wrong format.")
|
|
45
|
+
|
|
46
|
+
def wrongFormat(msg: String): Nothing / Exception[WrongFormat] =
|
|
47
|
+
do raise(WrongFormat(), msg)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* A fatal runtime error that cannot be caught
|
|
52
|
+
*/
|
|
53
|
+
extern io def panic[R](msg: String): R =
|
|
54
|
+
js "(function() { throw ${msg} })()"
|
|
55
|
+
chez "(raise ${msg})"
|
|
56
|
+
ml "raise Fail ${msg}"
|
|
57
|
+
llvm """
|
|
58
|
+
call void @c_io_println_String(%Pos ${msg})
|
|
59
|
+
call void @exit(i32 1)
|
|
60
|
+
ret %Pos zeroinitializer ; Unit
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
// Exception Handlers
|
|
65
|
+
// ==================
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Converts exceptions of (static) type E to an uncatchable panic that aborts the program
|
|
70
|
+
*/
|
|
71
|
+
def panicOn[E, T] { prog: => T / Exception[E] }: T =
|
|
72
|
+
try { prog() } with Exception[E] { def raise(exception: E, msg: String) = panic(msg) }
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Reports exceptions of (static) type E to the console
|
|
76
|
+
*/
|
|
77
|
+
def report[E] { prog: => Unit / Exception[E] }: Unit =
|
|
78
|
+
try { prog() } with Exception[E] { def raise(exception: E, msg: String) = println(msg) }
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Ignores exceptions of (static) type E
|
|
82
|
+
*/
|
|
83
|
+
def ignore[E] { prog: => Unit / Exception[E] }: Unit =
|
|
84
|
+
try { prog() } with Exception[E] { def raise(exception: E, msg: String) = () }
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Use the default value to handle the exception of type E
|
|
88
|
+
*/
|
|
89
|
+
def default[E, T] { default: => T } { prog: => T / Exception[E] }: T =
|
|
90
|
+
try { prog() } with Exception[E] { def raise(exception: E, msg: String) = default() }
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Runs the finalizer and rethrows E
|
|
94
|
+
*/
|
|
95
|
+
def finalize[E, T] { finalizer: => Unit } { prog: => T / Exception[E] }: T / Exception[E] =
|
|
96
|
+
try { val res = prog(); finalizer(); res } with Exception[E] {
|
|
97
|
+
def raise(exception: E, msg: String) = { finalizer(); do raise(exception, msg) }
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* A proxy value to enable partial type applications, such as:
|
|
102
|
+
*
|
|
103
|
+
* ```
|
|
104
|
+
* with on[MissingValue].ignore; ...
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
record on[E]()
|
|
108
|
+
|
|
109
|
+
def ignore[E](proxy: on[E]) { prog: => Unit / Exception[E] }: Unit =
|
|
110
|
+
ignore[E] {prog}
|
|
111
|
+
|
|
112
|
+
def default[E, T](proxy: on[E]) { d: => T } { prog: => T / Exception[E] }: T =
|
|
113
|
+
default[E, T] {d} {prog}
|
|
114
|
+
|
|
115
|
+
def panic[E, T](proxy: on[E]) { prog: => T / Exception[E] }: T =
|
|
116
|
+
panicOn[E, T] {prog}
|
|
117
|
+
|
|
118
|
+
def report[E](proxy: on[E]) { prog: => Unit / Exception[E] }: Unit =
|
|
119
|
+
report[E] {prog}
|
|
120
|
+
|
|
121
|
+
def finalize[E, T](proxy: on[E]) { finalizer: => Unit } { prog: => T / Exception[E] }: T / Exception[E] =
|
|
122
|
+
finalize[E, T] {finalizer} {prog}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
module io/console
|
|
2
|
+
|
|
3
|
+
import io
|
|
4
|
+
import io/time // just for testing
|
|
5
|
+
|
|
6
|
+
extern js """
|
|
7
|
+
const readline = require('node:readline');
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
interface Console {
|
|
11
|
+
def readLine(): String
|
|
12
|
+
def writeLine(content: String): Unit
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
namespace js {
|
|
16
|
+
extern type JSConsole
|
|
17
|
+
extern {io} def newConsole(): JSConsole =
|
|
18
|
+
js """readline.createInterface({
|
|
19
|
+
input: process.stdin,
|
|
20
|
+
output: process.stdout,
|
|
21
|
+
})"""
|
|
22
|
+
extern {io} def close(console: JSConsole): Unit =
|
|
23
|
+
js "${console}.close()"
|
|
24
|
+
|
|
25
|
+
extern {io} def readline(console: JSConsole, k: String => Unit at {io, global}): Unit =
|
|
26
|
+
js "${console}.question('', input => (${k})(input).run())"
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Handler for the console effect, using the Console available in js
|
|
31
|
+
*/
|
|
32
|
+
def console[R] { prog: => R / Console }: R / AsyncIO = {
|
|
33
|
+
val c = js::newConsole()
|
|
34
|
+
try { val res = prog(); js::close(c); res } with Console {
|
|
35
|
+
def readLine() = {
|
|
36
|
+
resume(do performIO[String](box { write =>
|
|
37
|
+
js::readline(c, write)
|
|
38
|
+
}))
|
|
39
|
+
}
|
|
40
|
+
def writeLine(content) = resume(println(content))
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// TODO we could also use stdin and out to implement the Console effect:
|
|
45
|
+
namespace alternative {
|
|
46
|
+
extern {io} def writeStdoutCallback(message: String, k: () => Unit at {io, global}): Unit =
|
|
47
|
+
js "process.stdout.write(${message}, 'utf-8', () => (${k})().run())"
|
|
48
|
+
|
|
49
|
+
def write(message: String): Unit / IO =
|
|
50
|
+
do performIO[Unit](box { write => writeStdoutCallback(message, box { write(()) })})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
namespace examples {
|
|
54
|
+
|
|
55
|
+
def greeter() = {
|
|
56
|
+
do writeLine("What's your name?")
|
|
57
|
+
val name = do readLine();
|
|
58
|
+
do writeLine("Hi " ++ name ++ ", nice to meet you!")
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
def main() = eventloop(box {
|
|
62
|
+
with console;
|
|
63
|
+
greeter()
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
}
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
module io/error
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Errors defined by libuv that can occur in IO operations.
|
|
5
|
+
*
|
|
6
|
+
* In addition to the named error codes, we also assign each error a
|
|
7
|
+
* (positive) integer value that is stable across the different platforms.
|
|
8
|
+
*
|
|
9
|
+
* For the mapping of IOError and code values, see function fromCode.
|
|
10
|
+
*
|
|
11
|
+
* While stable, this integer value is supposed to only be used internally.
|
|
12
|
+
* All user-facing operations should use values of type IOError, instead.
|
|
13
|
+
*
|
|
14
|
+
* see: https://docs.libuv.org/en/v1.x/errors.html
|
|
15
|
+
*/
|
|
16
|
+
type IOError {
|
|
17
|
+
E2BIG();
|
|
18
|
+
EACCES();
|
|
19
|
+
EADDRINUSE();
|
|
20
|
+
EADDRNOTAVAIL();
|
|
21
|
+
EAFNOSUPPORT();
|
|
22
|
+
EAGAIN();
|
|
23
|
+
EAI_ADDRFAMILY();
|
|
24
|
+
EAI_AGAIN();
|
|
25
|
+
EAI_BADFLAGS();
|
|
26
|
+
EAI_BADHINTS();
|
|
27
|
+
EAI_CANCELED();
|
|
28
|
+
EAI_FAIL();
|
|
29
|
+
EAI_FAMILY();
|
|
30
|
+
EAI_MEMORY();
|
|
31
|
+
EAI_NODATA();
|
|
32
|
+
EAI_NONAME();
|
|
33
|
+
EAI_OVERFLOW();
|
|
34
|
+
EAI_PROTOCOL();
|
|
35
|
+
EAI_SERVICE();
|
|
36
|
+
EAI_SOCKTYPE();
|
|
37
|
+
EALREADY();
|
|
38
|
+
EBADF();
|
|
39
|
+
EBUSY();
|
|
40
|
+
ECANCELED();
|
|
41
|
+
ECHARSET();
|
|
42
|
+
ECONNABORTED();
|
|
43
|
+
ECONNREFUSED();
|
|
44
|
+
ECONNRESET();
|
|
45
|
+
EDESTADDRREQ();
|
|
46
|
+
EEXIST();
|
|
47
|
+
EFAULT();
|
|
48
|
+
EFBIG();
|
|
49
|
+
EHOSTUNREACH();
|
|
50
|
+
EINTR();
|
|
51
|
+
EINVAL();
|
|
52
|
+
EIO();
|
|
53
|
+
EISCONN();
|
|
54
|
+
EISDIR();
|
|
55
|
+
ELOOP();
|
|
56
|
+
EMFILE();
|
|
57
|
+
EMSGSIZE();
|
|
58
|
+
ENAMETOOLONG();
|
|
59
|
+
ENETDOWN();
|
|
60
|
+
ENETUNREACH();
|
|
61
|
+
ENFILE();
|
|
62
|
+
ENOBUFS();
|
|
63
|
+
ENODEV();
|
|
64
|
+
ENOENT();
|
|
65
|
+
ENOMEM();
|
|
66
|
+
ENONET();
|
|
67
|
+
ENOPROTOOPT();
|
|
68
|
+
ENOSPC();
|
|
69
|
+
ENOSYS();
|
|
70
|
+
ENOTCONN();
|
|
71
|
+
ENOTDIR();
|
|
72
|
+
ENOTEMPTY();
|
|
73
|
+
ENOTSOCK();
|
|
74
|
+
ENOTSUP();
|
|
75
|
+
EOVERFLOW();
|
|
76
|
+
EPERM();
|
|
77
|
+
EPIPE();
|
|
78
|
+
EPROTO();
|
|
79
|
+
EPROTONOSUPPORT();
|
|
80
|
+
EPROTOTYPE();
|
|
81
|
+
ERANGE();
|
|
82
|
+
EROFS();
|
|
83
|
+
ESHUTDOWN();
|
|
84
|
+
ESPIPE();
|
|
85
|
+
ESRCH();
|
|
86
|
+
ETIMEDOUT();
|
|
87
|
+
ETXTBSY();
|
|
88
|
+
EXDEV();
|
|
89
|
+
UNKNOWN();
|
|
90
|
+
EOF();
|
|
91
|
+
ENXIO();
|
|
92
|
+
EMLINK();
|
|
93
|
+
ENOTTY();
|
|
94
|
+
EFTYPE();
|
|
95
|
+
EILSEQ();
|
|
96
|
+
ESOCKTNOSUPPORT();
|
|
97
|
+
EUNATCH()
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Corresponding error message for a libuv error
|
|
102
|
+
*
|
|
103
|
+
* see: https://docs.libuv.org/en/v1.x/errors.html
|
|
104
|
+
*/
|
|
105
|
+
def message(error: IOError): String = error match {
|
|
106
|
+
case E2BIG() => "argument list too long"
|
|
107
|
+
case EACCES() => "permission denied"
|
|
108
|
+
case EADDRINUSE() => "address already in use"
|
|
109
|
+
case EADDRNOTAVAIL() => "address not available"
|
|
110
|
+
case EAFNOSUPPORT() => "address family not supported"
|
|
111
|
+
case EAGAIN() => "resource temporarily unavailable"
|
|
112
|
+
case EAI_ADDRFAMILY() => "address family not supported"
|
|
113
|
+
case EAI_AGAIN() => "temporary failure"
|
|
114
|
+
case EAI_BADFLAGS() => "bad ai_flags value"
|
|
115
|
+
case EAI_BADHINTS() => "invalid value for hints"
|
|
116
|
+
case EAI_CANCELED() => "request canceled"
|
|
117
|
+
case EAI_FAIL() => "permanent failure"
|
|
118
|
+
case EAI_FAMILY() => "ai_family not supported"
|
|
119
|
+
case EAI_MEMORY() => "out of memory"
|
|
120
|
+
case EAI_NODATA() => "no address"
|
|
121
|
+
case EAI_NONAME() => "unknown node or service"
|
|
122
|
+
case EAI_OVERFLOW() => "argument buffer overflow"
|
|
123
|
+
case EAI_PROTOCOL() => "resolved protocol is unknown"
|
|
124
|
+
case EAI_SERVICE() => "service not available for socket type"
|
|
125
|
+
case EAI_SOCKTYPE() => "socket type not supported"
|
|
126
|
+
case EALREADY() => "connection already in progress"
|
|
127
|
+
case EBADF() => "bad file descriptor"
|
|
128
|
+
case EBUSY() => "resource busy or locked"
|
|
129
|
+
case ECANCELED() => "operation canceled"
|
|
130
|
+
case ECHARSET() => "invalid Unicode character"
|
|
131
|
+
case ECONNABORTED() => "software caused connection abort"
|
|
132
|
+
case ECONNREFUSED() => "connection refused"
|
|
133
|
+
case ECONNRESET() => "connection reset by peer"
|
|
134
|
+
case EDESTADDRREQ() => "destination address required"
|
|
135
|
+
case EEXIST() => "file already exists"
|
|
136
|
+
case EFAULT() => "bad address in system call argument"
|
|
137
|
+
case EFBIG() => "file too large"
|
|
138
|
+
case EHOSTUNREACH() => "host is unreachable"
|
|
139
|
+
case EINTR() => "interrupted system call"
|
|
140
|
+
case EINVAL() => "invalid argument"
|
|
141
|
+
case EIO() => "i/o error"
|
|
142
|
+
case EISCONN() => "socket is already connected"
|
|
143
|
+
case EISDIR() => "illegal operation on a directory"
|
|
144
|
+
case ELOOP() => "too many symbolic links encountered"
|
|
145
|
+
case EMFILE() => "too many open files"
|
|
146
|
+
case EMSGSIZE() => "message too long"
|
|
147
|
+
case ENAMETOOLONG() => "name too long"
|
|
148
|
+
case ENETDOWN() => "network is down"
|
|
149
|
+
case ENETUNREACH() => "network is unreachable"
|
|
150
|
+
case ENFILE() => "file table overflow"
|
|
151
|
+
case ENOBUFS() => "no buffer space available"
|
|
152
|
+
case ENODEV() => "no such device"
|
|
153
|
+
case ENOENT() => "no such file or directory"
|
|
154
|
+
case ENOMEM() => "not enough memory"
|
|
155
|
+
case ENONET() => "machine is not on the network"
|
|
156
|
+
case ENOPROTOOPT() => "protocol not available"
|
|
157
|
+
case ENOSPC() => "no space left on device"
|
|
158
|
+
case ENOSYS() => "function not implemented"
|
|
159
|
+
case ENOTCONN() => "socket is not connected"
|
|
160
|
+
case ENOTDIR() => "not a directory"
|
|
161
|
+
case ENOTEMPTY() => "directory not empty"
|
|
162
|
+
case ENOTSOCK() => "socket operation on non-socket"
|
|
163
|
+
case ENOTSUP() => "operation not supported on socket"
|
|
164
|
+
case EOVERFLOW() => "value too large for defined data type"
|
|
165
|
+
case EPERM() => "operation not permitted"
|
|
166
|
+
case EPIPE() => "broken pipe"
|
|
167
|
+
case EPROTO() => "protocol error"
|
|
168
|
+
case EPROTONOSUPPORT() => "protocol not supported"
|
|
169
|
+
case EPROTOTYPE() => "protocol wrong type for socket"
|
|
170
|
+
case ERANGE() => "result too large"
|
|
171
|
+
case EROFS() => "read-only file system"
|
|
172
|
+
case ESHUTDOWN() => "cannot send after transport endpoint shutdown"
|
|
173
|
+
case ESPIPE() => "invalid seek"
|
|
174
|
+
case ESRCH() => "no such process"
|
|
175
|
+
case ETIMEDOUT() => "connection timed out"
|
|
176
|
+
case ETXTBSY() => "text file is busy"
|
|
177
|
+
case EXDEV() => "cross-device link not permitted"
|
|
178
|
+
case UNKNOWN() => "unknown error"
|
|
179
|
+
case EOF() => "end of file"
|
|
180
|
+
case ENXIO() => "no such device or address"
|
|
181
|
+
case EMLINK() => "too many links"
|
|
182
|
+
case ENOTTY() => "inappropriate ioctl for device"
|
|
183
|
+
case EFTYPE() => "inappropriate file type or format"
|
|
184
|
+
case EILSEQ() => "illegal byte sequence"
|
|
185
|
+
case ESOCKTNOSUPPORT() => "socket type not supported"
|
|
186
|
+
case EUNATCH() => "protocol driver not attached"
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Corresponding name of a libuv error
|
|
191
|
+
*
|
|
192
|
+
* see: https://docs.libuv.org/en/v1.x/errors.html
|
|
193
|
+
*/
|
|
194
|
+
def name(error: IOError): String = error match {
|
|
195
|
+
case E2BIG() => "E2BIG"
|
|
196
|
+
case EACCES() => "EACCES"
|
|
197
|
+
case EADDRINUSE() => "EADDRINUSE"
|
|
198
|
+
case EADDRNOTAVAIL() => "EADDRNOTAVAIL"
|
|
199
|
+
case EAFNOSUPPORT() => "EAFNOSUPPORT"
|
|
200
|
+
case EAGAIN() => "EAGAIN"
|
|
201
|
+
case EAI_ADDRFAMILY() => "EAI_ADDRFAMILY"
|
|
202
|
+
case EAI_AGAIN() => "EAI_AGAIN"
|
|
203
|
+
case EAI_BADFLAGS() => "EAI_BADFLAGS"
|
|
204
|
+
case EAI_BADHINTS() => "EAI_BADHINTS"
|
|
205
|
+
case EAI_CANCELED() => "EAI_CANCELED"
|
|
206
|
+
case EAI_FAIL() => "EAI_FAIL"
|
|
207
|
+
case EAI_FAMILY() => "EAI_FAMILY"
|
|
208
|
+
case EAI_MEMORY() => "EAI_MEMORY"
|
|
209
|
+
case EAI_NODATA() => "EAI_NODATA"
|
|
210
|
+
case EAI_NONAME() => "EAI_NONAME"
|
|
211
|
+
case EAI_OVERFLOW() => "EAI_OVERFLOW"
|
|
212
|
+
case EAI_PROTOCOL() => "EAI_PROTOCOL"
|
|
213
|
+
case EAI_SERVICE() => "EAI_SERVICE"
|
|
214
|
+
case EAI_SOCKTYPE() => "EAI_SOCKTYPE"
|
|
215
|
+
case EALREADY() => "EALREADY"
|
|
216
|
+
case EBADF() => "EBADF"
|
|
217
|
+
case EBUSY() => "EBUSY"
|
|
218
|
+
case ECANCELED() => "ECANCELED"
|
|
219
|
+
case ECHARSET() => "ECHARSET"
|
|
220
|
+
case ECONNABORTED() => "ECONNABORTED"
|
|
221
|
+
case ECONNREFUSED() => "ECONNREFUSED"
|
|
222
|
+
case ECONNRESET() => "ECONNRESET"
|
|
223
|
+
case EDESTADDRREQ() => "EDESTADDRREQ"
|
|
224
|
+
case EEXIST() => "EEXIST"
|
|
225
|
+
case EFAULT() => "EFAULT"
|
|
226
|
+
case EFBIG() => "EFBIG"
|
|
227
|
+
case EHOSTUNREACH() => "EHOSTUNREACH"
|
|
228
|
+
case EINTR() => "EINTR"
|
|
229
|
+
case EINVAL() => "EINVAL"
|
|
230
|
+
case EIO() => "EIO"
|
|
231
|
+
case EISCONN() => "EISCONN"
|
|
232
|
+
case EISDIR() => "EISDIR"
|
|
233
|
+
case ELOOP() => "ELOOP"
|
|
234
|
+
case EMFILE() => "EMFILE"
|
|
235
|
+
case EMSGSIZE() => "EMSGSIZE"
|
|
236
|
+
case ENAMETOOLONG() => "ENAMETOOLONG"
|
|
237
|
+
case ENETDOWN() => "ENETDOWN"
|
|
238
|
+
case ENETUNREACH() => "ENETUNREACH"
|
|
239
|
+
case ENFILE() => "ENFILE"
|
|
240
|
+
case ENOBUFS() => "ENOBUFS"
|
|
241
|
+
case ENODEV() => "ENODEV"
|
|
242
|
+
case ENOENT() => "ENOENT"
|
|
243
|
+
case ENOMEM() => "ENOMEM"
|
|
244
|
+
case ENONET() => "ENONET"
|
|
245
|
+
case ENOPROTOOPT() => "ENOPROTOOPT"
|
|
246
|
+
case ENOSPC() => "ENOSPC"
|
|
247
|
+
case ENOSYS() => "ENOSYS"
|
|
248
|
+
case ENOTCONN() => "ENOTCONN"
|
|
249
|
+
case ENOTDIR() => "ENOTDIR"
|
|
250
|
+
case ENOTEMPTY() => "ENOTEMPTY"
|
|
251
|
+
case ENOTSOCK() => "ENOTSOCK"
|
|
252
|
+
case ENOTSUP() => "ENOTSUP"
|
|
253
|
+
case EOVERFLOW() => "EOVERFLOW"
|
|
254
|
+
case EPERM() => "EPERM"
|
|
255
|
+
case EPIPE() => "EPIPE"
|
|
256
|
+
case EPROTO() => "EPROTO"
|
|
257
|
+
case EPROTONOSUPPORT() => "EPROTONOSUPPORT"
|
|
258
|
+
case EPROTOTYPE() => "EPROTOTYPE"
|
|
259
|
+
case ERANGE() => "ERANGE"
|
|
260
|
+
case EROFS() => "EROFS"
|
|
261
|
+
case ESHUTDOWN() => "ESHUTDOWN"
|
|
262
|
+
case ESPIPE() => "ESPIPE"
|
|
263
|
+
case ESRCH() => "ESRCH"
|
|
264
|
+
case ETIMEDOUT() => "ETIMEDOUT"
|
|
265
|
+
case ETXTBSY() => "ETXTBSY"
|
|
266
|
+
case EXDEV() => "EXDEV"
|
|
267
|
+
case UNKNOWN() => "UNKNOWN"
|
|
268
|
+
case EOF() => "EOF"
|
|
269
|
+
case ENXIO() => "ENXIO"
|
|
270
|
+
case EMLINK() => "EMLINK"
|
|
271
|
+
case ENOTTY() => "ENOTTY"
|
|
272
|
+
case EFTYPE() => "EFTYPE"
|
|
273
|
+
case EILSEQ() => "EILSEQ"
|
|
274
|
+
case ESOCKTNOSUPPORT() => "ESOCKTNOSUPPORT"
|
|
275
|
+
case EUNATCH() => "EUNATCH"
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Translates a integer code value to an IOError.
|
|
280
|
+
*
|
|
281
|
+
* See documentation of type IOError for further information.
|
|
282
|
+
*/
|
|
283
|
+
def fromCode(code: Int): IOError = code match {
|
|
284
|
+
case 1 => EPERM()
|
|
285
|
+
case 2 => ENOENT()
|
|
286
|
+
case 3 => ESRCH()
|
|
287
|
+
case 4 => EINTR()
|
|
288
|
+
case 5 => EIO()
|
|
289
|
+
case 6 => ENXIO()
|
|
290
|
+
case 7 => E2BIG()
|
|
291
|
+
case 9 => EBADF()
|
|
292
|
+
case 11 => EAGAIN()
|
|
293
|
+
case 12 => ENOMEM()
|
|
294
|
+
case 13 => EACCES()
|
|
295
|
+
case 14 => EFAULT()
|
|
296
|
+
case 16 => EBUSY()
|
|
297
|
+
case 17 => EEXIST()
|
|
298
|
+
case 18 => EXDEV()
|
|
299
|
+
case 19 => ENODEV()
|
|
300
|
+
case 20 => ENOTDIR()
|
|
301
|
+
case 21 => EISDIR()
|
|
302
|
+
case 22 => EINVAL()
|
|
303
|
+
case 23 => ENFILE()
|
|
304
|
+
case 24 => EMFILE()
|
|
305
|
+
case 25 => ENOTTY()
|
|
306
|
+
case 26 => ETXTBSY()
|
|
307
|
+
case 27 => EFBIG()
|
|
308
|
+
case 28 => ENOSPC()
|
|
309
|
+
case 29 => ESPIPE()
|
|
310
|
+
case 30 => EROFS()
|
|
311
|
+
case 31 => EMLINK()
|
|
312
|
+
case 32 => EPIPE()
|
|
313
|
+
case 34 => ERANGE()
|
|
314
|
+
case 36 => ENAMETOOLONG()
|
|
315
|
+
case 40 => ELOOP()
|
|
316
|
+
case 75 => EOVERFLOW()
|
|
317
|
+
case 79 => EFTYPE()
|
|
318
|
+
case 84 => EILSEQ()
|
|
319
|
+
case 88 => ENOTSOCK()
|
|
320
|
+
case 89 => EDESTADDRREQ()
|
|
321
|
+
case 90 => EMSGSIZE()
|
|
322
|
+
case 91 => EPROTOTYPE()
|
|
323
|
+
case 92 => ENOPROTOOPT()
|
|
324
|
+
case 93 => EPROTONOSUPPORT()
|
|
325
|
+
case 94 => ESOCKTNOSUPPORT()
|
|
326
|
+
case 95 => ENOTSUP()
|
|
327
|
+
case 97 => EAFNOSUPPORT()
|
|
328
|
+
case 98 => EADDRINUSE()
|
|
329
|
+
case 99 => EADDRNOTAVAIL()
|
|
330
|
+
case 100 => ENETDOWN()
|
|
331
|
+
case 101 => ENETUNREACH()
|
|
332
|
+
case 103 => ECONNABORTED()
|
|
333
|
+
case 104 => ECONNRESET()
|
|
334
|
+
case 105 => ENOBUFS()
|
|
335
|
+
case 106 => EISCONN()
|
|
336
|
+
case 107 => ENOTCONN()
|
|
337
|
+
case 110 => ETIMEDOUT()
|
|
338
|
+
case 111 => ECONNREFUSED()
|
|
339
|
+
case 113 => EHOSTUNREACH()
|
|
340
|
+
case 114 => EALREADY()
|
|
341
|
+
case 125 => ECANCELED()
|
|
342
|
+
|
|
343
|
+
case 200 => EAI_ADDRFAMILY()
|
|
344
|
+
case 201 => EAI_AGAIN()
|
|
345
|
+
case 202 => EAI_BADFLAGS()
|
|
346
|
+
case 203 => EAI_BADHINTS()
|
|
347
|
+
case 204 => EAI_CANCELED()
|
|
348
|
+
case 205 => EAI_FAIL()
|
|
349
|
+
case 206 => EAI_FAMILY()
|
|
350
|
+
case 207 => EAI_MEMORY()
|
|
351
|
+
case 208 => EAI_NODATA()
|
|
352
|
+
case 209 => EAI_NONAME()
|
|
353
|
+
case 210 => EAI_OVERFLOW()
|
|
354
|
+
case 211 => EAI_PROTOCOL()
|
|
355
|
+
case 212 => EAI_SERVICE()
|
|
356
|
+
case 213 => EAI_SOCKTYPE()
|
|
357
|
+
case 215 => ECHARSET()
|
|
358
|
+
case 216 => ENONET()
|
|
359
|
+
case 217 => UNKNOWN()
|
|
360
|
+
case 218 => EOF()
|
|
361
|
+
case 219 => EUNATCH()
|
|
362
|
+
case 220 => ESHUTDOWN()
|
|
363
|
+
|
|
364
|
+
case _ => panic("Not a valid error code: " ++ show(code))
|
|
365
|
+
}
|