1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use std::borrow::Borrow;
use itertools::Itertools;
use ::api::method::StringCast;
use ::api::result::{ObjectResult};
use ::api::RtObject as ObjectRef;
use ::modules::builtins::Type;
use ::resources::strings;
use ::runtime::Runtime;
use ::runtime::traits::{IteratorProvider, NoneProvider};
use ::system::primitives as rs;
use ::system::primitives::{Signature, Func, FuncType};
pub struct PrintFn;
impl PrintFn {
pub fn create() -> rs::Func {
trace!("create builtin"; "function" => "print");
let callable: Box<rs::WrapperFn> = Box::new(rs_builtin_print);
Func {
name: String::from("print"),
module: String::from(strings::BUILTINS_MODULE),
callable: FuncType::Wrapper(callable),
signature: Signature::new(
&["value"], &[], Some("*objs"), Some("**opts"))
}
}
}
#[allow(unused_variables)]
fn rs_builtin_print(rt: &Runtime, pos_args: &ObjectRef,
starargs: &ObjectRef,
kwargs: &ObjectRef) -> ObjectResult {
trace!("call"; "native_builtin" => "print");
let mut strings: Vec<String> = Vec::new();
let tuple_iterator = match rs::Iterator::new(pos_args){
Ok(iterator) => rt.iter(iterator),
Err(_) => unreachable!(),
};
let output = &tuple_iterator.map(|object| {
match object.native_str() {
Ok(string) => string,
Err(err) => {
warn!("Error during call"; "native_builtin" => "str");
format!("{}", object)
}
}
})
.map(|s| format!(">>> {}",s ))
.join("\n");
info!("rs_builtin_print";
"output" => format!("\n{}\n", output));
Ok(rt.none())
}