-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.rb
70 lines (60 loc) · 1.41 KB
/
errors.rb
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
class VM
class InternalError < ::Exception
def initialize(*)
super
set_backtrace(VM.instance.backtrace)
end
end
class LongJumpError < InternalError
attr_reader :value
def initialize(value)
@value = value
end
def do_jump!
raise InternalError, 'Not implemented'
end
def message
"#{self.class}(#{@value.inspect})"
end
end
class ReturnError < LongJumpError
def do_jump!
frame = VM.instance.current_frame
if frame.can_return?
# swallow
frame.returning = self.value
else
VM.instance.pop_frame(reason: "longjmp (return) #{self}")
raise self
end
end
end
class NextError < LongJumpError
def do_jump!
frame = VM.instance.current_frame
if frame.can_do_next?
# swallow
frame.returning = self.value
else
VM.instance.pop_frame(reason: "longjmp (next) #{self}")
raise self
end
end
end
class BreakError < LongJumpError
def do_jump!
frame = VM.instance.current_frame
if frame.can_do_break?
if frame.is_lambda
frame.returning = self.value
else
VM.instance.pop_frame(reason: "propagating block return #{self}")
raise ReturnError, self.value
end
else
VM.instance.pop_frame(reason: "longjmp (break) #{self}")
raise self
end
end
end
end