ctoolbox/formats/eite/
util.rs

1pub mod array;
2pub mod ascii;
3pub mod bitwise;
4pub mod logic;
5pub mod math;
6pub mod pred;
7pub mod string;
8
9/// Representation of the “generic” StageL values referenced by the JS.
10/// We only add the variants actually needed by the converted functions here.
11#[derive(Clone, Debug, PartialEq)]
12pub enum Value {
13    Bool(bool),
14    Int(i32),
15    Str(String),
16    Bytes(Vec<u8>),
17    Array(Vec<Value>),
18}
19
20impl Value {
21    pub fn as_bool(&self) -> Option<bool> {
22        if let Value::Bool(b) = self {
23            Some(*b)
24        } else {
25            None
26        }
27    }
28    pub fn as_int(&self) -> Option<i32> {
29        if let Value::Int(i) = self {
30            Some(*i)
31        } else {
32            None
33        }
34    }
35    pub fn as_str(&self) -> Option<&str> {
36        if let Value::Str(s) = self {
37            Some(s)
38        } else {
39            None
40        }
41    }
42    pub fn is_generic_primitive(&self) -> bool {
43        matches!(self, Value::Bool(_) | Value::Int(_) | Value::Str(_))
44    }
45}
46
47pub fn ne_values(a: &Value, b: &Value) -> bool {
48    !eq_values(a, b)
49}
50
51/// Comparison helpers (implEq / implGt / implLt) simplified.
52/// Generic equality only covers primitive subset implemented in Value above.
53/// (The original JS allowed direct === which included string/int/bool.)
54pub fn eq_values(a: &Value, b: &Value) -> bool {
55    a == b
56}
57pub fn gt_int(a: i32, b: i32) -> bool {
58    a > b
59}
60pub fn lt_int(a: i32, b: i32) -> bool {
61    a < b
62}