forked from JuliaLang/julia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase.jl
153 lines (124 loc) · 3.89 KB
/
base.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# This file is a part of Julia. License is MIT: http://julialang.org/license
"""
SystemError(prefix::AbstractString, [errno::Int32])
A system call failed with an error code (in the `errno` global variable).
"""
mutable struct SystemError <: Exception
prefix::AbstractString
errnum::Int32
extrainfo
SystemError(p::AbstractString, e::Integer, extrainfo) = new(p, e, extrainfo)
SystemError(p::AbstractString, e::Integer) = new(p, e, nothing)
SystemError(p::AbstractString) = new(p, Libc.errno())
end
"""
ParseError(msg)
The expression passed to the `parse` function could not be interpreted as a valid Julia
expression.
"""
mutable struct ParseError <: Exception
msg::AbstractString
end
"""
ArgumentError(msg)
The parameters to a function call do not match a valid signature. Argument `msg` is a
descriptive error string.
"""
mutable struct ArgumentError <: Exception
msg::AbstractString
end
"""
KeyError(key)
An indexing operation into an `Associative` (`Dict`) or `Set` like object tried to access or
delete a non-existent element.
"""
mutable struct KeyError <: Exception
key
end
"""
MethodError(f, args)
A method with the required type signature does not exist in the given generic function.
Alternatively, there is no unique most-specific method.
"""
mutable struct MethodError <: Exception
f
args
world::UInt
MethodError(f::ANY, args::ANY, world::UInt) = new(f, args, world)
end
MethodError(f::ANY, args::ANY) = MethodError(f, args, typemax(UInt))
"""
EOFError()
No more data was available to read from a file or stream.
"""
mutable struct EOFError <: Exception end
"""
DimensionMismatch([msg])
The objects called do not have matching dimensionality. Optional argument `msg` is a
descriptive error string.
"""
mutable struct DimensionMismatch <: Exception
msg::AbstractString
end
DimensionMismatch() = DimensionMismatch("")
"""
AssertionError([msg])
The asserted condition did not evaluate to `true`.
Optional argument `msg` is a descriptive error string.
"""
mutable struct AssertionError <: Exception
msg::AbstractString
AssertionError() = new("")
AssertionError(msg) = new(msg)
end
#Generic wrapping of arbitrary exceptions
#Subtypes should put the exception in an 'error' field
abstract type WrappedException <: Exception end
"""
LoadError(file::AbstractString, line::Int, error)
An error occurred while `include`ing, `require`ing, or `using` a file. The error specifics
should be available in the `.error` field.
"""
mutable struct LoadError <: WrappedException
file::AbstractString
line::Int
error
end
"""
InitError(mod::Symbol, error)
An error occurred when running a module's `__init__` function. The actual error thrown is
available in the `.error` field.
"""
mutable struct InitError <: WrappedException
mod::Symbol
error
end
ccall(:jl_get_system_hooks, Void, ())
==(w::WeakRef, v::WeakRef) = isequal(w.value, v.value)
==(w::WeakRef, v) = isequal(w.value, v)
==(w, v::WeakRef) = isequal(w, v.value)
function finalizer(o::ANY, f::ANY)
if isimmutable(o)
error("objects of type ", typeof(o), " cannot be finalized")
end
ccall(:jl_gc_add_finalizer_th, Void, (Ptr{Void}, Any, Any),
Core.getptls(), o, f)
end
function finalizer{T}(o::T, f::Ptr{Void})
@_inline_meta
if isimmutable(T)
error("objects of type ", T, " cannot be finalized")
end
ccall(:jl_gc_add_ptr_finalizer, Void, (Ptr{Void}, Any, Ptr{Void}),
Core.getptls(), o, f)
end
finalize(o::ANY) = ccall(:jl_finalize_th, Void, (Ptr{Void}, Any,),
Core.getptls(), o)
gc(full::Bool=true) = ccall(:jl_gc_collect, Void, (Int32,), full)
gc_enable(on::Bool) = ccall(:jl_gc_enable, Int32, (Int32,), on) != 0
struct Nullable{T}
hasvalue::Bool
value::T
Nullable{T}() where {T} = new(false)
Nullable{T}(value::T, hasvalue::Bool=true) where {T} = new(hasvalue, value)
end