@sdeverywhere/compile 0.7.14 → 0.7.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdeverywhere/compile",
3
- "version": "0.7.14",
3
+ "version": "0.7.15",
4
4
  "description": "The core Vensim to C compiler for the SDEverywhere tool suite.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -67,12 +67,12 @@ function generateSmoothLevel(v, context, argInput, argDelay, argInit, levelNumbe
67
67
  // `equation-reader.js` and modified to work with the AST instead of directly depending
68
68
  // on antlr4-vensim constructs. This logic is pretty complex so we should try to refactor
69
69
  // or at least add some more fine-grained unit tests for it.
70
- let subs = context.extractSubscriptsFromVarNames(argInput, argDelay, argInit)
71
70
 
72
- // For SMOOTH3, the previous level is the input for level number 2 and 3. Add RHS subscripts.
73
- if (levelNumber > 1 && subs.length > 0) {
74
- argInput = `${argInput}${subs}`
75
- }
71
+ // Preserve the original subscript/dimension names that were passed in. In the case of
72
+ // separated variables, the `subs` array will be replaced to include the separated subscript
73
+ // names, but we still need the original subscript/dimension names.
74
+ const origSubs = context.extractSubscriptsFromVarNames(argInput, argDelay, argInit)
75
+ let subs = origSubs
76
76
 
77
77
  let levelVarBaseName
78
78
  let levelLHS
@@ -129,5 +129,8 @@ function generateSmoothLevel(v, context, argInput, argDelay, argInit, levelNumbe
129
129
  context.defineVariable(levelEqn)
130
130
  context.addVarReference(levelVarRefId)
131
131
 
132
- return [levelVarRefId, levelVarBaseName]
132
+ // The name of the level variable returned here includes the original subscript/dimension names
133
+ // (not the separated subscript names) so that the `argInput` is correct for the 2nd and 3rd levels
134
+ const levelVarFullName = `${levelVarBaseName}${origSubs}`
135
+ return [levelVarRefId, levelVarFullName]
133
136
  }
@@ -148,7 +148,7 @@ class Context {
148
148
  }
149
149
 
150
150
  if (result.size > 1) {
151
- console.error(`ERROR: Subscripts do not agree in extractSubscriptsFromVarNames: ${[...varNames]}`)
151
+ throw new Error(`Subscripts do not agree in extractSubscriptsFromVarNames: ${[...varNames]}`)
152
152
  }
153
153
  return [...result][0] || ''
154
154
  }