Skip to content

Commit 2437942

Browse files
Update implOfOperators.md
1 parent cc3ca63 commit 2437942

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
11
## Operators Implementation
2-
The implementation of the operators (+, -, *, /, ==, ===, !=, !==, &&, ||, !) are implemented in [decompiler](https://github.com/microsoft/pxt/blob/master/pxtcompiler/emitter/decompiler.ts).
3-
They are implemented by using a map, which includes the type of the operator and where it belongs.
2+
The implementation of the operators (+, -, *, /, ==, ===, !=, !==, &&, ||, !) are implemented in the [decompiler](https://github.com/microsoft/pxt/blob/master/pxtcompiler/emitter/decompiler.ts).
3+
They are implemented by using a map, which includes the type of the operator and where it belongs:
4+
``` ts
5+
const ops: pxt.Map<{ type: string; op?: string; leftName?: string; rightName?: string }> = {
6+
"+": { type: "math_arithmetic", op: "ADD" },
7+
"-": { type: "math_arithmetic", op: "MINUS" },
8+
"/": { type: "math_arithmetic", op: "DIVIDE" },
9+
"*": { type: "math_arithmetic", op: "MULTIPLY" },
10+
"**": { type: "math_arithmetic", op: "POWER" },
11+
"%": { type: "math_modulo", leftName: "DIVIDEND", rightName: "DIVISOR" },
12+
"<": { type: "logic_compare", op: "LT" },
13+
"<=": { type: "logic_compare", op: "LTE" },
14+
">": { type: "logic_compare", op: "GT" },
15+
">=": { type: "logic_compare", op: "GTE" },
16+
"==": { type: "logic_compare", op: "EQ" },
17+
"===": { type: "logic_compare", op: "EQ" },
18+
"!=": { type: "logic_compare", op: "NEQ" },
19+
"!==": { type: "logic_compare", op: "NEQ" },
20+
"&&": { type: "logic_operation", op: "AND" },
21+
"||": { type: "logic_operation", op: "OR" },
22+
}
23+
```

0 commit comments

Comments
 (0)