Skip to content

Add python Evaluator module#2986

Merged
slaff merged 8 commits intoSmingHub:developfrom
pljakobs:feature/evaluator
Jan 26, 2026
Merged

Add python Evaluator module#2986
slaff merged 8 commits intoSmingHub:developfrom
pljakobs:feature/evaluator

Conversation

@pljakobs
Copy link
Contributor

Introduce an 'Evaluator' Class to Tools/Python/evaluator.py designed to evaluate logical and mathematical expressions in various build-time configurations like ConfigDB

Key features:

  • implements a set of arithmetic functions (+,-,*,/, pow2, log2)
  • implements logical operations (&&, ||, ! and !=)
  • implements min/max and align_up functions to calculate hardware- specific values such as "how much flash do I need to store x bytes if flash block size is 4096

Introduce an 'Evaluator' Class to Tools/Python/evaluator.py
designed to evaluate logical and mathematical expressions in
various build-time configurations like ConfigDB

Key features:
- implements a set of arithmetic functions (+,-,*,/, pow2, log2)
- implements logical operations (&&, ||, ! and !=)
- implements min/max and align_up functions to calculate hardware-
  specific values such as "how much flash do I need to store x bytes
  if flash block size is 4096
@what-the-diff
Copy link

what-the-diff bot commented Jan 16, 2026

PR Summary

  • New Python script: 'evaluator.py'
    We have added a new script which introduces a specialized language to efficiently handle and compute expressions.

  • Introduction of 'Evaluator' class
    This newly implemented class will assist in performing mathematical, binary, logical operations and comparisons. It also comes with some uniquely modeled functions like 'pow2', 'log2', and 'align_up'.

  • Environment Variables Processing
    We are also processing environment variables, converting them into boolean (true or false) values with the help of an auxiliary '_is_truthy' function.

  • Enhanced Expression Parsing
    We have improved handling and interpretation of expressions using Python's AST library, which should simplify their usage and increase reliability.

  • New Documentation: 'evaluator.md'
    A markup file has been created documenting the syntax of our newly introduced specialized language, it's built-in functions and any security precautions taken to prevent any possible compromises, such as injection attacks.

  • Automated Test Script: 'evaluator_test.py'
    Finally, we've added a test script to run a variety of tests that will verify the function of our 'Evaluator' class in comparison to the expected results, ensuring their performance matches our standards.

@slaff slaff requested a review from mikee47 January 19, 2026 12:16
Copy link
Contributor

@mikee47 mikee47 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pljakobs Are you happy with the changes I've made? The two main changes are:

  • Allow custom variable resolution using get_variable callback
  • Propagate exceptions rather than returning a string. That might be OK in a CLI but not for use in other code. We cannot know that legitimate return values don't start with 'Error: ' for example.

We may need other features in the future but I think this covers the basics.

@slaff slaff modified the milestones: 6.3.0, 6.1.0 Jan 19, 2026
@pljakobs
Copy link
Contributor Author

looks good to me. Thanks for your work!

@mikee47 mikee47 changed the title [WIP] Feature/evaluator Add python Evaluator module Jan 21, 2026
@slaff slaff merged commit 714687a into SmingHub:develop Jan 26, 2026
34 of 35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants