1mod built_in;
2mod files;
3mod float;
4mod int;
5mod list;
6mod math;
7mod string;
8
9use std::sync::Arc;
10
11use ahash::AHashMap;
12use diatom_core::{
13 extension::{Extension, ExtensionKind},
14 ffi::{DiatomValue, ForeignFunction},
15 IoWrite, StdCore,
16};
17
18static PRELUDE_NAMES: [&str; 17] = [
19 "print",
20 "println",
21 "todo",
22 "assert",
23 "unreachable",
24 "panic",
25 "List",
26 "Int",
27 "Float",
28 "String",
29 "Table",
30 "Iter",
31 "Range",
32 "Option",
33 "Some",
34 "None",
35 "Gc",
36];
37
38pub struct StdLibCore;
39
40impl StdCore for StdLibCore {
41 fn prelude_names() -> &'static [&'static str] {
42 &PRELUDE_NAMES
43 }
44
45 fn prelude_files() -> &'static [(&'static str, &'static str)] {
46 &files::PRELUDE_FILES
47 }
48
49 fn prelude_extension<Buffer: IoWrite>() -> Extension<Buffer> {
50 Extension {
51 name: "prelude".to_string(),
52 kind: ExtensionKind::SubExtensions(vec![
53 built_in::built_in_extension(),
54 int::int_extension(),
55 float::float_extension(),
56 list::list_extension(),
57 ]),
58 }
59 }
60}
61
62pub fn std_lib<Buffer: IoWrite>() -> Vec<Extension<Buffer>> {
63 vec![math::math_extension()]
64}
65
66macro_rules! assure_para_len {
67 ($parameters: ident, $len: literal) => {
68 if $parameters.len() != $len {
69 return Err(format!(
70 "Expected {} parameter while {} is provided",
71 $len,
72 $parameters.len()
73 ));
74 }
75 };
76}
77
78pub(crate) use assure_para_len;