@sdeverywhere/compile 0.7.11 → 0.7.12
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 +0 -4
- package/src/_shared/read-dat.js +11 -2
- package/src/generate/code-gen.js +21 -25
- package/src/model/model.js +3 -17
- package/src/model/toposort.js +1 -1
package/package.json
CHANGED
package/src/_shared/helpers.js
CHANGED
package/src/_shared/read-dat.js
CHANGED
|
@@ -35,8 +35,16 @@ export async function readDat(pathname, prefix = '') {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
return new Promise(resolve => {
|
|
39
|
-
|
|
38
|
+
return new Promise((resolve, reject) => {
|
|
39
|
+
// Errors from the read stream aren't propagated by the byline package
|
|
40
|
+
// so we attach the error handler to `readStream` rather than to `stream`
|
|
41
|
+
let readStream = fs.createReadStream(pathname, 'utf8')
|
|
42
|
+
let stream = byline(readStream)
|
|
43
|
+
readStream.on('error', e => {
|
|
44
|
+
stream.destroy()
|
|
45
|
+
reject(new Error(`Failed to read dat file: ${e.message}`))
|
|
46
|
+
})
|
|
47
|
+
|
|
40
48
|
stream.on('data', line => {
|
|
41
49
|
let values = splitDatLine(line)
|
|
42
50
|
if (values.length === 1) {
|
|
@@ -63,6 +71,7 @@ export async function readDat(pathname, prefix = '') {
|
|
|
63
71
|
lineNum++
|
|
64
72
|
// if (lineNum % 1e5 === 0) console.log(num(lineNum).format('0,0'))
|
|
65
73
|
})
|
|
74
|
+
|
|
66
75
|
stream.on('end', () => {
|
|
67
76
|
addValues()
|
|
68
77
|
resolve(log)
|
package/src/generate/code-gen.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as R from 'ramda'
|
|
2
2
|
|
|
3
|
-
import { asort, lines, strlist,
|
|
3
|
+
import { asort, lines, strlist, mapIndexed } from '../_shared/helpers.js'
|
|
4
4
|
import { sub, allDimensions, allMappings, subscriptFamilies } from '../_shared/subscript.js'
|
|
5
5
|
import Model from '../model/model.js'
|
|
6
6
|
|
|
@@ -37,30 +37,26 @@ let codeGenerator = (parsedModel, opts) => {
|
|
|
37
37
|
function generate() {
|
|
38
38
|
// Read variables and subscript ranges from the model parse tree.
|
|
39
39
|
// This is the main entry point for code generation and is called just once.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return code
|
|
61
|
-
}
|
|
62
|
-
} catch (e) {
|
|
63
|
-
abend(e)
|
|
40
|
+
Model.read(parsedModel, spec, extData, directData, modelDirname)
|
|
41
|
+
// In list mode, print variables to the console instead of generating code.
|
|
42
|
+
if (operations.includes('printRefIdTest')) {
|
|
43
|
+
Model.printRefIdTest()
|
|
44
|
+
}
|
|
45
|
+
if (operations.includes('printRefGraph')) {
|
|
46
|
+
Model.printRefGraph(opts.varname)
|
|
47
|
+
}
|
|
48
|
+
if (operations.includes('convertNames')) {
|
|
49
|
+
// Do not generate output, but leave the results of model analysis.
|
|
50
|
+
}
|
|
51
|
+
if (operations.includes('generateC')) {
|
|
52
|
+
// Generate code for each variable in the proper order.
|
|
53
|
+
let code = emitDeclCode()
|
|
54
|
+
code += emitInitLookupsCode()
|
|
55
|
+
code += emitInitConstantsCode()
|
|
56
|
+
code += emitInitLevelsCode()
|
|
57
|
+
code += emitEvalCode()
|
|
58
|
+
code += emitIOCode()
|
|
59
|
+
return code
|
|
64
60
|
}
|
|
65
61
|
}
|
|
66
62
|
|
package/src/model/model.js
CHANGED
|
@@ -454,9 +454,7 @@ function removeUnusedVariables(spec) {
|
|
|
454
454
|
recordUsedVariable(refVar)
|
|
455
455
|
recordRefsOfVariable(refVar)
|
|
456
456
|
} else {
|
|
457
|
-
|
|
458
|
-
console.error(v)
|
|
459
|
-
process.exit(1)
|
|
457
|
+
throw new Error(`No var found for ${refId} when recording references for ${v.varName}`)
|
|
460
458
|
}
|
|
461
459
|
}
|
|
462
460
|
}
|
|
@@ -877,13 +875,7 @@ function sortVarsOfType(varType) {
|
|
|
877
875
|
// Sort into an lhs dependency list.
|
|
878
876
|
if (PRINT_AUX_GRAPH) printDepsGraph(graph, 'AUX')
|
|
879
877
|
if (PRINT_LEVEL_GRAPH) printDepsGraph(graph, 'LEVEL')
|
|
880
|
-
let deps
|
|
881
|
-
try {
|
|
882
|
-
deps = toposort(graph).reverse()
|
|
883
|
-
} catch (e) {
|
|
884
|
-
console.error(e.message)
|
|
885
|
-
process.exit(1)
|
|
886
|
-
}
|
|
878
|
+
let deps = toposort(graph).reverse()
|
|
887
879
|
|
|
888
880
|
// Turn the dependency-sorted var name list into a var list.
|
|
889
881
|
let sortedVars = varsOfType(
|
|
@@ -978,13 +970,7 @@ function sortInitVars() {
|
|
|
978
970
|
if (PRINT_INIT_GRAPH) printDepsGraph(graph, 'INIT')
|
|
979
971
|
|
|
980
972
|
// Sort into a reference id dependency list.
|
|
981
|
-
let deps
|
|
982
|
-
try {
|
|
983
|
-
deps = toposort(graph).reverse()
|
|
984
|
-
} catch (e) {
|
|
985
|
-
console.error(e.message)
|
|
986
|
-
process.exit(1)
|
|
987
|
-
}
|
|
973
|
+
let deps = toposort(graph).reverse()
|
|
988
974
|
|
|
989
975
|
// Turn the reference id list into a var list.
|
|
990
976
|
let sortedVars = R.map(refId => varWithRefId(refId), deps)
|
package/src/model/toposort.js
CHANGED
|
@@ -42,7 +42,7 @@ function toposort(nodes, edges) {
|
|
|
42
42
|
} catch (e) {
|
|
43
43
|
nodeRep = ''
|
|
44
44
|
}
|
|
45
|
-
throw new Error('
|
|
45
|
+
throw new Error('Found cyclic dependency during toposort:\n' + [...predecessors].join(' →\n') + nodeRep)
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
if (!nodesHash.has(node)) {
|