microcad_lang/builtin/
module_builder.rs1use crate::{
7 Identifier,
8 builtin::{BuiltinConstant, BuiltinWorkbenchDefinition},
9 lower::ir,
10 symbol::{Symbol, SymbolDef},
11 value::Value,
12};
13
14pub struct ModuleBuilder {
16 module: Symbol,
18}
19
20impl ModuleBuilder {
21 pub fn new(id: impl Into<Identifier>) -> Self {
23 Self {
24 module: Symbol::new(
25 SymbolDef::Module(ir::ModuleDefinition::new(ir::Visibility::Public, id.into())),
26 None,
27 ),
28 }
29 }
30
31 pub fn symbol(self, symbol: Symbol) -> Self {
33 Symbol::add_child(&self.module, symbol);
34 self
35 }
36
37 pub fn builtin<T: BuiltinWorkbenchDefinition>(self) -> Self {
39 self.symbol(T::symbol())
40 }
41
42 pub fn pub_const(self, id: &str, value: impl Into<Value>) -> Self {
44 let value = value.into();
45 self.symbol(Symbol::new_builtin(BuiltinConstant {
46 id: Identifier::no_ref(id),
47 value,
48 doc: None,
49 }))
50 }
51
52 pub fn build(self) -> Symbol {
54 self.module
55 }
56}