sim_lib_lang_ruby/
runtime.rs1use sim_kernel::{Cx, Ref, Result, Symbol};
2use sim_lib_control::{ControlResultValue, LabeledPrompt, NonLocalExit, escape_to_label};
3
4#[derive(Clone, Debug, PartialEq, Eq)]
9pub struct RubyBlockScope {
10 label: Symbol,
11 prompt: Ref,
12}
13
14impl RubyBlockScope {
15 pub fn new(label: Symbol) -> Self {
17 let prompt = Ref::Symbol(Symbol::qualified("ruby/block-prompt", label.to_string()));
18 Self { label, prompt }
19 }
20
21 pub fn label(&self) -> &Symbol {
23 &self.label
24 }
25
26 pub fn prompt(&self) -> &Ref {
28 &self.prompt
29 }
30
31 pub fn labeled_prompt(&self) -> LabeledPrompt {
33 LabeledPrompt::new(self.label.clone(), self.prompt.clone())
34 }
35}
36
37pub fn ruby_break(cx: &mut Cx, scope: &RubyBlockScope, value: Ref) -> Result<ControlResultValue> {
42 escape_to_label(
43 cx,
44 &[scope.labeled_prompt()],
45 NonLocalExit::break_to(scope.label.clone(), value),
46 )
47}
48
49pub fn ruby_next(cx: &mut Cx, scope: &RubyBlockScope, value: Ref) -> Result<ControlResultValue> {
54 escape_to_label(
55 cx,
56 &[scope.labeled_prompt()],
57 NonLocalExit::next_to(scope.label.clone(), value),
58 )
59}