Skip to content

Commit b9226ca

Browse files
committed
Evaluating expression and operators (Refs #51)[2]
* new files: py_visitor, py_utils, py_operators - to support needs for py_visitor for now, usage of any for loose type checks for now * py-interpreter - replaced dummy with PyVisitor * py_visitor - rework visit*expr to work with ExprNS and FileInputStmt * py_utils - reworked operandTranslator to work with TokenType * py_operators - reworked to change es.UnaryOperator to TokenType
1 parent 5a3f1ac commit b9226ca

File tree

4 files changed

+660
-3
lines changed

4 files changed

+660
-3
lines changed

src/cse-machine/py_interpreter.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ import { Context } from "./context";
22
import { CSEBreak, Representation, Result, Finished } from "../types";
33
import { StmtNS } from "../ast-types";
44
import { Value, ErrorValue } from "./stash";
5+
import { PyVisitor } from "./py_visitor";
56

67
type Stmt = StmtNS.Stmt;
78

89
export function PyCSEResultPromise(context: Context, value: Value): Promise<Result> {
910
return new Promise((resolve, reject) => {
1011
if (value instanceof CSEBreak) {
1112
resolve({ status: 'suspended-cse-eval', context });
12-
} else if (value.type === 'error') {
13+
} else if (value && value.type === 'error') {
1314
const errorValue = value as ErrorValue;
1415
const representation = new Representation(errorValue.message);
1516
resolve({ status: 'finished', context, value, representation } as Finished);
@@ -22,6 +23,7 @@ export function PyCSEResultPromise(context: Context, value: Value): Promise<Resu
2223

2324
export function PyEvaluate(code: string, program: Stmt, context: Context): Promise<Result> {
2425
// dummy for now, just to test getting AST from parser
25-
const dummyValue = { type: 'NoneType', value: undefined };
26-
return PyCSEResultPromise(context, dummyValue);
26+
const visitor = new PyVisitor(code, context);
27+
const result = visitor.visit(program);
28+
return PyCSEResultPromise(context, result);
2729
}

0 commit comments

Comments
 (0)