Skip to main content

aether/api/
limits.rs

1use super::Aether;
2use crate::runtime::ExecutionLimits;
3
4impl Aether {
5    // ============================================================
6    // 执行限制
7    // ============================================================
8
9    /// 使用执行限制创建新的 Aether 引擎
10    pub fn with_limits(mut self, limits: ExecutionLimits) -> Self {
11        self.evaluator.set_limits(limits);
12        self
13    }
14
15    /// 设置执行限制
16    pub fn set_limits(&mut self, limits: ExecutionLimits) {
17        self.evaluator.set_limits(limits);
18    }
19
20    /// 获取当前执行限制
21    pub fn limits(&self) -> &ExecutionLimits {
22        self.evaluator.limits()
23    }
24
25    // ============================================================
26    // 大整数阈值
27    // ============================================================
28
29    /// 设置大整数切换阈值。
30    ///
31    /// 整数字面量位数超过该阈值时,解析期会将其构造为任意精度 BigInteger。
32    /// 默认值 15(接近 f64 精度极限)。
33    ///
34    /// 注意:AST 缓存按源码文本命中,修改阈值后已在缓存中的程序不会重新解析;
35    /// 如需立即生效可配合 `reset_env()` 或对新代码使用。
36    pub fn set_bigint_threshold(&mut self, threshold: usize) {
37        self.bigint_threshold = threshold;
38        // Import 路径的解析也走 Evaluator,保持一致
39        self.evaluator.set_bigint_threshold(threshold);
40    }
41
42    /// 获取当前大整数切换阈值
43    pub fn bigint_threshold(&self) -> usize {
44        self.bigint_threshold
45    }
46}