microcad_lang/eval/
init.rs

1// Copyright © 2024-2025 The µcad authors <info@ucad.xyz>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4use crate::{eval::*, model::*, syntax::*};
5
6impl InitDefinition {
7    /// Evaluate a call to the init definition
8    pub fn eval(&self, args: Tuple, context: &mut Context) -> EvalResult<()> {
9        context.grant(self)?;
10        let model = context.get_model()?;
11        context.scope(StackFrame::Init(args.into()), |context| {
12            let _: Value = self.body.statements.eval(context)?;
13
14            if let Some(properties) = model.borrow().get_properties() {
15                let missing: IdentifierList = properties
16                    .iter()
17                    .filter(|(_, value)| value.is_invalid())
18                    .map(|(id, _)| id.clone())
19                    .collect();
20
21                if !missing.is_empty() {
22                    context.error(self, EvalError::BuildingPlanIncomplete(missing))?;
23                }
24            }
25
26            Ok(())
27        })
28    }
29}