Skip to main content

logicaffeine_system/
text.rs

1// Intentionally camelCase to match the LOGOS surface builtins `parseInt`/`parseFloat`
2// (codegen emits these exact names), so the non-snake-case lint is suppressed rather
3// than renamed — and so compiled programs that link this crate keep a clean stderr.
4#[inline]
5#[allow(non_snake_case)]
6pub fn parseInt(s: String) -> i64 {
7    s.trim()
8        .parse::<i64>()
9        .unwrap_or_else(|_| panic!("Cannot parse '{}' as Int", s))
10}
11
12#[inline]
13#[allow(non_snake_case)]
14pub fn parseFloat(s: String) -> f64 {
15    s.trim()
16        .parse::<f64>()
17        .unwrap_or_else(|_| panic!("Cannot parse '{}' as Float", s))
18}
19
20#[inline]
21pub fn chr(code: i64) -> String {
22    match char::from_u32(code as u32) {
23        Some(c) => c.to_string(),
24        None => panic!("Invalid character code: {}", code),
25    }
26}