@@ -53,21 +53,23 @@ namespace rubinius {
53
53
void Fiber::start_on_stack () {
54
54
#ifdef RBX_FIBER_ENABLED
55
55
VM* vm = VM::current ();
56
- State state (vm);
56
+ State state_obj (vm), *state = &state_obj ;
57
57
58
- Fiber* fib = Fiber::current (& state);
58
+ Fiber* fib = Fiber::current (state);
59
59
60
60
// Reset the current fiber again to reset the stack limits so
61
61
// we can properly detect stack overflows
62
62
vm->set_current_fiber (fib);
63
63
64
64
Array* result = nil<Array>();
65
- Object* obj = fib->starter ()->send (&state, NULL , state.globals ().sym_call .get (), fib->value (), cNil, false );
65
+ Object* obj = fib->starter ()->send (state, NULL , G (sym_call), fib->value (), cNil, false );
66
+
66
67
// GC has run! Don't use stack vars!
67
68
68
- fib = Fiber::current (& state);
69
+ fib = Fiber::current (state);
69
70
fib->status_ = Fiber::eDead;
70
71
fib->dead_ = cTrue;
72
+ fib->set_call_frame (0 );
71
73
72
74
Fiber* dest = fib->prev ();
73
75
@@ -80,19 +82,20 @@ namespace rubinius {
80
82
// of returning, so we can deal with it in the same way
81
83
// as *args from #yield, #resume, and #transfer
82
84
if (obj) {
83
- result = Array::create (& state, 1 );
84
- result->set (& state, 0 , obj);
85
+ result = Array::create (state, 1 );
86
+ result->set (state, 0 , obj);
85
87
} else {
86
- if (state. vm ()->thread_state ()->raise_reason () == cException) {
87
- dest->exception (& state, state. vm ()->thread_state ()->current_exception ());
88
+ if (state-> vm ()->thread_state ()->raise_reason () == cException) {
89
+ dest->exception (state, state-> vm ()->thread_state ()->current_exception ());
88
90
}
89
91
}
90
92
91
- dest->run ();
92
- dest->value (&state, result);
93
- state.vm ()->set_current_fiber (dest);
93
+ dest->run (state);
94
+ dest->value (state, result);
95
+
96
+ dest->data_ ->switch_and_orphan (state, fib->data_ );
94
97
95
- dest-> data_ -> switch_and_orphan (&state, fib-> data_ );
98
+ // TODO: CallFrame: return from this function
96
99
97
100
assert (0 && " fatal start_on_stack error" );
98
101
#else
@@ -123,15 +126,15 @@ namespace rubinius {
123
126
}
124
127
125
128
if (status_ == Fiber::eDead || data_->dead_p ()) {
126
- Exception::fiber_error (state, " dead fiber called" );
129
+ Exception::raise_fiber_error (state, " dead fiber called" );
127
130
}
128
131
129
132
if (!prev_->nil_p ()) {
130
- Exception::fiber_error (state, " double resume" );
133
+ Exception::raise_fiber_error (state, " double resume" );
131
134
}
132
135
133
136
if (data_->thread () && data_->thread () != state->vm ()) {
134
- Exception::fiber_error (state, " cross thread fiber resuming is illegal" );
137
+ Exception::raise_fiber_error (state, " cross thread fiber resuming is illegal" );
135
138
}
136
139
137
140
Array* val = args.as_array (state);
@@ -140,10 +143,9 @@ namespace rubinius {
140
143
Fiber* cur = Fiber::current (state);
141
144
prev (state, cur);
142
145
143
- cur->sleep (calling_environment );
146
+ cur->sleep (state-> vm ()-> call_frame () );
144
147
145
- run ();
146
- state->vm ()->set_current_fiber (this );
148
+ run (state);
147
149
148
150
data_->switch_to (state, cur->data_ );
149
151
@@ -181,11 +183,11 @@ namespace rubinius {
181
183
}
182
184
183
185
if (status_ == Fiber::eDead || data_->dead_p ()) {
184
- Exception::fiber_error (state, " dead fiber called" );
186
+ Exception::raise_fiber_error (state, " dead fiber called" );
185
187
}
186
188
187
189
if (data_->thread () && data_->thread () != state->vm ()) {
188
- Exception::fiber_error (state, " cross thread fiber resuming is illegal" );
190
+ Exception::raise_fiber_error (state, " cross thread fiber resuming is illegal" );
189
191
}
190
192
191
193
Array* val = args.as_array (state);
@@ -197,10 +199,9 @@ namespace rubinius {
197
199
198
200
prev (state, root);
199
201
200
- cur->sleep (calling_environment );
202
+ cur->sleep (state-> vm ()-> call_frame () );
201
203
202
- run ();
203
- state->vm ()->set_current_fiber (this );
204
+ run (state);
204
205
205
206
data_->switch_to (state, cur->data_ );
206
207
@@ -239,18 +240,17 @@ namespace rubinius {
239
240
assert (cur != dest_fib);
240
241
241
242
if (cur->root_ ) {
242
- Exception::fiber_error (state, " can't yield from root fiber" );
243
+ Exception::raise_fiber_error (state, " can't yield from root fiber" );
243
244
}
244
245
245
246
cur->prev (state, nil<Fiber>());
246
247
247
248
Array* val = args.as_array (state);
248
249
dest_fib->value (state, val);
249
250
250
- cur->sleep (calling_environment );
251
+ cur->sleep (state-> vm ()-> call_frame () );
251
252
252
- dest_fib->run ();
253
- state->vm ()->set_current_fiber (dest_fib);
253
+ dest_fib->run (state);
254
254
255
255
dest_fib->data_ ->switch_to (state, cur->data_ );
256
256
0 commit comments