-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patherror.go
More file actions
112 lines (95 loc) · 3.44 KB
/
error.go
File metadata and controls
112 lines (95 loc) · 3.44 KB
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
// This Source Code Form is subject to the terms of the Mozilla Public License,
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
// obtain one at http://mozilla.org/MPL/2.0/.
package core
var DefaultHandler = NewFunction(NewSymbol("DEFAULT-HANDLER"), func(e Environment, c Instance) (Instance, Instance) {
return nil, c
})
func SignalCondition(e Environment, condition, continuable Instance) (Instance, Instance) {
if !InstanceOf(SeriousConditionClass, condition) {
return SignalCondition(e, NewDomainError(e, condition, SeriousConditionClass), Nil)
}
condition.(BasicInstance).SetSlotValue(NewSymbol("IRIS.CONTINUABLE"), continuable, SeriousConditionClass)
_, c := e.Handler.(Applicable).Apply(e, condition)
if InstanceOf(ContinueClass, c) {
o, _ := c.(BasicInstance).GetSlotValue(NewSymbol("IRIS.OBJECT"), ContinueClass)
return o, nil
}
return nil, c
}
func NewEndOfStream(e Environment) Instance {
return Create(e, EndOfStreamClass)
}
func NewArithmeticError(e Environment, operation, operands Instance) Instance {
return Create(e, ArithmeticErrorClass,
NewSymbol("OPERATION"), operation,
NewSymbol("OPERANDS"), operands)
}
func NewDivisionByZero(e Environment, operation, operands Instance) Instance {
return Create(e, DivisionByZeroClass,
NewSymbol("OPERATION"), operation,
NewSymbol("OPERANDS"), operands)
}
func NewParseError(e Environment, str, expectedClass Instance) Instance {
return Create(e, ParseErrorClass,
NewSymbol("STRING"), str,
NewSymbol("EXPECTED-CLASS"), expectedClass)
}
func NewDomainError(e Environment, object Instance, expectedClass Class) Instance {
return Create(e, DomainErrorClass,
NewSymbol("OBJECT"), object,
NewSymbol("EXPECTED-CLASS"), expectedClass)
}
func NewUndefinedFunction(e Environment, name Instance) Instance {
l, c := -1, -1
if s, ok := name.(Symbol); ok {
l, c = s.Location()
}
loc := NewCons(NewInteger(l), NewInteger(c))
return Create(e, UndefinedFunctionClass,
NewSymbol("NAME"), name,
NewSymbol("NAMESPACE"), NewSymbol("FUNCTION"),
NewSymbol("IRIS.STACKTRACE"), NewCons(loc, Nil))
}
func NewUnboundVariable(e Environment, name Instance) Instance {
l, c := -1, -1
if s, ok := name.(Symbol); ok {
l, c = s.Location()
}
loc := NewCons(NewInteger(l), NewInteger(c))
return Create(e, UnboundVariableClass,
NewSymbol("NAME"), name,
NewSymbol("NAMESPACE"), NewSymbol("VARIABLE"),
NewSymbol("IRIS.STACKTRACE"), NewCons(loc, Nil))
}
func NewUndefinedClass(e Environment, name Instance) Instance {
l, c := -1, -1
if s, ok := name.(Symbol); ok {
l, c = s.Location()
}
loc := NewCons(NewInteger(l), NewInteger(c))
return Create(e, UndefinedEntityClass,
NewSymbol("NAME"), name,
NewSymbol("NAMESPACE"), NewSymbol("CLASS"),
NewSymbol("IRIS.STACKTRACE"), NewCons(loc, Nil))
}
func NewArityError(e Environment) Instance {
return Create(e, ProgramErrorClass)
}
func NewIndexOutOfRange(e Environment) Instance {
return Create(e, ProgramErrorClass)
}
func NewImmutableBinding(e Environment) Instance {
return Create(e, ProgramErrorClass)
}
func NewSimpleError(e Environment, formatString, formatArguments Instance) Instance {
return Create(e, SimpleErrorClass,
NewSymbol("FORMAT-STRING"), formatString,
NewSymbol("FORMAT-ARGUMENTS"), formatArguments)
}
func NewControlError(e Environment) Instance {
return Create(e, ControlErrorClass)
}
func NewStreamError(e Environment, stream Instance) Instance {
return Create(e, StreamErrorClass, NewSymbol("STREAM"), stream)
}