microcad_lang/builtin/
mod.rs1#[allow(clippy::module_inception)]
7pub mod builtin;
8
9pub mod export;
10pub mod file_io;
11pub mod import;
12pub mod module_builder;
13pub mod operation;
14pub mod workpiece;
15
16pub use builtin::*;
17pub use export::*;
18pub use file_io::*;
19pub use import::*;
20pub use module_builder::*;
21pub use workpiece::*;
22
23use microcad_core::*;
24
25use crate::{ty::*, value::*};
26
27pub enum BuiltinTypeHelper {
32 Integer,
34 Scalar,
36 Length,
38 Area,
40 Volume,
42 Density,
44 Angle,
46 Weight,
48 String,
50 Bool,
52 Color,
54}
55
56impl From<BuiltinTypeHelper> for Type {
57 fn from(value: BuiltinTypeHelper) -> Self {
58 match value {
59 BuiltinTypeHelper::Integer => Type::Integer,
60 BuiltinTypeHelper::Scalar => Type::Quantity(QuantityType::Scalar),
61 BuiltinTypeHelper::Length => Type::Quantity(QuantityType::Length),
62 BuiltinTypeHelper::Area => Type::Quantity(QuantityType::Area),
63 BuiltinTypeHelper::Volume => Type::Quantity(QuantityType::Volume),
64 BuiltinTypeHelper::Density => Type::Quantity(QuantityType::Density),
65 BuiltinTypeHelper::Angle => Type::Quantity(QuantityType::Angle),
66 BuiltinTypeHelper::Weight => Type::Quantity(QuantityType::Weight),
67 BuiltinTypeHelper::String => Type::String,
68 BuiltinTypeHelper::Bool => Type::Bool,
69 BuiltinTypeHelper::Color => Type::Tuple(TupleType::new_color().into()),
70 }
71 }
72}
73
74pub enum BuiltinValueHelper {
79 Integer(Integer),
81 Scalar(Scalar),
83 Length(Length),
85 Area(Scalar),
87 Volume(Scalar),
89 Density(Scalar),
91 Angle(Scalar),
93 Weight(Scalar),
95 String(String),
97 Bool(bool),
99 Color(Color),
101}
102
103impl From<BuiltinValueHelper> for Value {
104 fn from(value: BuiltinValueHelper) -> Self {
105 match value {
106 BuiltinValueHelper::Scalar(v) => {
107 Value::Quantity(Quantity::new(v, QuantityType::Scalar))
108 }
109 BuiltinValueHelper::Integer(i) => Value::Integer(i),
110 BuiltinValueHelper::Length(v) => {
111 Value::Quantity(Quantity::new(*v, QuantityType::Length))
112 }
113 BuiltinValueHelper::Area(v) => Value::Quantity(Quantity::new(v, QuantityType::Area)),
114 BuiltinValueHelper::Volume(v) => {
115 Value::Quantity(Quantity::new(v, QuantityType::Volume))
116 }
117 BuiltinValueHelper::Density(v) => {
118 Value::Quantity(Quantity::new(v, QuantityType::Density))
119 }
120 BuiltinValueHelper::Angle(v) => Value::Quantity(Quantity::new(v, QuantityType::Angle)),
121 BuiltinValueHelper::Weight(v) => {
122 Value::Quantity(Quantity::new(v, QuantityType::Weight))
123 }
124 BuiltinValueHelper::String(s) => Value::String(s),
125 BuiltinValueHelper::Bool(b) => Value::Bool(b),
126 BuiltinValueHelper::Color(c) => c.into(),
127 }
128 }
129}
130
131pub use crate::model::Operation;
133pub use crate::parameter;
134pub use crate::symbol::Symbol;
135pub use crate::syntax::Identifier;
136pub use crate::value::ParameterValue;
137pub use crate::value::ParameterValueList;
138pub use crate::value::ValueAccess;
139
140#[macro_export]
142macro_rules! parameter {
143 ($id:ident) => {
144 (
145 $crate::builtin::Identifier::no_ref(stringify!($id)),
146 $crate::value::ParameterValue {
147 src_ref: microcad_lang_base::SrcRef(None),
148 ..Default::default()
149 },
150 )
151 };
152 ($id:ident: $ty:ident) => {
153 (
154 $crate::syntax::Identifier::no_ref(stringify!($id)),
155 $crate::value::ParameterValue {
156 specified_type: Some($crate::builtin::BuiltinTypeHelper::$ty.into()),
157 src_ref: microcad_lang_base::SrcRef(None),
158 ..Default::default()
159 },
160 )
161 };
162 ($id:ident: $ty:ident = $value:expr) => {
163 (
164 $crate::syntax::Identifier::no_ref(stringify!($id)),
165 $crate::value::ParameterValue {
166 specified_type: Some($crate::builtin::BuiltinTypeHelper::$ty.into()),
167 default_value: Some($crate::builtin::BuiltinValueHelper::$ty($value).into()),
168 src_ref: microcad_lang_base::SrcRef(None),
169 },
170 )
171 };
172 ($id:ident = $value:expr) => {
173 (
174 $crate::syntax::Identifier::no_ref(stringify!($id)),
175 $crate::value::ParameterValue {
176 default_value: Some($value),
177 ..Default::default()
178 },
179 )
180 };
181 () => {};
182}
183
184#[macro_export]
186macro_rules! argument {
187 ($id:ident: $ty:ident = $value:expr) => {
188 (
189 $crate::syntax::Identifier::no_ref(stringify!($id)),
190 ArgumentValue::new(
191 $crate::builtin::BuiltinValueHelper::$ty($value).into(),
192 None,
193 microcad_lang_base::SrcRef(None),
194 ),
195 )
196 };
197 ($ty:ident = $value:expr) => {
198 (
199 Identifier::none(),
200 ArgumentValue::new(
201 $crate::builtin::BuiltinValueHelper::$ty($value).into(),
202 None,
203 microcad_lang_base::SrcRef(None),
204 ),
205 )
206 };
207 () => {};
208}
209
210#[macro_export]
212macro_rules! property {
213 ($id:ident : $ty:ident = $value:expr) => {
214 (
215 Identifier::no_ref(stringify!($id)),
216 $crate::builtin::BuiltinValueHelper::$ty($value).into(),
217 )
218 };
219 () => {};
220}