Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new implementation of read and code gen phases based on parse package #412

Closed
chrispcampbell opened this issue Dec 5, 2023 · 0 comments · Fixed by #413 or #421
Closed

Add new implementation of read and code gen phases based on parse package #412

chrispcampbell opened this issue Dec 5, 2023 · 0 comments · Fixed by #413 or #421

Comments

@chrispcampbell
Copy link
Contributor

I recently introduced a new @sdeverywhere/parse package in #405 that adds a new format-agnostic AST structure and a new parsing layer that insulates the @sdeverywhere/compile package from antlr4-vensim.

The next step (step 2 of the transition described in that issue) is to add new alternate implementations of the read and code gen phases of the compiler using the new parse package instead of depending directly on antlr4-vensim.

This work is now mostly complete (I've been working on it in a side branch for a while). The goal was for the new implementations to be as close to 100% compatible (in terms of behavior and generated code) with the old implementations, and that goal has mostly been met (there are only a few slight differences in whitespace and use of parentheses).

My plan is to introduce the new code alongside the old code, with the new code disabled for now, but allow it to be enabled by setting a temporary environment variable (SDE_NONPUBLIC_USE_NEW_PARSE=1).

Once we are satisfied with the new code, I will file a third issue/PR to make the new code the default and remove the old implementation.

Here's the mapping of old source files to new ones in the compile package:


Preprocess phase + shared parse reader code:

  • old:
    • preprocessor.js
    • model-reader.js
    • parser.js
  • new:
    • (handled by parse package)

Read dimensions (aka subscript ranges) phase:

  • old:
    • subscript-range-reader.js
  • new:
    • read-subscripts.js (will be renamed read-dimensions.js or similar in a later branch)

Read variables phase:

  • old:
    • variable-reader.js
  • new:
    • read-variables.js

Read equations phase:

  • old:
    • equation-reader.js
  • new:
    • read-equations.js
    • read-equation-fn-*.js

Reduce equations phase:

  • old:
    • expr-reader.js
  • new:
    • reduce-variables.js (with support from parse package)

Generate code phase:

  • old:
    • equation-gen.js
    • loop-index-vars.js
    • model-lhs-reader.js
    • var-name-reader.js
  • new:
    • gen-equation.js (entrypoint that depends on the following implementation files)
      • direct-data-helpers.js
      • gen-const-list.js
      • gen-direct-const.js
      • gen-expr.js
      • gen-lookup-*.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment