@sdeverywhere/compile 0.7.16 → 0.7.17
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 +1 -1
- package/src/generate/code-gen.js +5 -15
- package/src/model/model.js +2 -3
package/package.json
CHANGED
package/src/generate/code-gen.js
CHANGED
|
@@ -17,14 +17,7 @@ let codeGenerator = (parsedModel, opts) => {
|
|
|
17
17
|
// Set to 'decl', 'init-lookups', 'eval', etc depending on the section being generated.
|
|
18
18
|
let mode = ''
|
|
19
19
|
// Set to true to output all variables when there is no model run spec.
|
|
20
|
-
let outputAllVars
|
|
21
|
-
if (spec.outputVars && spec.outputVars.length > 0) {
|
|
22
|
-
outputAllVars = false
|
|
23
|
-
} else if (spec.outputVarNames && spec.outputVarNames.length > 0) {
|
|
24
|
-
outputAllVars = false
|
|
25
|
-
} else {
|
|
26
|
-
outputAllVars = true
|
|
27
|
-
}
|
|
20
|
+
let outputAllVars = spec.outputVarNames === undefined || spec.outputVarNames.length === 0
|
|
28
21
|
// Function to generate a section of the code
|
|
29
22
|
let generateSection = R.map(v => {
|
|
30
23
|
if (parsedModel.kind === 'vensim-legacy') {
|
|
@@ -157,19 +150,19 @@ ${chunkedFunctions('evalLevels', Model.levelVars(), ' // Evaluate levels.')}
|
|
|
157
150
|
// Input/output section
|
|
158
151
|
//
|
|
159
152
|
function emitIOCode() {
|
|
160
|
-
let
|
|
161
|
-
let
|
|
153
|
+
let headerVarNames = outputAllVars ? expandedVarNames(true) : spec.outputVarNames
|
|
154
|
+
let outputVarIds = outputAllVars ? expandedVarNames() : spec.outputVars
|
|
162
155
|
mode = 'io'
|
|
163
156
|
return `void setInputs(const char* inputData) {${inputsFromStringImpl()}}
|
|
164
157
|
|
|
165
158
|
void setInputsFromBuffer(double* inputData) {${inputsFromBufferImpl()}}
|
|
166
159
|
|
|
167
160
|
const char* getHeader() {
|
|
168
|
-
return "${R.map(varName =>
|
|
161
|
+
return "${R.map(varName => varName.replace(/"/g, '\\"'), headerVarNames).join('\\t')}";
|
|
169
162
|
}
|
|
170
163
|
|
|
171
164
|
void storeOutputData() {
|
|
172
|
-
${specOutputSection(
|
|
165
|
+
${specOutputSection(outputVarIds)}
|
|
173
166
|
}
|
|
174
167
|
|
|
175
168
|
void storeOutput(size_t varIndex, size_t subIndex0, size_t subIndex1, size_t subIndex2) {
|
|
@@ -382,9 +375,6 @@ ${postStep}
|
|
|
382
375
|
}
|
|
383
376
|
return inputVars
|
|
384
377
|
}
|
|
385
|
-
function headerTitle(varName) {
|
|
386
|
-
return Model.vensimName(varName).replace(/"/g, '\\"')
|
|
387
|
-
}
|
|
388
378
|
|
|
389
379
|
return {
|
|
390
380
|
generate: generate
|
package/src/model/model.js
CHANGED
|
@@ -102,9 +102,8 @@ function read(parsedModel, spec, extData, directData, modelDirname, opts) {
|
|
|
102
102
|
if (opts?.stopAfterReadVariables) return
|
|
103
103
|
|
|
104
104
|
if (spec) {
|
|
105
|
-
// If the spec file contains `input/outputVarNames
|
|
106
|
-
//
|
|
107
|
-
// assumed to be valid C names.
|
|
105
|
+
// If the spec file contains `input/outputVarNames`, convert the full Vensim variable
|
|
106
|
+
// names to C names first so that later phases only need to work with canonical names
|
|
108
107
|
if (spec.inputVarNames) {
|
|
109
108
|
spec.inputVars = R.map(cName, spec.inputVarNames)
|
|
110
109
|
}
|