Skip to content

Conversation

lucasnyc
Copy link

@lucasnyc lucasnyc commented Sep 4, 2025

This PR begins work on Issue #51 removing the translator layer and directly interpreting Python AST in the CSE machine.

Currently, the interpreter converts Python AST into an intermediate JavaScript AST before evaluation. While functional, this extra step increases complexity and diverges from how a Python interpreter normally behaves.

Goals:

  1. Remove dependency on estree library
  2. Adapt CSE to accept and evaluate Python AST directly

@lucasnyc lucasnyc force-pushed the migration/remove_translator branch 4 times, most recently from 7dcd393 to 3d82c5c Compare September 4, 2025 09:17
* Updated index.ts with runPyAST (Python AST -> CSE)

* py_interpreter.ts in CSE (to replace interpreter.ts in the future)

* PyRunCSEMachine in pyRunner.ts

* added local.test.ts to gitignore

* naming convention for files/functions to replace old logic will start
  with "Py" --  to be renamed after full migration
@lucasnyc lucasnyc force-pushed the migration/remove_translator branch from 3d82c5c to 5a3f1ac Compare September 4, 2025 10:48
* 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
* Updated compilerOptions in tsconfig.json - target: es2016 -> es2020
    Reason: support for bigInt(0n)
* stash.ts - Reintroduce Value to be passed to visitors in pyvisitor
    Updates: Failed lol, major changes that affects stdlib in src
    Temp solution: fallback to Value : any in /cse-machine/stash.ts for now
* py_operators.ts - introduce bool for integers, string, None
  (evaluteUnaryExpression)
* py_operator.ts refactored {evaluateBinaryExpression} - cleaner sequence
    Operands: String -> Complex -> Mixed Float&/Int (arithmetic ->
    comparisons) -> Integers only
* py_visitor.ts: added visitComplexExpr
* tokenizer.ts - bug fix for TokenType.NOT to prevent crash
* py-visitor.ts - Added visitCompareExpr, visitBoolOpExpr,
  visitVariableExpr and visitNoneExpr
* py-operators.ts - refined not oprator logic to handle truthiness
                  - added specific errors for module and power operators
                    with to handle lhs or rhs operand of 0
* super small commit haha
* conductor/runner/types/PyEvaluator.ts - Updated with PyRunInContext,
  no change to the rest
* index.ts - Introduced PyRunInContext that is replacement for
  runInContext
* a small reminder: frigging initialise the PyEvaluator (UNCOMMENT) for
  local testingssssss
…[6]

* New Files: py_context.ts, py_control.ts, py_instrCreator.ts,
  py_types.ts
  Note: No logic change, only adaptation of pynodes and instr
* index.ts, pyrunner - Adjusted execution path and adaptaion of
  pycontext, pycontrol
* py_interpreter - Overhauled to support control and instr
* changes 1
* py_types -added  BoolOpInstr
* py_instrcreator - added boolOpInstr
* py_interpreter - added handler for boolop, none, variable,
* tsconfig.json: added ignoreDeprecations to for backward compatibility
  with moduleresolution
* new files: py_environment
* Introduced for simple handling of variable declarations
TODO: undeclared variable error
@lucasnyc lucasnyc force-pushed the migration/remove_translator branch from d5b7e4f to 6bd1db6 Compare September 16, 2025 02:32
* 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
* minor fix for integer division on bigints
* new files: errors/ - py_errors, py_runtimeSourceError
* replace temporary error handlign with propery runtimeHandler
* moved interpreter core functions
* TODO: other errors as needed when new handlers are introduced
*
@lucasnyc lucasnyc force-pushed the migration/remove_translator branch 2 times, most recently from ff60494 to 5de0365 Compare September 18, 2025 11:47
* removed translator.ts, not used anymore
* removed regression.test, the test is mainly for translator
* removed py_visitor - failed attempt for migration
@lucasnyc lucasnyc force-pushed the migration/remove_translator branch from 5de0365 to c8cb9fb Compare September 18, 2025 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant