@sdeverywhere/compile 0.7.15 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sdeverywhere/compile",
3
- "version": "0.7.15",
3
+ "version": "0.7.17",
4
4
  "description": "The core Vensim to C compiler for the SDEverywhere tool suite.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -14,7 +14,7 @@
14
14
  "js-yaml": "^3.13.1",
15
15
  "ramda": "^0.27.0",
16
16
  "split-string": "^6.0.0",
17
- "xlsx": "^0.17.0"
17
+ "xlsx": "https://cdn.sheetjs.com/xlsx-0.20.2/xlsx-0.20.2.tgz"
18
18
  },
19
19
  "author": "Climate Interactive",
20
20
  "license": "MIT",
@@ -1,3 +1,4 @@
1
+ import * as fs from 'node:fs'
1
2
  import util from 'util'
2
3
  import B from 'bufx'
3
4
  import { parse as parseCsv } from 'csv-parse/sync'
@@ -23,6 +24,10 @@ let nextAuxVarSeq = 1
23
24
  // parsed csv data cache
24
25
  let csvData = new Map()
25
26
 
27
+ // Newer versions of the xlsx package require manually setting the `fs` instance
28
+ // before using the `XLSX.readFile` function
29
+ XLSX.set_fs(fs)
30
+
26
31
  // XXX: This is needed for tests due to sequence numbers being in module-level storage
27
32
  export function resetHelperState() {
28
33
  nextTmpVarSeq = 1
@@ -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 headerVars = outputAllVars ? expandedVarNames(true) : spec.outputVars
161
- let outputVars = outputAllVars ? expandedVarNames() : spec.outputVars
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 => headerTitle(varName), headerVars).join('\\t')}";
161
+ return "${R.map(varName => varName.replace(/"/g, '\\"'), headerVarNames).join('\\t')}";
169
162
  }
170
163
 
171
164
  void storeOutputData() {
172
- ${specOutputSection(outputVars)}
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
@@ -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` (with full Vensim variable names)
106
- // convert those to C names first. Otherwise, use `input/outputNames` which are already
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
  }