Skip to content

Commit

Permalink
fix: remove old implementation of read and code gen phases (#473)
Browse files Browse the repository at this point in the history
Fixes #448
  • Loading branch information
chrispcampbell authored May 20, 2024
1 parent 9c2f7d1 commit 8de0d16
Show file tree
Hide file tree
Showing 31 changed files with 185 additions and 3,206 deletions.
10 changes: 5 additions & 5 deletions examples/hello-world/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
"save-baseline": "sde-check baseline --save"
},
"dependencies": {
"@sdeverywhere/build": "^0.3.0",
"@sdeverywhere/cli": "^0.7.6",
"@sdeverywhere/plugin-check": "^0.3.0",
"@sdeverywhere/plugin-wasm": "^0.2.0",
"@sdeverywhere/plugin-worker": "^0.2.0",
"@sdeverywhere/build": "^0.3.4",
"@sdeverywhere/cli": "^0.7.23",
"@sdeverywhere/plugin-check": "^0.3.5",
"@sdeverywhere/plugin-wasm": "^0.2.3",
"@sdeverywhere/plugin-worker": "^0.2.3",
"vite": "^4.4.9"
}
}
12 changes: 6 additions & 6 deletions examples/template-default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
"packages/app"
],
"dependencies": {
"@sdeverywhere/build": "^0.3.2",
"@sdeverywhere/check-core": "^0.1.1",
"@sdeverywhere/cli": "^0.7.12",
"@sdeverywhere/plugin-check": "^0.3.4",
"@sdeverywhere/plugin-config": "^0.2.3",
"@sdeverywhere/build": "^0.3.4",
"@sdeverywhere/check-core": "^0.1.2",
"@sdeverywhere/cli": "^0.7.23",
"@sdeverywhere/plugin-check": "^0.3.5",
"@sdeverywhere/plugin-config": "^0.2.4",
"@sdeverywhere/plugin-vite": "^0.1.8",
"@sdeverywhere/plugin-wasm": "^0.2.1",
"@sdeverywhere/plugin-wasm": "^0.2.3",
"@sdeverywhere/plugin-worker": "^0.2.3"
}
}
10 changes: 5 additions & 5 deletions examples/template-minimal/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"save-baseline": "sde-check baseline --save"
},
"dependencies": {
"@sdeverywhere/build": "^0.3.2",
"@sdeverywhere/check-core": "^0.1.1",
"@sdeverywhere/cli": "^0.7.12",
"@sdeverywhere/plugin-check": "^0.3.4",
"@sdeverywhere/plugin-wasm": "^0.2.1",
"@sdeverywhere/build": "^0.3.4",
"@sdeverywhere/check-core": "^0.1.2",
"@sdeverywhere/cli": "^0.7.23",
"@sdeverywhere/plugin-check": "^0.3.5",
"@sdeverywhere/plugin-wasm": "^0.2.3",
"@sdeverywhere/plugin-worker": "^0.2.3"
}
}
36 changes: 11 additions & 25 deletions models/prune/prune_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,17 @@ expect_present "_constant_partial_2"
expect_present "_initial_partial"
expect_present "_partial"
expect_present "_test_1_result = _IF_THEN_ELSE(_input_1 == 10.0, _test_1_t, _test_1_f);"
if [[ $SDE_NONPUBLIC_USE_NEW_PARSE == "0" ]]; then
expect_present "_test_2_result = (_test_2_f);"
expect_present "_test_3_result = (_test_3_t);"
expect_present "_test_4_result = (_test_4_f);"
expect_present "_test_5_result = (_test_5_t);"
expect_present "_test_6_result = (_test_6_f);"
expect_present "_test_7_result = (_test_7_t);"
expect_present "_test_8_result = (_test_8_f);"
expect_present "_test_9_result = (_test_9_t);"
expect_present "_test_10_result = _IF_THEN_ELSE(_ABS(_test_10_cond), _test_10_t, _test_10_f);"
expect_present "_test_11_result = (_test_11_f);"
expect_present "_test_12_result = (_test_12_t);"
else
expect_present "_test_2_result = _test_2_f;"
expect_present "_test_3_result = _test_3_t;"
expect_present "_test_4_result = _test_4_f;"
expect_present "_test_5_result = _test_5_t;"
expect_present "_test_6_result = _test_6_f;"
expect_present "_test_7_result = _test_7_t;"
expect_present "_test_8_result = _test_8_f;"
expect_present "_test_9_result = _test_9_t;"
expect_present "_test_10_result = _test_10_t;"
expect_present "_test_11_result = _test_11_f;"
expect_present "_test_12_result = _test_12_t;"
fi
expect_present "_test_2_result = _test_2_f;"
expect_present "_test_3_result = _test_3_t;"
expect_present "_test_4_result = _test_4_f;"
expect_present "_test_5_result = _test_5_t;"
expect_present "_test_6_result = _test_6_f;"
expect_present "_test_7_result = _test_7_t;"
expect_present "_test_8_result = _test_8_f;"
expect_present "_test_9_result = _test_9_t;"
expect_present "_test_10_result = _test_10_t;"
expect_present "_test_11_result = _test_11_f;"
expect_present "_test_12_result = _test_12_t;"
expect_present "_test_13_result = (_test_13_t1 + _test_13_t2) \* 10.0;"

