Skip to content

Commit

Permalink
add SPLAT_ALL_INDICATORS for *IN implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
cosentino-smeup committed Jan 17, 2024
1 parent 719446a commit c37844f
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 5 deletions.
2 changes: 2 additions & 0 deletions rpgJavaInterpreter-core/src/main/antlr/RpgLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ SPLAT_FILE: '*'[fF][iI][lL][eE];
SPLAT_GETIN: '*'[gG][eE][tT][iI][nN];
SPLAT_HIVAL: '*'[hH][iI][vV][aA][lL];
SPLAT_INIT: '*'[iI][nN][iI][tT];
SPLAT_ALL_INDICATORS: '*' [iI] [nN] [ ] [ ];
SPLAT_INDICATOR : ( '*' [iI] [nN] [0-9] [0-9]
| '*' [iI] [nN] [a-zA-Z] [a-zA-Z]
| '*' [iI] [nN] '(' [0-9] [0-9] ')' );
Expand Down Expand Up @@ -1032,6 +1033,7 @@ CS_Factor2_SPLAT_GETIN : SPLAT_GETIN {35+6<= getCharPositionInLine() && getCharP
CS_Factor2_SPLAT_HIVAL : SPLAT_HIVAL {35+6<= getCharPositionInLine() && getCharPositionInLine()<=48}? -> type(SPLAT_HIVAL);
CS_Factor2_SPLAT_INIT : SPLAT_INIT {35+5<= getCharPositionInLine() && getCharPositionInLine()<=48}? -> type(SPLAT_INIT);
CS_Factor2_SPLAT_INDICATOR : SPLAT_INDICATOR {35+4<= getCharPositionInLine() && getCharPositionInLine()<=48}? -> type(SPLAT_INDICATOR);
CS_Factor2_SPLAT_ALL_INDICATORS : SPLAT_ALL_INDICATORS {35+4<= getCharPositionInLine() && getCharPositionInLine()<=48}? -> type(SPLAT_ALL_INDICATORS);
CS_Factor2_SPLAT_INZSR : SPLAT_INZSR {35+6<= getCharPositionInLine() && getCharPositionInLine()<=48}? -> type(SPLAT_INZSR);
CS_Factor2_SPLAT_IN : SPLAT_IN {35+3<= getCharPositionInLine() && getCharPositionInLine()<=48}? -> type(SPLAT_IN);
CS_Factor2_SPLAT_JOBRUN : SPLAT_JOBRUN {35+7<= getCharPositionInLine() && getCharPositionInLine()<=48}? -> type(SPLAT_JOBRUN);
Expand Down
1 change: 1 addition & 0 deletions rpgJavaInterpreter-core/src/main/antlr/RpgParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -2581,6 +2581,7 @@ SPLAT_ALL
| SPLAT_HIVAL
| SPLAT_INIT
| SPLAT_INDICATOR
| SPLAT_ALL_INDICATORS
| SPLAT_INZSR
| SPLAT_IN
| SPLAT_JOBRUN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import java.math.MathContext
import java.math.RoundingMode
import java.time.temporal.ChronoUnit
import java.time.ZoneId
import java.util.HashMap
import kotlin.math.abs
import kotlin.math.sqrt

Expand Down Expand Up @@ -676,8 +677,20 @@ class ExpressionEvaluation(
override fun eval(expression: AssignmentExpr) =
throw RuntimeException("AssignmentExpr should be handled by the interpreter: $expression")

override fun eval(expression: GlobalIndicatorExpr) =
throw RuntimeException("PredefinedGlobalIndicatorExpr should be handled by the interpreter: $expression")
override fun eval(expression: GlobalIndicatorExpr): Value {

for (i in 1..99)
if (interpreterStatus.indicators[i] == null)
interpreterStatus.indicators[i] = BooleanValue(false)
val ret = interpreterStatus.indicators.map { it.value }
return StringValue(
ret.map {
if (it.value) {
1 } else {
0
}
}.joinToString { it.toString() })
}

override fun eval(expression: ParmsExpr): Value {
return IntValue(interpreterStatus.params.toLong())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ data class IndicatorExpr(val index: IndicatorKey, override val position: Positio
@Serializable
data class GlobalIndicatorExpr(override val position: Position? = null) :
AssignableExpression(position) {
override fun size(): Int {
TODO("not implemented") // To change body of created functions use File | Settings | File Templates.
}
override fun size(): Int = 99
override fun evalWith(evaluator: Evaluator): Value = evaluator.eval(this)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,11 @@ internal fun SymbolicConstantsContext.toAst(conf: ToAstConfiguration = ToAstConf
position = position
)
}
this.SPLAT_ALL_INDICATORS() != null -> {
GlobalIndicatorExpr(
position = position
)
}
this.SPLAT_ALL() != null -> {
val content: LiteralContext = this.parent.getChild(1) as LiteralContext
AllExpr(content.toAst(conf), position)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2202,4 +2202,11 @@ Test 6
val expected = listOf("A1_OK", "A2_OK", "A3_OK", "N1_OK", "N2_OK", "N3_OK", "DS_OK", "DSA1_OK", "DSA2_OK")
assertEquals(expected, "RESET01".outputOf())
}

@Test
fun executeMOVEAIN() {
val expected = listOf("000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000")
assertASTCanBeProduced("MOVEAIN", printTree = true)
assertEquals(expected, "MOVEAIN".outputOf())
}
}
13 changes: 13 additions & 0 deletions rpgJavaInterpreter-core/src/test/resources/MOVEAIN.rpgle
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
D* £DBG_Ind S 99
D £DBG_Sch S 1 DIM(99)
*
C MOVEL *ON *IN44
C SETON 88
C* MOVEA(P) *IN £DBG_Ind
C MOVEA(P) *IN £DBG_Sch
* Expected:
* '000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000'
*
C* £DBG_Ind DSPLY
C £DBG_Sch DSPLY
C SETON LR

0 comments on commit c37844f

Please sign in to comment.