@sdeverywhere/compile 0.7.8 → 0.7.9

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.8",
3
+ "version": "0.7.9",
4
4
  "description": "The core Vensim to C compiler for the SDEverywhere tool suite.",
5
5
  "type": "module",
6
6
  "files": [
@@ -9,8 +9,8 @@
9
9
  ],
10
10
  "main": "./src/index.js",
11
11
  "dependencies": {
12
- "antlr4": "4.9.2",
13
- "antlr4-vensim": "0.6.0",
12
+ "antlr4": "4.12.0",
13
+ "antlr4-vensim": "0.6.2",
14
14
  "bufx": "^1.0.5",
15
15
  "byline": "^5.0.0",
16
16
  "csv-parse": "^5.3.3",
@@ -983,8 +983,9 @@ export default class EquationGen extends ModelReader {
983
983
  // Push the var name on the stack and then emit it.
984
984
  let id = ctx.Id().getText()
985
985
  let varName = canonicalName(id)
986
+ let functionName = this.currentFunctionName()
986
987
  if (isDimension(varName)) {
987
- if (this.currentFunctionName() === '_ELMCOUNT') {
988
+ if (functionName === '_ELMCOUNT') {
988
989
  // Emit the size of the dimension in place of the dimension name.
989
990
  this.emit(`${sub(varName).size}`)
990
991
  } else {
@@ -997,8 +998,8 @@ export default class EquationGen extends ModelReader {
997
998
  }
998
999
  } else {
999
1000
  this.varNames.push(varName)
1000
- if (this.currentFunctionName() === '_VECTOR_SELECT') {
1001
- let argIndex = this.argIndexForFunctionName('_VECTOR_SELECT')
1001
+ if (functionName === '_VECTOR_SELECT') {
1002
+ let argIndex = this.argIndexForFunctionName(functionName)
1002
1003
  if (argIndex === 0) {
1003
1004
  this.vsSelectionArray = this.currentVarName()
1004
1005
  super.visitVar(ctx)
@@ -1007,30 +1008,42 @@ export default class EquationGen extends ModelReader {
1007
1008
  } else {
1008
1009
  super.visitVar(ctx)
1009
1010
  }
1010
- } else if (this.currentFunctionName() === '_VECTOR_ELM_MAP') {
1011
- if (this.argIndexForFunctionName('_VECTOR_ELM_MAP') === 1) {
1011
+ } else if (functionName === '_VECTOR_ELM_MAP') {
1012
+ if (this.argIndexForFunctionName(functionName) === 1) {
1012
1013
  this.vemOffset = this.currentVarName()
1013
1014
  }
1014
1015
  super.visitVar(ctx)
1015
- } else if (this.currentFunctionName() === '_VECTOR_SORT_ORDER') {
1016
- if (this.argIndexForFunctionName('_VECTOR_SORT_ORDER') === 0) {
1016
+ } else if (functionName === '_VECTOR_SORT_ORDER') {
1017
+ if (this.argIndexForFunctionName(functionName) === 0) {
1017
1018
  this.vsoVarName = this.currentVarName()
1018
1019
  this.vsoTmpName = newTmpVarName()
1019
1020
  this.emit(this.vsoTmpName)
1020
1021
  }
1021
1022
  super.visitVar(ctx)
1022
- } else if (this.currentFunctionName() === '_ALLOCATE_AVAILABLE') {
1023
- if (this.argIndexForFunctionName('_ALLOCATE_AVAILABLE') === 0) {
1023
+ } else if (functionName === '_ALLOCATE_AVAILABLE') {
1024
+ if (this.argIndexForFunctionName(functionName) === 0) {
1024
1025
  this.aaRequestArray = this.currentVarName()
1025
1026
  this.aaTmpName = newTmpVarName()
1026
1027
  this.emit(this.aaTmpName)
1027
- } else if (this.argIndexForFunctionName('_ALLOCATE_AVAILABLE') === 1) {
1028
+ } else if (this.argIndexForFunctionName(functionName) === 1) {
1028
1029
  this.aaPriorityArray = this.currentVarName()
1029
1030
  }
1030
1031
  super.visitVar(ctx)
1031
- } else if (this.currentFunctionName() === '_GET_DATA_BETWEEN_TIMES') {
1032
+ } else if (functionName === '_GET_DATA_BETWEEN_TIMES') {
1032
1033
  this.emit(this.currentVarName())
1033
1034
  super.visitVar(ctx)
1035
+ } else if (
1036
+ functionName === '_LOOKUP_FORWARD' ||
1037
+ functionName === '_LOOKUP_BACKWARD' ||
1038
+ functionName === '_LOOKUP_INVERT'
1039
+ ) {
1040
+ let argIndex = this.argIndexForFunctionName(functionName)
1041
+ if (argIndex === 0) {
1042
+ this.emit(this.currentVarName())
1043
+ super.visitVar(ctx)
1044
+ } else {
1045
+ emitVar()
1046
+ }
1034
1047
  } else {
1035
1048
  emitVar()
1036
1049
  }
@@ -48,13 +48,29 @@ export default class SubscriptRangeReader extends ModelReader {
48
48
  }
49
49
  }
50
50
  visitSubscriptList(ctx) {
51
- // A subscript list can appear in either a subscript range or mapping.
52
- let subscripts = R.map(id => id.getText(), ctx.Id())
53
- if (ctx.parentCtx.ruleIndex === ModelParser.RULE_subscriptRange) {
54
- this.indNames = subscripts
51
+ // Get the subscripts from each subscript index in the list.
52
+ for (let child of ctx.children) {
53
+ if (child.symbol?.type === ModelParser.Id) {
54
+ this.addSubscriptIndex(ctx, child)
55
+ }
55
56
  }
56
- if (ctx.parentCtx.ruleIndex === ModelParser.RULE_subscriptMapping) {
57
- this.mappingValue = subscripts
57
+ }
58
+ visitSubscriptDefList(ctx) {
59
+ // Subscript range definitions can have indices and numeric subscript sequences.
60
+ for (let child of ctx.children) {
61
+ if (child.symbol?.type === ModelParser.Id) {
62
+ this.addSubscriptIndex(ctx, child)
63
+ } else if (child.ruleIndex === ModelParser.RULE_subscriptSequence) {
64
+ this.visitSubscriptSequence(child)
65
+ }
66
+ }
67
+ }
68
+ addSubscriptIndex(ctx, child) {
69
+ let subscript = child.getText()
70
+ if (ctx.parentCtx.ruleIndex === ModelParser.RULE_subscriptRange) {
71
+ this.indNames.push(subscript)
72
+ } else if (ctx.parentCtx.ruleIndex === ModelParser.RULE_subscriptMapping) {
73
+ this.mappingValue.push(subscript)
58
74
  }
59
75
  }
60
76
  visitSubscriptMapping(ctx) {
@@ -74,6 +90,7 @@ export default class SubscriptRangeReader extends ModelReader {
74
90
  let prefix = matches[0][1]
75
91
  let start = parseInt(matches[0][2])
76
92
  let end = parseInt(matches[1][2])
93
+ // TODO get this to work with subscript mappings too
77
94
  for (let i = start; i <= end; i++) {
78
95
  this.indNames.push(prefix + i)
79
96
  }