This includes the first step towards refactoring out the actual unit definitions from the logic that handles the CT checking.
The idea is to generate everything from a macro declaration that at some point will live in a si_system.nim file or something. Other systems can then be added that define their own units.
For that to become properly useful, we also need to generate the QuantityKind, UnitKind and BaseUnitKind as well as the related procedures from some declarative context.
Once these things are done however (and a general refactor of parsing / declaration / math / etc) has been done, general unit systems should be plug and play.
From there adding logic that describes how different systems can interop with one another becomes possible to reason about.
Other things in this PR
this PR adds the following functions:
sqrt: Allows to take the sqrt of a perfect square unit (e.g. sqrt(25.kg²) == 5.kg)
abs: returns the absolute value of the unit
*=, +=, ...: mutable assignment helpers. Units must conform to normal logic of course! This means e.g. *= is only allowed between a unit and a unitless object
improve type determination logic
allow hashing of units (to use them as keys for example)
clean up input AST before re-emitting it. This helps the AST bloat that can be accumulated if node is part of multiple complex math operations. We strip all previous conversions and re-apply the new unit now.
This includes the first step towards refactoring out the actual unit definitions from the logic that handles the CT checking.
The idea is to generate everything from a macro declaration that at some point will live in a
si_system.nim
file or something. Other systems can then be added that define their own units.For that to become properly useful, we also need to generate the
QuantityKind
,UnitKind
andBaseUnitKind
as well as the related procedures from some declarative context.Once these things are done however (and a general refactor of parsing / declaration / math / etc) has been done, general unit systems should be plug and play.
From there adding logic that describes how different systems can interop with one another becomes possible to reason about.
Other things in this PR
sqrt
: Allows to take thesqrt
of a perfect square unit (e.g.sqrt(25.kg²) == 5.kg
)abs
: returns the absolute value of the unit*=
,+=
, ...: mutable assignment helpers. Units must conform to normal logic of course! This means e.g.*=
is only allowed between a unit and a unitless object