# Verify that unreferenced variables do not appear in the generated C file
Expand Down
8 changes: 6 additions & 2 deletions packages/cli/src/sde-causes.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ let causes = (model, varname, opts) => {
let directData = new Map()
let spec = parseSpec(opts.spec)
// Preprocess model text into parser input.
// TODO: The legacy `parseModel` function previously required the `preprocessModel`
// step to be performed first, but the new `parseModel` runs the preprocessor
// implicitly, so we can remove this step (and can simplify this code to use
// `parseAndGenerate` instead)
let input = preprocessModel(modelPathname, spec)
// Parse the model to get variable and subscript information.
let parseTree = parseModel(input)
let parsedModel = parseModel(input, modelDirname)
let operations = ['printRefGraph']
generateCode(parseTree, { spec, operations, extData, directData, modelDirname, varname })
generateCode(parsedModel, { spec, operations, extData, directData, modelDirname, varname })
}
export default {
command,
Expand Down
2 changes: 0 additions & 2 deletions packages/compile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
},
"dependencies": {
"@sdeverywhere/parse": "^0.1.0",
"antlr4": "4.12.0",
"antlr4-vensim": "0.6.2",
"bufx": "^1.0.5",
"byline": "^5.0.0",
"csv-parse": "^5.3.3",
Expand Down
26 changes: 8 additions & 18 deletions packages/compile/src/_tests/test-support.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { fileURLToPath } from 'url'

import type { Model } from '@sdeverywhere/parse'

import type { VensimModelParseTree } from '../parse/parser'
import { preprocessModel } from '../preprocess/preprocessor'
import { canonicalName } from '../_shared/helpers'
import { parseModel } from '../parse-and-generate'

Expand All @@ -14,12 +12,7 @@ export interface ParsedVensimModel {
root: Model
}

export interface LegacyParsedVensimModel {
kind: 'vensim-legacy'
parseTree: VensimModelParseTree
}

export type ParsedModel = ParsedVensimModel | LegacyParsedVensimModel
export type ParsedModel = ParsedVensimModel

export type DimModelName = string
export type DimCName = string
Expand Down Expand Up @@ -159,16 +152,13 @@ export function sampleModelDir(modelName: string): string {
export function parseVensimModel(modelName: string): ParsedModel {
const modelDir = sampleModelDir(modelName)
const modelFile = resolve(modelDir, `${modelName}.mdl`)
let mdlContent: string
if (process.env.SDE_NONPUBLIC_USE_NEW_PARSE !== '0') {
// Note that the new parser implicitly runs the preprocessor on the input model text,
// so we don't need to do that here. (We should make it configurable so that we can
// skip the preprocess step in `parse-and-generate.js` when the input model text has
// already been run through a preprocessor.)
mdlContent = readFileSync(modelFile, 'utf8')
} else {
mdlContent = preprocessModel(modelFile, undefined, 'genc', false)
}

// Note that the new parser implicitly runs the preprocessor on the input model text,
// so we don't need to do that here. (We should make it configurable so that we can
// skip the preprocess step in `parse-and-generate.js` when the input model text has
// already been run through a preprocessor.)
const mdlContent = readFileSync(modelFile, 'utf8')

// We currently sort the preprocessed definitions alphabetically for
// compatibility with the legacy preprocessor. Once we drop the legacy code
// we could remove this step and update the tests to use the original order.
Expand Down
7 changes: 1 addition & 6 deletions packages/compile/src/generate/code-gen.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { sub, allDimensions, allMappings, subscriptFamilies } from '../_shared/s
import Model from '../model/model.js'

import { generateEquation } from './gen-equation.js'
import EquationGen from './equation-gen.js'
import { expandVarNames } from './expand-var-names.js'

export function generateCode(parsedModel, opts) {
Expand All @@ -20,11 +19,7 @@ let codeGenerator = (parsedModel, opts) => {
let outputAllVars = spec.outputVarNames === undefined || spec.outputVarNames.length === 0
// Function to generate a section of the code
let generateSection = R.map(v => {
if (parsedModel.kind === 'vensim-legacy') {
return new EquationGen(v, extData, directData, mode, modelDirname).generate()
} else {
return generateEquation(v, mode, extData, directData, modelDirname)
}
return generateEquation(v, mode, extData, directData, modelDirname)
})
let section = R.pipe(generateSection, R.flatten, lines)
function generate() {
Expand Down
Loading

0 comments on commit 8de0d16

Please sign in to comment.