Skip to content

Commit 86d9747

Browse files
committed
Add TODO markers
1 parent 63553a7 commit 86d9747

File tree

2 files changed

+54
-26
lines changed

2 files changed

+54
-26
lines changed

packages/language/src/typesystem/arithmetic-operations.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ type ArithmeticTypeRule = {
1010
when: BinaryOperatorPredicate;
1111
then: ComputeOperationReturnType;
1212
};
13-
type ArithmeticOperator = '+' | '-' | '*' | '/' | '**';
13+
export type ArithmeticOperator = '+' | '-' | '*' | '/' | '**';
1414

1515
/** Approximation of ln(10)/ln(2) */
1616
export const DecimalToBinaryDigitsFactor = 3.32;

packages/language/src/typesystem/infer.ts

+53-25
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { assertUnreachable } from "langium";
22
import { isExpression, isNumberLiteral, isStringLiteral, Pl1AstType } from "../generated/ast";
33
import { TypesDescriptions } from "./descriptions";
4+
import { ArithmeticOperator, createArithmeticOperationTable } from "./arithmetic-operations";
45

56
export type PliAstNode = Pl1AstType[keyof Pl1AstType];
67

@@ -9,63 +10,90 @@ export interface PliTypeInferer {
910
}
1011

1112
export class DefaultPliTypeInferer implements PliTypeInferer {
13+
private inferArithmeticOperation: ({ op, lhs, rhs }: { op: ArithmeticOperator; lhs: TypesDescriptions.Arithmetic; rhs: TypesDescriptions.Arithmetic; }) => TypesDescriptions.Any | undefined;
14+
constructor() {
15+
/** @todo pass in the compiler flag RULES(X), where X = 'ans' or 'ibm' */
16+
this.inferArithmeticOperation = createArithmeticOperationTable('ans');
17+
}
1218
/** @todo multiple entry points: for Expression, VariableDecl, Entries? */
1319
inferType(node: PliAstNode): TypesDescriptions.Any | undefined {
1420
if (isExpression(node)) {
1521
switch (node.$type) {
1622
case "BinaryExpression":
17-
//@see https://www.ibm.com/docs/en/epfz/6.1?topic=operations-results-arithmetic
1823
switch (node.op) {
19-
case "!!":
20-
case "&":
21-
case "*":
22-
case "**":
2324
case "+":
2425
case "-":
26+
case "*":
2527
case "/":
28+
case "**": {
29+
//@see https://www.ibm.com/docs/en/epfz/6.1?topic=operations-results-arithmetic
30+
const op = node.op;
31+
const lhs = this.inferType(node.left);
32+
const rhs = this.inferType(node.right);
33+
if (!lhs || !rhs || !TypesDescriptions.isArithmetic(lhs) || !TypesDescriptions.isArithmetic(rhs)) {
34+
/** @todo also take care of this branch */
35+
return undefined;
36+
}
37+
return this.inferArithmeticOperation({ op, lhs, rhs })
38+
}
39+
case "<":
40+
case "<=":
41+
case "<>":
42+
case "=":
43+
case ">":
44+
case ">=": {
45+
return TypesDescriptions.Boolean;
46+
}
2647
case "^":
48+
case "!!":
49+
case "&":
2750
case "^=":
2851
case "|":
2952
case "||":
3053
case "¬":
3154
case "¬<":
3255
case "¬=":
33-
case "¬>":
34-
break;
35-
case "<":
36-
case "<=":
37-
case "<>":
38-
case "=":
39-
case ">":
40-
case ">=":
41-
return TypesDescriptions.Boolean;
56+
case "¬>": {
57+
/** @todo */
58+
return undefined;
59+
}
4260
default:
4361
assertUnreachable(node)
4462
}
45-
break;
4663
case "UnaryExpression":
4764
switch (node.op) {
4865
case "+":
49-
case "-":
50-
case "^":
51-
case "¬":
52-
break;
66+
case "-": {
67+
/** @todo what about negating vs. sign of the type */
68+
return this.inferType(node.expr);
69+
}
70+
case "^": {
71+
/** @todo */
72+
return undefined;
73+
}
74+
case "¬": {
75+
return TypesDescriptions.Boolean;
76+
}
5377
default:
5478
assertUnreachable(node)
5579
}
56-
break;
5780
case "Literal":
5881
if (isStringLiteral(node.value)) {
59-
82+
/** @todo */
83+
return undefined;
6084
} else if (isNumberLiteral(node.value)) {
61-
85+
/** @todo */
86+
return undefined;
6287
} else {
6388
assertUnreachable(node.value);
6489
}
65-
break;
66-
case "LocatorCall":
90+
case "LocatorCall": {
6791
//node.previous -> node.element
68-
break;
92+
/** @todo */
93+
return undefined;
94+
}
95+
default:
96+
assertUnreachable(node);
6997
}
7098
}
7199
return undefined;

0 commit comments

Comments
 (0)