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 Target,
56}
57
58impl From<BuiltinTypeHelper> for Type {
59 fn from(value: BuiltinTypeHelper) -> Self {
60 match value {
61 BuiltinTypeHelper::Integer => Type::Integer,
62 BuiltinTypeHelper::Scalar => Type::Quantity(QuantityType::Scalar),
63 BuiltinTypeHelper::Length => Type::Quantity(QuantityType::Length),
64 BuiltinTypeHelper::Area => Type::Quantity(QuantityType::Area),
65 BuiltinTypeHelper::Volume => Type::Quantity(QuantityType::Volume),
66 BuiltinTypeHelper::Density => Type::Quantity(QuantityType::Density),
67 BuiltinTypeHelper::Angle => Type::Quantity(QuantityType::Angle),
68 BuiltinTypeHelper::Weight => Type::Quantity(QuantityType::Weight),
69 BuiltinTypeHelper::String => Type::String,
70 BuiltinTypeHelper::Bool => Type::Bool,
71 BuiltinTypeHelper::Color => Type::Tuple(TupleType::new_color().into()),
72 BuiltinTypeHelper::Target => Type::Target,
73 }
74 }
75}
76
77pub enum BuiltinValueHelper {
82 Integer(Integer),
84 Scalar(Scalar),
86 Length(Length),
88 Area(Scalar),
90 Volume(Scalar),
92 Density(Scalar),
94 Angle(Scalar),
96 Weight(Scalar),
98 String(String),
100 Bool(bool),
102 Color(Color),
104 Name(Target),
106}
107
108impl From<BuiltinValueHelper> for Value {
109 fn from(value: BuiltinValueHelper) -> Self {
110 match value {
111 BuiltinValueHelper::Scalar(v) => {
112 Value::Quantity(Quantity::new(v, QuantityType::Scalar))
113 }
114 BuiltinValueHelper::Integer(i) => Value::Integer(i),
115 BuiltinValueHelper::Length(v) => {
116 Value::Quantity(Quantity::new(*v, QuantityType::Length))
117 }
118 BuiltinValueHelper::Area(v) => Value::Quantity(Quantity::new(v, QuantityType::Area)),
119 BuiltinValueHelper::Volume(v) => {
120 Value::Quantity(Quantity::new(v, QuantityType::Volume))
121 }
122 BuiltinValueHelper::Density(v) => {
123 Value::Quantity(Quantity::new(v, QuantityType::Density))
124 }
125 BuiltinValueHelper::Angle(v) => Value::Quantity(Quantity::new(v, QuantityType::Angle)),
126 BuiltinValueHelper::Weight(v) => {
127 Value::Quantity(Quantity::new(v, QuantityType::Weight))
128 }
129 BuiltinValueHelper::String(s) => Value::String(s),
130 BuiltinValueHelper::Bool(b) => Value::Bool(b),
131 BuiltinValueHelper::Color(c) => c.into(),
132 BuiltinValueHelper::Name(t) => t.try_into().expect("Valid value"),
133 }
134 }
135}
136
137pub use crate::model::Operation;
139pub use crate::parameter;
140pub use crate::resolve::Symbol;
141pub use crate::syntax::Identifier;
142pub use crate::value::ParameterValue;
143pub use crate::value::ParameterValueList;
144pub use crate::value::ValueAccess;
145
146#[macro_export]
148macro_rules! parameter {
149 ($id:ident) => {
150 (
151 $crate::builtin::Identifier::no_ref(stringify!($id)),
152 $crate::value::ParameterValue {
153 src_ref: $crate::src_ref::SrcRef(None),
154 ..Default::default()
155 },
156 )
157 };
158 ($id:ident: $ty:ident) => {
159 (
160 $crate::syntax::Identifier::no_ref(stringify!($id)),
161 $crate::value::ParameterValue {
162 specified_type: Some($crate::builtin::BuiltinTypeHelper::$ty.into()),
163 src_ref: $crate::src_ref::SrcRef(None),
164 ..Default::default()
165 },
166 )
167 };
168 ($id:ident: $ty:ident = $value:expr) => {
169 (
170 $crate::syntax::Identifier::no_ref(stringify!($id)),
171 $crate::value::ParameterValue {
172 specified_type: Some($crate::builtin::BuiltinTypeHelper::$ty.into()),
173 default_value: Some($crate::builtin::BuiltinValueHelper::$ty($value).into()),
174 src_ref: $crate::src_ref::SrcRef(None),
175 },
176 )
177 };
178 ($id:ident = $value:expr) => {
179 (
180 $crate::syntax::Identifier::no_ref(stringify!($id)),
181 $crate::value::ParameterValue {
182 default_value: Some($value),
183 ..Default::default()
184 },
185 )
186 };
187 () => {};
188}
189
190#[macro_export]
192macro_rules! argument {
193 ($id:ident: $ty:ident = $value:expr) => {
194 (
195 $crate::syntax::Identifier::no_ref(stringify!($id)),
196 ArgumentValue::new(
197 $crate::builtin::BuiltinValueHelper::$ty($value).into(),
198 None,
199 $crate::src_ref::SrcRef(None),
200 ),
201 )
202 };
203 ($ty:ident = $value:expr) => {
204 (
205 Identifier::none(),
206 ArgumentValue::new(
207 $crate::builtin::BuiltinValueHelper::$ty($value).into(),
208 None,
209 $crate::src_ref::SrcRef(None),
210 ),
211 )
212 };
213 () => {};
214}
215
216#[macro_export]
218macro_rules! property {
219 ($id:ident : $ty:ident = $value:expr) => {
220 (
221 Identifier::no_ref(stringify!($id)),
222 $crate::builtin::BuiltinValueHelper::$ty($value).into(),
223 )
224 };
225 () => {};
226}