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