Skip to content

Missing arithmetic operators #761

Open
jonasstrehle wants to merge 24 commits intorelease/0.0.12from
feat/operator-mul-div
Open

Missing arithmetic operators #761
jonasstrehle wants to merge 24 commits intorelease/0.0.12from
feat/operator-mul-div

Conversation

@jonasstrehle
Copy link
Copy Markdown
Member

…ypes, so now implement them anywhere will be more easy.

…ypes, so now implement them anywhere will be more easy.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 27, 2026

Test Results (datex_macros)

14 tests   14 ✅  0s ⏱️
 3 suites   0 💤
 1 files     0 ❌

Results for commit 9b6481e.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 27, 2026

Test Results (no_std)

218 tests   218 ✅  6s ⏱️
  4 suites    0 💤
  1 files      0 ❌

Results for commit 9b6481e.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 27, 2026

Test Results (std)

233 tests   233 ✅  6s ⏱️
  4 suites    0 💤
  1 files      0 ❌

Results for commit 9b6481e.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 27, 2026

Test Results (no_std_full)

806 tests   806 ✅  10s ⏱️
  4 suites    0 💤
  1 files      0 ❌

Results for commit 9b6481e.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 27, 2026

Test Results (std_full)

825 tests   825 ✅  12s ⏱️
  4 suites    0 💤
  1 files      0 ❌

Results for commit 9b6481e.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 27, 2026

🐰 Bencher Report

