|
ESBMC
Efficient SMT-based Context-Bounded Model Checker
|
Lightweight Python AST evaluator for compile-time function evaluation. More...
#include <python_consteval.h>
Public Member Functions | |
| python_consteval (const nlohmann::json &ast, int max_iterations=50000) | |
| std::optional< PyConstValue > | try_eval_call (const std::string &func_name, const std::vector< PyConstValue > &args) |
| Try to evaluate a function call with constant arguments. | |
| std::optional< PyConstValue > | try_eval_global_expr (const nlohmann::json &expr) |
| Try to evaluate an arbitrary expression at module scope, seeding the environment with module-level constant globals first. | |
Lightweight Python AST evaluator for compile-time function evaluation.
When a pure function is called with all-constant arguments, this evaluator interprets the function body at conversion time and returns the result, eliminating loops from the GOTO program entirely.
|
explicit |
| std::optional< PyConstValue > python_consteval::try_eval_call | ( | const std::string & | func_name, |
| const std::vector< PyConstValue > & | args ) |
Try to evaluate a function call with constant arguments.
Returns std::nullopt if evaluation cannot be completed (unsupported construct, timeout, recursion limit, etc.).
| std::optional< PyConstValue > python_consteval::try_eval_global_expr | ( | const nlohmann::json & | expr | ) |
Try to evaluate an arbitrary expression at module scope, seeding the environment with module-level constant globals first.
Used to fold whole assertion tests such as f(GLOBAL) == [literal] whose operands reference module globals (which try_eval_call alone cannot see). Returns std::nullopt if any sub-expression is not constant-foldable.