pipeline_script/plugin/
builtin.rs

1use crate::ast::r#type::Type;
2use crate::core::builtin::{cmd, now, panic, println, sleep, spawn, 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("sleep", sleep as *mut c_void);
20        e.register_builtin_symbol_type(
21            "sizeof",
22            Type::Function(Box::new(Type::Int64), vec![], false),
23        );
24        let reference = Global::unit_type().get_undef().as_llvm_value_ref();
25        let sizeof_reference = LLVMValue::Function(FunctionValue::new(
26            reference,
27            "sizeof".into(),
28            Box::new(Global::const_i32(0).into()),
29            vec![],
30        ));
31        e.register_builtin_symbol("sizeof", sizeof_reference);
32        e.register_precluded_scripts(&["extern fn cmd(cmd: String)
33            extern fn println(obj: Any)
34            extern fn workspace(path: String)
35            extern fn panic(msg: String)
36            extern fn printf(format: String, ...)
37            extern fn now() -> Int64
38            extern fn spawn(f: Fn())
39            extern fn sleep(ms: Int64)"]);
40    }
41}