uni_core/primitives/
doc.rs1use crate::compat::ToString;
2use crate::interpreter::Interpreter;
3use crate::value::{RuntimeError, Value};
4
5pub fn doc_builtin(interp: &mut Interpreter) -> Result<(), RuntimeError> {
6 let value = interp.pop()?;
7 let doc_text = match value {
8 Value::String(s) => s,
9 _ => {
10 return Err(RuntimeError::TypeError(
11 "doc expects a string value".to_string(),
12 ));
13 }
14 };
15
16 let target = interp
17 .take_pending_doc_target()
18 .ok_or_else(|| RuntimeError::TypeError("doc must follow def or val".to_string()))?;
19
20 interp.attach_doc(&target, doc_text)?;
21 Ok(())
22}