1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright © 2024-2026 The µcad authors <info@microcad.xyz>
// SPDX-License-Identifier: AGPL-3.0-or-later
//! Evaluation of parsed content.
//!
//! To be able to evaluate (run) a source file, it must be loaded, parsed and resolved.
//! To do so a [`EvalContext`] can be created with [`EvalContext::new()`] based on an already resolved symbol or
//! by using [`EvalContext::from_source()`] or `ContextBuilder::from_source_captured()` which both automatically
//! load and resolve the source file and build a context around it which then can be evaluated with [`EvalContext::eval()`]:
//!
//! ```ignore
//! use microcad_lang::eval::EvalContext;
//! use microcad_lang::diag::Diag;
//! use std::io::stdout;
//!
//! // create a context for evaluation of the source file
//! let mut context = EvalContext::from_source(
//! "my.µcad", // root file name
//! builtin_module(), // `__builtin` library
//! &["./std/lib".into()] // list of std library path
//! ).expect("successful load, parse and resolve");
//!
//! // evaluate the source file in it's context
//! let node = context.eval().expect("successful evaluation");
//!
//! // print any error
//! println!("{}", context.diagnosis());
//! ```
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
use *;
use PushDiag;
use crate::;
/// Evaluation trait.
///
/// The return type `T` defines to which output type the type is evaluated.
/// Usually, these output types are used in specific context:
///
/// | Return type `T` | Context / Scope | Return value on error | Description |
/// | ------------------- | --------------------------------------------------- | ----------------------- | ----------------------------------------------------------------------- |
/// | `()` | [`Assignment`]. | `()` | An assignment returns nothing but alters the symbol table. |
/// | | | |
/// | `Value` | Function calls, module statements, | `Value::None` | These trait implementations are
/// | | parameter lists, argument lists. | | mostly used when evaluating functions.
/// | | | |
/// | `Option<Model>` | Workbenches, object bodies, source files, if. | `None` | Something is evaluated into a single model. |
/// | | | |
/// | `Models` | Statement, statement list, body, multiplicities. | `Models::default()` | A collection of models . |
/// Like `todo!()` but within a evaluation context
///
/// emits a diagnostic error instead of panicking.
pub use eval_todo;