Branchfeat/operator-mul-div
Testbedubuntu-latest
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
nanoseconds (ns)
(Result Δ%)
Upper Boundary
nanoseconds (ns)
(Limit %)
dxb to json/test1.json📈 view plot
🚷 view threshold
68,683.00 ns
(+0.67%)Baseline: 68,228.70 ns
110,877.17 ns
(61.95%)
dxb to json/test2.json📈 view plot
🚷 view threshold
18,542,000.00 ns
(+14.55%)Baseline: 16,187,100.00 ns
31,137,986.22 ns
(59.55%)
dxb to runtime value/test1.json📈 view plot
🚷 view threshold
39,526.00 ns
(-0.59%)Baseline: 39,760.60 ns
63,909.50 ns
(61.85%)
dxb to runtime value/test2.json📈 view plot
🚷 view threshold
10,750,000.00 ns
(-2.45%)Baseline: 11,019,700.00 ns
17,035,511.13 ns
(63.10%)
json to dxb/test1.json📈 view plot
🚷 view threshold
64,948.00 ns
(-84.42%)Baseline: 416,940.80 ns
1,276,323.07 ns
(5.09%)
json to dxb/test2.json📈 view plot
🚷 view threshold
20,687,000.00 ns
(-83.61%)Baseline: 126,231,300.00 ns
365,090,360.46 ns
(5.67%)
json to runtime value datex auto static detection/test1.json📈 view plot
🚷 view threshold
92,192.00 ns
(-78.83%)Baseline: 435,458.10 ns
1,257,780.93 ns
(7.33%)
json to runtime value datex auto static detection/test2.json📈 view plot
🚷 view threshold
30,058,000.00 ns
(-77.86%)Baseline: 135,757,600.00 ns
362,440,556.27 ns
(8.29%)
json to runtime value datex forced static/test1.json📈 view plot
🚷 view threshold
77,101.00 ns
(-81.62%)Baseline: 419,480.70 ns
1,275,110.77 ns
(6.05%)
json to runtime value datex forced static/test2.json📈 view plot
🚷 view threshold
25,905,000.00 ns
(-79.48%)Baseline: 126,245,800.00 ns
374,294,689.83 ns
(6.92%)
json to runtime value datex/test1.json📈 view plot
🚷 view threshold
111,770.00 ns
(-74.94%)Baseline: 445,946.00 ns
1,248,144.03 ns
(8.95%)
json to runtime value datex/test2.json📈 view plot
🚷 view threshold
32,547,000.00 ns
(-76.23%)Baseline: 136,913,300.00 ns
372,400,041.62 ns
(8.74%)
json to runtime value json_syntax/test1.json📈 view plot
🚷 view threshold
11,752.00 ns
(-32.80%)Baseline: 17,487.30 ns
30,151.27 ns
(38.98%)
json to runtime value json_syntax/test2.json📈 view plot
🚷 view threshold
4,231,600.00 ns
(-26.92%)Baseline: 5,790,340.00 ns
9,270,799.74 ns
(45.64%)
json to runtime value serde_json/test1.json📈 view plot
🚷 view threshold
4,662.60 ns
(-20.10%)Baseline: 5,835.67 ns
8,058.23 ns
(57.86%)
json to runtime value serde_json/test2.json📈 view plot
🚷 view threshold
1,687,600.00 ns
(-15.78%)Baseline: 2,003,850.00 ns
2,583,725.29 ns
(65.32%)
runtime init📈 view plot
🚷 view threshold
0.31 ns
(-100.00%)Baseline: 101,757.03 ns
1,033,065.87 ns
(0.00%)
runtime value to dxb/test1.json📈 view plot
🚷 view threshold
4,055.20 ns
(+1.03%)Baseline: 4,014.01 ns
8,296.46 ns
(48.88%)
runtime value to dxb/test2.json📈 view plot
🚷 view threshold
1,143,200.00 ns
(+5.92%)Baseline: 1,079,335.00 ns
2,314,164.21 ns
(49.40%)
runtime value to json datex/test1.json📈 view plot
🚷 view threshold
72,462.00 ns
(-1.02%)Baseline: 73,210.30 ns
121,363.17 ns
(59.71%)
runtime value to json datex/test2.json📈 view plot
🚷 view threshold
19,603,000.00 ns
(+11.75%)Baseline: 17,541,900.00 ns
34,634,050.54 ns
(56.60%)
runtime value to json json_syntax/test1.json📈 view plot
🚷 view threshold
6,224.20 ns
(-33.98%)Baseline: 9,427.65 ns
15,551.86 ns
(40.02%)
runtime value to json json_syntax/test2.json📈 view plot
🚷 view threshold
2,639,600.00 ns
(-34.33%)Baseline: 4,019,720.00 ns
6,527,691.85 ns
(40.44%)
runtime value to json serde_json/test1.json📈 view plot
🚷 view threshold
1,587.50 ns
(-37.80%)Baseline: 2,552.38 ns
5,203.71 ns
(30.51%)
runtime value to json serde_json/test2.json📈 view plot
🚷 view threshold
480,180.00 ns
(-44.64%)Baseline: 867,309.00 ns
1,813,101.71 ns
(26.48%)
🐰 View full continuous benchmarking report in Bencher

Comment thread crates/datex-core/src/values/core_value.rs Outdated
Comment thread crates/datex-core/src/values/core_value.rs Outdated
@jonasstrehle jonasstrehle added this to the Release 0.0.11 milestone Mar 27, 2026
@jonasstrehle jonasstrehle marked this pull request as draft March 27, 2026 14:41
Comment thread crates/datex-core/src/values/value.rs Outdated
Comment thread crates/datex-core/src/values/core_values/decimal/mod.rs
Comment thread crates/datex-core/src/values/core_values/decimal/mod.rs
Comment thread crates/datex-core/src/values/core_values/decimal/mod.rs Outdated
@jonasstrehle jonasstrehle marked this pull request as ready for review March 27, 2026 14:45
@Vasyl-Trefilov
Copy link
Copy Markdown
Collaborator

Vasyl-Trefilov commented Mar 27, 2026

Test (datex-macros) / Test (datex-macros) (pull_request)
this is not my fail, its some macros, I never ever touched it
screenshot_20260327_202409

