Skip to content

Commit c148d73

Browse files
committed
Added Grouping and Complex (Refs #51)[9]
* minor fix for integer division on bigints
1 parent aaee0a7 commit c148d73

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/cse-machine/py_interpreter.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,16 @@ const pyCmdEvaluators: { [type: string]: CmdEvaluator } = {
131131
control.push(boolOp.left);
132132
},
133133

134+
'Grouping': (command, context, control) => {
135+
const groupingNode = command as ExprNS.Grouping;
136+
control.push(groupingNode.expression);
137+
},
138+
139+
'Complex': (command, context, control, stash) => {
140+
const complexNode = command as ExprNS.Complex;
141+
stash.push({ type: 'complex', value: complexNode.value });
142+
},
143+
134144
'None': (command, context, control, stash, isPrelude) => {
135145
stash.push({ type: 'undefined' });
136146
},

src/cse-machine/py_operators.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ export function evaluateUnaryExpression(operator: TokenType, value: Value, comma
265265
}
266266
default:
267267
// handleRuntimeError(context, new UnsupportedOperandTypeError(...));
268-
return { type: 'error', message: `Unsupported operand for -: '${value.type}'` };
268+
return { type: 'error', message: `TypeError: Unsupported operand for -: '${value.type}'` };
269269
}
270270

271271
case TokenType.PLUS:
@@ -278,7 +278,7 @@ export function evaluateUnaryExpression(operator: TokenType, value: Value, comma
278278
return { type: 'bigint', value: value.value ? 1n : 0n };
279279
default:
280280
// handleRuntimeError(context, new UnsupportedOperandTypeError(...));
281-
return { type: 'error', message: `Unsupported operand for +: '${value.type}'` };
281+
return { type: 'error', message: `TypeError: Unsupported operand for +: '${value.type}'` };
282282
}
283283
}
284284
return { type: 'error', message: 'Unreachable unary operator' };
@@ -399,7 +399,7 @@ export function evaluateBinaryExpression(code: string, command: ExprNS.Expr, con
399399
return { type: 'number', value: Number(l) / Number(r) };
400400
case TokenType.DOUBLESLASH:
401401
if (r === 0n) return { type: 'error', message: 'ZeroDivisionError: integer division or modulo by zero' };
402-
return { type: 'bigint', value: l / r };
402+
return { type: 'bigint', value: (l - (pythonMod(l, r) as bigint)) / r };
403403
case TokenType.PERCENT:
404404
if (r === 0n) return { type: 'error', message: 'ZeroDivisionError: integer division or modulo by zero' };
405405
return { type: 'bigint', value: pythonMod(l, r) };

0 commit comments

Comments
 (0)