Skip to content

Commit ef0e5c6

Browse files
committed
feat: wip if-else logic
1 parent c6a96ab commit ef0e5c6

File tree

3 files changed

+70
-8
lines changed

3 files changed

+70
-8
lines changed

src/context/signal.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ pub enum Signal {
66
// Will be signaled if a function has been executed successfully
77
Success(Value),
88
// Will be signaled if
9-
// - a function recieves wrong parameter
9+
// - a function receives wrong parameter
1010
// - a function throws an error
11-
// - taurus itself throwns an error
12-
// - will stop the execution of the flow completly
11+
// - taurus itself throws an error
12+
// - will stop the execution of the flow completely
1313
Failure(RuntimeError),
1414
// Will be signaled if the `return` function has been executed
1515
// - will break the current context and return the value to the upper node
1616
Return(Value),
1717
// Will be signaled if the `respond` function has been executed
18-
// - will stop the execution of the flow completly
18+
// - will stop the execution of the flow completely
1919
// - will return the value to the adapter
2020
Respond(Value),
2121
// Will be signaled if the `stop` function has been executed
22-
// - will stop the execution of the flow completly
22+
// - will stop the execution of the flow completely
2323
Stop,
2424
}
2525

src/executor/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl<'a> Executor<'a> {
106106
Signal::Success(value.clone())
107107
}
108108
tucana::shared::node_value::Value::ReferenceValue(_reference_value) => {
109-
todo!("implement reference values!")
109+
unimplemented!("implement reference values!")
110110
}
111111
tucana::shared::node_value::Value::NodeFunctionId(id) => Executor::execute(self, *id),
112112
}

src/implementation/control.rs

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
use tucana::shared::Value;
2-
31
use crate::context::signal::Signal;
42
use crate::{context::Context, error::RuntimeError, registry::HandlerFn};
3+
use tucana::shared::Value;
4+
use tucana::shared::value::Kind;
55

66
pub fn collect_control_functions() -> Vec<(&'static str, HandlerFn)> {
77
vec![
88
("std::control::stop", stop),
99
("std::control::return", r#return),
10+
("std::control::if", r#if),
11+
("std::control::if_else", if_else),
1012
]
1113
}
1214

@@ -24,3 +26,63 @@ fn r#return(values: &[Value], _ctx: &mut Context) -> Signal {
2426

2527
Signal::Return(Value { kind: kind.clone() })
2628
}
29+
30+
fn r#if(values: &[Value], _ctx: &mut Context) -> Signal {
31+
let [
32+
Value {
33+
kind: Some(Kind::StringValue(text)),
34+
},
35+
] = values
36+
else {
37+
return Signal::Failure(RuntimeError::simple(
38+
"InvalidArgumentRuntimeError",
39+
format!("Expected a string value but received {:?}", values),
40+
));
41+
};
42+
43+
let bool: bool = match text.to_lowercase().parse() {
44+
Ok(value) => value,
45+
Err(_) => {
46+
return Signal::Failure(RuntimeError::simple(
47+
"InvalidArgumentRuntimeError",
48+
format!("Failed to parse boolean from string: {:?}", text),
49+
));
50+
}
51+
};
52+
53+
if bool {
54+
unimplemented!()
55+
} else {
56+
unimplemented!()
57+
}
58+
}
59+
60+
fn if_else(values: &[Value], _ctx: &mut Context) -> Signal {
61+
let [
62+
Value {
63+
kind: Some(Kind::StringValue(text)),
64+
},
65+
] = values
66+
else {
67+
return Signal::Failure(RuntimeError::simple(
68+
"InvalidArgumentRuntimeError",
69+
format!("Expected a string value but received {:?}", values),
70+
));
71+
};
72+
73+
let bool: bool = match text.to_lowercase().parse() {
74+
Ok(value) => value,
75+
Err(_) => {
76+
return Signal::Failure(RuntimeError::simple(
77+
"InvalidArgumentRuntimeError",
78+
format!("Failed to parse boolean from string: {:?}", text),
79+
));
80+
}
81+
};
82+
83+
if bool {
84+
unimplemented!()
85+
} else {
86+
unimplemented!()
87+
}
88+
}

0 commit comments

Comments
 (0)