/
vm_thread_state.cpp
98 lines (84 loc) · 2.83 KB
/
vm_thread_state.cpp
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
#include "builtin/exception.hpp"
#include "vm_thread_state.hpp"
#include "builtin/variable_scope.hpp"
#include "builtin/fixnum.hpp"
#include "builtin/class.hpp"
#include "builtin/symbol.hpp"
#include "builtin/exception.hpp"
#include "builtin/thread_state.hpp"
namespace rubinius {
VMThreadState::VMThreadState(VM* state)
: current_exception_(state, nil<Exception>())
, raise_value_(state, cNil)
, throw_dest_(state, cNil)
, raise_reason_(cNone)
, destination_scope_(state, nil<VariableScope>())
{}
ThreadState* VMThreadState::state_as_object(STATE) {
if(raise_reason_ == cNone && current_exception_.get()->nil_p()) return nil<ThreadState>();
ThreadState* thread_state = ThreadState::create(state);
thread_state->raise_reason(state, Fixnum::from(raise_reason_));
thread_state->destination_scope(state, destination_scope());
thread_state->throw_dest(state, throw_dest());
thread_state->current_exception(state, current_exception());
thread_state->raise_value(state, raise_value());
return thread_state;
}
void VMThreadState::set_state(STATE, ThreadState* thread_state) {
raise_reason_ = (RaiseReason)thread_state->raise_reason()->to_native();
current_exception_.set(thread_state->current_exception());
raise_value_.set(thread_state->raise_value());
destination_scope_.set(thread_state->destination_scope());
throw_dest_.set(thread_state->throw_dest());
}
void VMThreadState::clear() {
raise_value_.set(cNil);
raise_reason_ = cNone;
destination_scope_.set(cNil);
throw_dest_.set(cNil);
current_exception_.set(cNil);
}
void VMThreadState::clear_break() {
raise_reason_ = cNone;
raise_value_.set(cNil);
destination_scope_.set(cNil);
throw_dest_.set(cNil);
}
void VMThreadState::clear_return() {
// Use the same logic as break
clear_break();
}
void VMThreadState::clear_raise() {
clear_return();
current_exception_.set(cNil);
}
void VMThreadState::raise_exception(Exception* exc) {
raise_reason_ = cException;
current_exception_.set(exc);
destination_scope_.set(cNil);
}
void VMThreadState::raise_return(Object* value, VariableScope* dest) {
raise_reason_ = cReturn;
raise_value_.set(value);
destination_scope_.set(dest);
}
void VMThreadState::raise_break(Object* value, VariableScope* dest) {
raise_reason_ = cBreak;
raise_value_.set(value);
destination_scope_.set(dest);
}
void VMThreadState::raise_exit(Object* code) {
raise_reason_ = cExit;
raise_value_.set(code);
destination_scope_.set(cNil);
}
void VMThreadState::raise_throw(Object* dest, Object* value) {
raise_reason_ = cCatchThrow;
raise_value_.set(value);
throw_dest_.set(dest);
current_exception_.set(cNil);
}
void VMThreadState::raise_thread_kill() {
raise_reason_ = cThreadKill;
}
}