@sdeverywhere/compile 0.7.3 → 0.7.5
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/_shared/helpers.js +2 -2
- package/src/generate/code-gen.js +0 -50
package/package.json
CHANGED
package/src/_shared/helpers.js
CHANGED
|
@@ -224,8 +224,8 @@ export let readCsv = (pathname, delimiter = ',') => {
|
|
|
224
224
|
delimiter,
|
|
225
225
|
columns: false,
|
|
226
226
|
trim: true,
|
|
227
|
-
skip_empty_lines:
|
|
228
|
-
skip_records_with_empty_values:
|
|
227
|
+
skip_empty_lines: false,
|
|
228
|
+
skip_records_with_empty_values: false
|
|
229
229
|
}
|
|
230
230
|
try {
|
|
231
231
|
let data = B.read(pathname)
|
package/src/generate/code-gen.js
CHANGED
|
@@ -42,7 +42,6 @@ let codeGenerator = (parseTree, opts) => {
|
|
|
42
42
|
} else if (operation === 'generateC') {
|
|
43
43
|
// Generate code for each variable in the proper order.
|
|
44
44
|
let code = emitDeclCode()
|
|
45
|
-
code += emitGetControlValuesCode()
|
|
46
45
|
code += emitInitLookupsCode()
|
|
47
46
|
code += emitInitConstantsCode()
|
|
48
47
|
code += emitInitLevelsCode()
|
|
@@ -80,55 +79,6 @@ ${dimensionMappingsSection()}
|
|
|
80
79
|
${section(Model.lookupVars())}
|
|
81
80
|
${section(Model.dataVars())}
|
|
82
81
|
|
|
83
|
-
`
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
//
|
|
87
|
-
// Control value getters section
|
|
88
|
-
//
|
|
89
|
-
function emitGetControlValuesCode() {
|
|
90
|
-
function getConstTimeValue(vensimName) {
|
|
91
|
-
const v = Model.varWithName(Model.cName(vensimName))
|
|
92
|
-
if (v && v.varType === 'const') {
|
|
93
|
-
return v.modelFormula
|
|
94
|
-
} else {
|
|
95
|
-
throw new Error(`SDE only supports ${vensimName} defined as a constant value`)
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function getSaveperValue() {
|
|
100
|
-
const v = Model.varWithName('_saveper')
|
|
101
|
-
if (v && v.varType === 'const') {
|
|
102
|
-
return v.modelFormula
|
|
103
|
-
} else if (v && v.varType === 'aux' && v.modelFormula === 'TIME STEP') {
|
|
104
|
-
return getConstTimeValue('TIME STEP')
|
|
105
|
-
} else {
|
|
106
|
-
throw new Error(`SDE only supports SAVEPER defined as TIME STEP or a constant value`)
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// For now we only allow models that have:
|
|
111
|
-
// INITIAL TIME = a constant value
|
|
112
|
-
// FINAL TIME = a constant value
|
|
113
|
-
// SAVEPER = a constant value or constant `TIME STEP`
|
|
114
|
-
// If the model does not meet these expectations, we throw an error.
|
|
115
|
-
// TODO: Loosen this up to allow for certain common constant expressions
|
|
116
|
-
const initialTimeValue = getConstTimeValue('INITIAL TIME')
|
|
117
|
-
const finalTimeValue = getConstTimeValue('FINAL TIME')
|
|
118
|
-
const saveperValue = getSaveperValue('SAVEPER')
|
|
119
|
-
|
|
120
|
-
return `
|
|
121
|
-
// Control parameter accessors
|
|
122
|
-
double getInitialTime() {
|
|
123
|
-
return ${initialTimeValue};
|
|
124
|
-
}
|
|
125
|
-
double getFinalTime() {
|
|
126
|
-
return ${finalTimeValue};
|
|
127
|
-
}
|
|
128
|
-
double getSaveper() {
|
|
129
|
-
return ${saveperValue};
|
|
130
|
-
}
|
|
131
|
-
|
|
132
82
|
`
|
|
133
83
|
}
|
|
134
84
|
|