@Vasyl-Trefilov Vasyl-Trefilov requested a review from benStre April 21, 2026 15:17
Comment thread crates/datex-core/src/values/core_values/set.rs Outdated
Comment thread crates/datex-core/src/values/core_values/set.rs
Comment thread crates/datex-core/src/values/core_values/set.rs Outdated
Comment thread crates/datex-core/src/values/core_values/set.rs Outdated
Comment thread crates/datex-core/src/values/core_values/set.rs
@@ -1,3 +1,30 @@
//! [`Integer`] is precise number that can be used for very fast and cheep Math operations that doesnt need
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Avoid backticks for linked modules. Prefer [Integer] over [`Integer`]

}

#[test]
fn doc_test() {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

rename eq. test

}

impl Mul for TypedInteger {
type Output = Option<TypedInteger>;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Use wrapped instead, and not return a option but TypedInteger

TypedInteger::I8(v1) => TypedInteger::I8(match rhs {
TypedInteger::I8(v2) => v1.checked_mul(v2)?,
TypedInteger::I16(v2) => {
i8::try_from((v1 as i16).checked_mul(v2)?).ok()?
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

move to checked_mul and implement a non fallible wrapped_mul


impl Neg for Value {
impl Mul for Value {
type Output = Result<Value, ValueError>;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Should not be an error

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Error where? Or ths microsoft or I am dumb

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

impl Mul for Value {
    type Output = Result<Value, ValueError>; // here it should be Value and not Result

as multiplication can never fail, we can transition the Result<X, Y> to X.
Only Rem and Div might fail, as divisions by zero for integers can occur. For decimals we never expect errors for all arithmentic operators.

@@ -61,84 +73,183 @@ pub enum InstructionCode {

To allow for serialization of the new instruction and it's potential payload, it
might be necessary to add a new entry to the `Instruction` enum in the
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

new entry to either RegularInstruction enum or TypeInstruction enum, not to Instruction enum directly

might be necessary to add a new entry to the `Instruction` enum in the
[`datex-core/src/global/protocol_structures/instructions.rs`](../../src/global/protocol_structures/instructions.rs)
file:
[`/cratesdatex-core/src/global/protocol_structures/instructions.rs`](../../crates/datex-core/src/global/protocol_structures/instructions.rs)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

crates/datex-core

```

Is, // New instruction for the `is` operator
There are two types of `Instruction`, if your `Data Type` or `Data Structure` produces a runtime value then its a `RegularInstruction` e.g.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The distinction is not completely correct. Both Type Instructions and Regular Instructions can produce "runtime values". The distinction is more between "normal" values and "type space" values.
E.g. when defining a type with

type example = integer | text

the right hand side is represented by type instructions. But when defining a normal variable with

var example = "example";

the right hand side are regular instructions

the [`datex-core/src/compiler/parser.rs`](../../src/compiler/ast_parser) module.
The parser is responsible for converting the sequence of tokens recognized by
the lexer into an Abstract Syntax Tree (AST).
If you want to understand exactly why `push_next_regular(2)` and how does it work you can either look for something that is close for your new syntax, for example you add something like `Array`, then look at `List`, or try to read each function that is used in `InstructionCode` creating to use 100% correct one
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this can be explained in the guide.
The push_next_regular just indicated how many additional instructions are guaranteed to follow after the current instruction. So e.g. a list with 3 elements will have the LIST instruction followed by at least 3 more instructions resolving to the 3 elements of the list.


and add there instruction how your Syntax must be converted in `ValueContainer`

Again here is `List` example
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please also specify the name of the function where this mapping must be added

Token::RightCurly => Some("}"),
Token::LeftAngle => Some("<"),
Token::RightAngle => Some(">"),
Token::SetOpen => Some("<|"),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Note: Set will probably not have a custom syntax, it will just be written as Set(...)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

100% it will not have a custom syntax, I just wanted to try to add something with custom Token, and I know and understand that special Token for Set is not the best idea

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