Skip to content

Commit aaee0a7

Browse files
committed
Removed __py_{operators} and updated operators (Refs #51)[9]
* src/types.ts - updated Representation as call toPythonString is redundant * py_interpreter - removed mapOperatorToPyOperator, update binary and compare * py_operators - updated evaluateUnaryExpression, evaluateBinaryExpression, PyCompare * minor fix for the pythonMod, pyGetVariable
1 parent 6bd1db6 commit aaee0a7

File tree

5 files changed

+224
-275
lines changed

5 files changed

+224
-275
lines changed

src/cse-machine/py_interpreter.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,6 @@ export function PyCSEResultPromise(context: PyContext, value: Value): Promise<Re
3535
});
3636
}
3737

38-
function mapOperatorToPyOperator(operatorToken: Token): TokenType | string {
39-
switch (operatorToken.type) {
40-
case TokenType.PLUS: return '__py_adder';
41-
case TokenType.MINUS: return '__py_minuser';
42-
case TokenType.STAR: return '__py_multiplier';
43-
case TokenType.SLASH: return '__py_divider';
44-
case TokenType.PERCENT: return '__py_modder';
45-
case TokenType.DOUBLESTAR: return '__py_powerer';
46-
// Add other arithmetic operators as needed
47-
default: return operatorToken.type; // For comparison and unary operators
48-
}
49-
}
50-
5138
export function PyEvaluate(code: string, program: StmtNS.Stmt, context: PyContext, options: IOptions): Value {
5239
context.control = new PyControl(program);
5340
context.runtime.isRunning = true;
@@ -131,8 +118,7 @@ const pyCmdEvaluators: { [type: string]: CmdEvaluator } = {
131118

132119
'Binary': (command, context, control) => {
133120
const binary = command as ExprNS.Binary;
134-
const opStr = mapOperatorToPyOperator(binary.operator);
135-
const op_instr = instr.binOpInstr(opStr, binary);
121+
const op_instr = instr.binOpInstr(binary.operator.type, binary);
136122
control.push(op_instr);
137123
control.push(binary.right);
138124
control.push(binary.left);
@@ -167,8 +153,7 @@ const pyCmdEvaluators: { [type: string]: CmdEvaluator } = {
167153
'Compare': (command, context, control, stash, isPrelude) => {
168154
const compareNode = command as ExprNS.Compare;
169155
// For now, we only handle simple, single comparisons.
170-
const opStr = mapOperatorToPyOperator(compareNode.operator);
171-
const op_instr = instr.binOpInstr(opStr, compareNode);
156+
const op_instr = instr.binOpInstr(compareNode.operator.type, compareNode);
172157
control.push(op_instr);
173158
control.push(compareNode.right);
174159
control.push(compareNode.left);

0 commit comments

Comments
 (0)