Skip to main content

rl_lang/interpreter/stdlib/types/
oct.rs

1use crate::interpreter::{
2    evaluator::Evaluator,
3    stdlib::common::{verr, vok, vs},
4    values::Value,
5};
6
7pub fn func(_: &mut Evaluator, value: Value) -> Value {
8    let result = match value {
9        Value::Integer(v) => format!("{:o}", v),
10        Value::Byte(v) => format!("{:o}", v),
11        Value::Char(v) => format!("{:o}", v as u32),
12        Value::String(s) => s.bytes().map(|b| format!("{:o}", b)).collect::<String>(),
13
14        other => {
15            return verr!(vs!(format!(
16                "cannot parse \"{}\" as octal",
17                other.type_name()
18            )));
19        }
20    };
21    vok!(vs!(result))
22}