pipeline_script/plugin/
builtin.rs

1use crate::ast::r#type::Type;
2use crate::core::builtin::{cmd, now, panic, println, sleep, spawn, wait, workspace};
3use crate::core::engine::Engine;
4use crate::llvm::global::Global;
5use crate::llvm::value::fucntion::FunctionValue;
6use crate::llvm::value::LLVMValue;
7use crate::plugin::Plugin;
8use std::ffi::c_void;
9
10pub struct BuiltinPlugin;
11impl Plugin for BuiltinPlugin {
12    fn apply(self, e: &mut Engine) {
13        e.register_external_function("println", println as *mut c_void);
14        e.register_external_function("cmd", cmd as *mut c_void);
15        e.register_external_function("workspace", workspace as *mut c_void);
16        e.register_external_function("panic", panic as *mut c_void);
17        e.register_external_function("now", now as *mut c_void);
18        e.register_external_function("spawn", spawn as *mut c_void);
19        e.register_external_function("wait", wait as *mut c_void);
20        e.register_external_function("sleep", sleep as *mut c_void);
21        e.register_builtin_symbol_type(
22            "sizeof",
23            Type::Function(Box::new(Type::Int64), vec![], false),
24        );
25        let reference = Global::unit_type().get_undef().as_llvm_value_ref();
26        let sizeof_reference = LLVMValue::Function(FunctionValue::new(
27            reference,
28            "sizeof".into(),
29            Box::new(Global::const_i32(0).into()),
30            vec![],
31        ));
32        e.register_builtin_symbol("sizeof", sizeof_reference);
33        e.register_precluded_scripts(&["extern fn cmd(key: String, cmd: String)
34            extern fn println(obj: Any)
35            extern fn workspace(key: String, path: String)
36            extern fn panic(msg: String)
37            extern fn printf(format: String, ...)
38            extern fn now() -> Int64
39            extern fn spawn(f: Fn())
40            extern fn wait()
41            extern fn sleep(ms: Int64)"]);
42    }
43}