From 4598a83e8eb0b6b6aabc30321a2f3ecb96c3fd44 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Wed, 29 Mar 2023 02:23:02 +0200 Subject: [PATCH] fixing new comparisons --- .../src/prog8/codegen/cpu6502/AsmGen.kt | 169 ++--- .../assignment/AugmentableAssignmentAsmGen.kt | 501 +++++++----- compiler/src/prog8/compiler/Compiler.kt | 3 +- .../compiler/astprocessing/CodeDesugarer.kt | 2 +- compiler/test/comparisons/test_compares.p8 | 493 +++++++++++- examples/test.p8 | 713 ++++++++++++++---- 6 files changed, 1484 insertions(+), 397 deletions(-) diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt index c003c5ac8..b3b8b341f 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/AsmGen.kt @@ -554,7 +554,7 @@ class AsmGen6502Internal ( translateCompareAndJumpIfTrue(condition, jump) } else { val endLabel = makeLabel("if_end") - translateCompareAndJumpIfFalse(condition, endLabel) + translateCompareOrJumpIfFalse(condition, endLabel) translate(stmt.ifScope) out(endLabel) } @@ -562,7 +562,7 @@ class AsmGen6502Internal ( // both true and else parts val elseLabel = makeLabel("if_else") val endLabel = makeLabel("if_end") - translateCompareAndJumpIfFalse(condition, elseLabel) + translateCompareOrJumpIfFalse(condition, elseLabel) translate(stmt.ifScope) jmp(endLabel) out(elseLabel) @@ -576,6 +576,7 @@ class AsmGen6502Internal ( if (stmt.elseScope.children.isEmpty()) { val jump = stmt.ifScope.children.singleOrNull() if (jump is PtJump) { + // jump somewhere if X!=0 val label = when { jump.generatedLabel!=null -> jump.generatedLabel!! jump.identifier!=null -> asmSymbolName(jump.identifier!!) @@ -583,15 +584,16 @@ class AsmGen6502Internal ( else -> throw AssemblyError("weird jump") } when(stmt.condition.type) { - in WordDatatypes -> translateWordNotEqualsJump(stmt.condition, zero, leftConst, zero, label) - in ByteDatatypes -> translateByteNotEqualsJump(stmt.condition, zero, leftConst, zero, label) + in WordDatatypes -> translateWordEqualsOrJumpElsewhere(stmt.condition, zero, leftConst, zero, label) + in ByteDatatypes -> translateByteEqualsOrJumpElsewhere(stmt.condition, zero, leftConst, zero, label) else -> throw AssemblyError("weird condition dt") } } else { + // skip the true block (=jump to end label) if X==0 val endLabel = makeLabel("if_end") when(stmt.condition.type) { - in WordDatatypes -> translateWordNotEqualsJump(stmt.condition, zero, leftConst, zero, endLabel) - in ByteDatatypes -> translateByteNotEqualsJump(stmt.condition, zero, leftConst, zero, endLabel) + in WordDatatypes -> translateWordNotEqualsOrJumpElsewhere(stmt.condition, zero, leftConst, zero, endLabel) + in ByteDatatypes -> translateByteNotEqualsOrJumpElsewhere(stmt.condition, zero, leftConst, zero, endLabel) else -> throw AssemblyError("weird condition dt") } translate(stmt.ifScope) @@ -602,8 +604,8 @@ class AsmGen6502Internal ( val elseLabel = makeLabel("if_else") val endLabel = makeLabel("if_end") when(stmt.condition.type) { - in WordDatatypes -> translateWordEqualsJump(stmt.condition, zero, leftConst, zero, elseLabel) - in ByteDatatypes -> translateByteEqualsJump(stmt.condition, zero, leftConst, zero, elseLabel) + in WordDatatypes -> translateWordNotEqualsOrJumpElsewhere(stmt.condition, zero, leftConst, zero, elseLabel) + in ByteDatatypes -> translateByteNotEqualsOrJumpElsewhere(stmt.condition, zero, leftConst, zero, elseLabel) else -> throw AssemblyError("weird condition dt") } translate(stmt.ifScope) @@ -1172,15 +1174,16 @@ $repeatLabel lda $counterVar jump.address!=null -> jump.address!!.toHex() else -> throw AssemblyError("weird jump") } - if (rightConstVal!=null && rightConstVal.number == 0.0) - testZeroAndJump(left, invertedComparisonOperator, label) + if (rightConstVal!=null && rightConstVal.number == 0.0) { + testZeroOrJumpElsewhere(left, invertedComparisonOperator, label) + } else { val leftConstVal = left as? PtNumber - testNonzeroComparisonAndJump(left, invertedComparisonOperator, right, label, leftConstVal, rightConstVal) + testNonzeroComparisonOrJumpElsewhere(left, invertedComparisonOperator, right, label, leftConstVal, rightConstVal) } } - private fun translateCompareAndJumpIfFalse(expr: PtBinaryExpression, jumpIfFalseLabel: String) { + private fun translateCompareOrJumpIfFalse(expr: PtBinaryExpression, jumpIfFalseLabel: String) { val left = expr.left val right = expr.right val operator = expr.operator @@ -1188,19 +1191,19 @@ $repeatLabel lda $counterVar val rightConstVal = right as? PtNumber if (rightConstVal!=null && rightConstVal.number == 0.0) - testZeroAndJump(left, operator, jumpIfFalseLabel) + testZeroOrJumpElsewhere(left, operator, jumpIfFalseLabel) else - testNonzeroComparisonAndJump(left, operator, right, jumpIfFalseLabel, leftConstVal, rightConstVal) + testNonzeroComparisonOrJumpElsewhere(left, operator, right, jumpIfFalseLabel, leftConstVal, rightConstVal) } - private fun testZeroAndJump( + private fun testZeroOrJumpElsewhere( left: PtExpression, operator: String, jumpIfFalseLabel: String ) { val dt = left.type if(dt in IntegerDatatypes && left is PtIdentifier) - return testVariableZeroAndJump(left, dt, operator, jumpIfFalseLabel) + return testVariableZeroOrJumpElsewhere(left, dt, operator, jumpIfFalseLabel) when(dt) { DataType.BOOL, DataType.UBYTE, DataType.UWORD -> { @@ -1286,7 +1289,7 @@ $repeatLabel lda $counterVar } } - private fun testVariableZeroAndJump(variable: PtIdentifier, dt: DataType, operator: String, jumpIfFalseLabel: String) { + private fun testVariableZeroOrJumpElsewhere(variable: PtIdentifier, dt: DataType, operator: String, jumpIfFalseLabel: String) { // optimized code if the expression is just an identifier (variable) val varname = asmVariableName(variable) when(dt) { @@ -1346,7 +1349,7 @@ $repeatLabel lda $counterVar } } - internal fun testNonzeroComparisonAndJump( + internal fun testNonzeroComparisonOrJumpElsewhere( left: PtExpression, operator: String, right: PtExpression, @@ -1359,70 +1362,70 @@ $repeatLabel lda $counterVar when (operator) { "==" -> { when (dt) { - in ByteDatatypes -> translateByteEqualsJump(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) - in WordDatatypes -> translateWordEqualsJump(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) - DataType.FLOAT -> translateFloatEqualsJump(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) - DataType.STR -> translateStringEqualsJump(left as PtIdentifier, right as PtIdentifier, jumpIfFalseLabel) + in ByteDatatypes -> translateByteEqualsOrJumpElsewhere(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) + in WordDatatypes -> translateWordEqualsOrJumpElsewhere(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) + DataType.FLOAT -> translateFloatEqualsOrJumpElsewhere(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) + DataType.STR -> translateStringEqualsOrJumpElsewhere(left as PtIdentifier, right as PtIdentifier, jumpIfFalseLabel) else -> throw AssemblyError("weird operand datatype") } } "!=" -> { when (dt) { - in ByteDatatypes -> translateByteNotEqualsJump(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) - in WordDatatypes -> translateWordNotEqualsJump(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) - DataType.FLOAT -> translateFloatNotEqualsJump(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) - DataType.STR -> translateStringNotEqualsJump(left as PtIdentifier, right as PtIdentifier, jumpIfFalseLabel) + in ByteDatatypes -> translateByteNotEqualsOrJumpElsewhere(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) + in WordDatatypes -> translateWordNotEqualsOrJumpElsewhere(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) + DataType.FLOAT -> translateFloatNotEqualsOrJumpElsewhere(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) + DataType.STR -> translateStringNotEqualsOrJumpElsewhere(left as PtIdentifier, right as PtIdentifier, jumpIfFalseLabel) else -> throw AssemblyError("weird operand datatype") } } "<" -> { when(dt) { - DataType.UBYTE -> translateUbyteLessJump(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) - DataType.BYTE -> translateByteLessJump(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) - DataType.UWORD -> translateUwordLessJump(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) - DataType.WORD -> translateWordLessJump(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) - DataType.FLOAT -> translateFloatLessJump(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) - DataType.STR -> translateStringLessJump(left as PtIdentifier, right as PtIdentifier, jumpIfFalseLabel) + DataType.UBYTE -> translateUbyteLessOrJumpElsewhere(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) + DataType.BYTE -> translateByteLessOrJumpElsewhere(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) + DataType.UWORD -> translateUwordLessOrJumpElsewhere(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) + DataType.WORD -> translateWordLessOrJumpElsewhere(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) + DataType.FLOAT -> translateFloatLessOrJumpElsewhere(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) + DataType.STR -> translateStringLessOrJumpElsewhere(left as PtIdentifier, right as PtIdentifier, jumpIfFalseLabel) else -> throw AssemblyError("weird operand datatype") } } "<=" -> { when(dt) { - DataType.UBYTE -> translateUbyteLessOrEqualJump(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) - DataType.BYTE -> translateByteLessOrEqualJump(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) - DataType.UWORD -> translateUwordLessOrEqualJump(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) - DataType.WORD -> translateWordLessOrEqualJump(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) - DataType.FLOAT -> translateFloatLessOrEqualJump(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) - DataType.STR -> translateStringLessOrEqualJump(left as PtIdentifier, right as PtIdentifier, jumpIfFalseLabel) + DataType.UBYTE -> translateUbyteLessOrEqualOrJumpElsewhere(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) + DataType.BYTE -> translateByteLessOrEqualOrJumpElsewhere(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) + DataType.UWORD -> translateUwordLessOrEqualOrJumpElsewhere(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) + DataType.WORD -> translateWordLessOrEqualOrJumpElsewhere(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) + DataType.FLOAT -> translateFloatLessOrEqualOrJumpElsewhere(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) + DataType.STR -> translateStringLessOrEqualOrJumpElsewhere(left as PtIdentifier, right as PtIdentifier, jumpIfFalseLabel) else -> throw AssemblyError("weird operand datatype") } } ">" -> { when(dt) { - DataType.UBYTE -> translateUbyteGreaterJump(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) - DataType.BYTE -> translateByteGreaterJump(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) - DataType.UWORD -> translateUwordGreaterJump(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) - DataType.WORD -> translateWordGreaterJump(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) - DataType.FLOAT -> translateFloatGreaterJump(left, right, leftConstVal,rightConstVal, jumpIfFalseLabel) - DataType.STR -> translateStringGreaterJump(left as PtIdentifier, right as PtIdentifier, jumpIfFalseLabel) + DataType.UBYTE -> translateUbyteGreaterOrJumpElsewhere(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) + DataType.BYTE -> translateByteGreaterOrJumpElsewhere(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) + DataType.UWORD -> translateUwordGreaterOrJumpElsewhere(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) + DataType.WORD -> translateWordGreaterOrJumpElsewhere(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) + DataType.FLOAT -> translateFloatGreaterOrJumpElsewhere(left, right, leftConstVal,rightConstVal, jumpIfFalseLabel) + DataType.STR -> translateStringGreaterOrJumpElsewhere(left as PtIdentifier, right as PtIdentifier, jumpIfFalseLabel) else -> throw AssemblyError("weird operand datatype") } } ">=" -> { when(dt) { - DataType.UBYTE -> translateUbyteGreaterOrEqualJump(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) - DataType.BYTE -> translateByteGreaterOrEqualJump(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) - DataType.UWORD -> translateUwordGreaterOrEqualJump(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) - DataType.WORD -> translateWordGreaterOrEqualJump(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) - DataType.FLOAT -> translateFloatGreaterOrEqualJump(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) - DataType.STR -> translateStringGreaterOrEqualJump(left as PtIdentifier, right as PtIdentifier, jumpIfFalseLabel) + DataType.UBYTE -> translateUbyteGreaterOrEqualOrJumpElsewhere(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) + DataType.BYTE -> translateByteGreaterOrEqualOrJumpElsewhere(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) + DataType.UWORD -> translateUwordGreaterOrEqualOrJumpElsewhere(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) + DataType.WORD -> translateWordGreaterOrEqualOrJumpElsewhere(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) + DataType.FLOAT -> translateFloatGreaterOrEqualOrJumpElsewhere(left, right, leftConstVal, rightConstVal, jumpIfFalseLabel) + DataType.STR -> translateStringGreaterOrEqualOrJumpElsewhere(left as PtIdentifier, right as PtIdentifier, jumpIfFalseLabel) else -> throw AssemblyError("weird operand datatype") } } } } - private fun translateFloatLessJump(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { + private fun translateFloatLessOrJumpElsewhere(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { if(leftConstVal!=null && rightConstVal!=null) { throw AssemblyError("const-compare should have been optimized away") } @@ -1467,7 +1470,7 @@ $repeatLabel lda $counterVar } } - private fun translateFloatLessOrEqualJump(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { + private fun translateFloatLessOrEqualOrJumpElsewhere(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { if(leftConstVal!=null && rightConstVal!=null) { throw AssemblyError("const-compare should have been optimized away") } @@ -1512,7 +1515,7 @@ $repeatLabel lda $counterVar } } - private fun translateFloatGreaterJump(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { + private fun translateFloatGreaterOrJumpElsewhere(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { if(leftConstVal!=null && rightConstVal!=null) { throw AssemblyError("const-compare should have been optimized away") } @@ -1557,7 +1560,7 @@ $repeatLabel lda $counterVar } } - private fun translateFloatGreaterOrEqualJump(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { + private fun translateFloatGreaterOrEqualOrJumpElsewhere(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { if(leftConstVal!=null && rightConstVal!=null) { throw AssemblyError("const-compare should have been optimized away") } @@ -1602,7 +1605,7 @@ $repeatLabel lda $counterVar } } - private fun translateUbyteLessJump(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { + private fun translateUbyteLessOrJumpElsewhere(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { fun code(cmpOperand: String) { out(" cmp $cmpOperand | bcs $jumpIfFalseLabel") @@ -1647,7 +1650,7 @@ $repeatLabel lda $counterVar return code("P8ZP_SCRATCH_B1") } - private fun translateByteLessJump(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { + private fun translateByteLessOrJumpElsewhere(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { fun code(sbcOperand: String) { out(""" @@ -1688,7 +1691,7 @@ $repeatLabel lda $counterVar return code("P8ZP_SCRATCH_B1") } - private fun translateUwordLessJump(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { + private fun translateUwordLessOrJumpElsewhere(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { fun code(msbCpyOperand: String, lsbCmpOperand: String) { out(""" @@ -1732,7 +1735,7 @@ $repeatLabel lda $counterVar return out(" jsr prog8_lib.reg_less_uw | beq $jumpIfFalseLabel") } - private fun translateWordLessJump(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { + private fun translateWordLessOrJumpElsewhere(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { fun code(msbCpyOperand: String, lsbCmpOperand: String) { out(""" @@ -1778,7 +1781,7 @@ $repeatLabel lda $counterVar return out(" jsr prog8_lib.reg_less_w | beq $jumpIfFalseLabel") } - private fun translateUbyteGreaterJump(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { + private fun translateUbyteGreaterOrJumpElsewhere(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { fun code(cmpOperand: String) { out(""" @@ -1824,7 +1827,7 @@ $repeatLabel lda $counterVar return code("P8ZP_SCRATCH_B1") } - private fun translateByteGreaterJump(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { + private fun translateByteGreaterOrJumpElsewhere(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { fun code(sbcOperand: String) { out(""" @@ -1867,7 +1870,7 @@ $repeatLabel lda $counterVar return code("P8ZP_SCRATCH_B1") } - private fun translateUwordGreaterJump(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { + private fun translateUwordGreaterOrJumpElsewhere(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { fun code(msbCpyOperand: String, lsbCmpOperand: String) { out(""" @@ -1917,7 +1920,7 @@ $repeatLabel lda $counterVar return code("P8ZP_SCRATCH_W2+1", "P8ZP_SCRATCH_W2") } - private fun translateWordGreaterJump(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { + private fun translateWordGreaterOrJumpElsewhere(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { fun code(msbCmpOperand: String, lsbCmpOperand: String) { out(""" @@ -1968,7 +1971,7 @@ $repeatLabel lda $counterVar return out(" jsr prog8_lib.reg_less_w | beq $jumpIfFalseLabel") } - private fun translateUbyteLessOrEqualJump(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { + private fun translateUbyteLessOrEqualOrJumpElsewhere(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { fun code(cmpOperand: String) { out(""" @@ -2015,7 +2018,7 @@ $repeatLabel lda $counterVar return code("P8ZP_SCRATCH_B1") } - private fun translateByteLessOrEqualJump(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { + private fun translateByteLessOrEqualOrJumpElsewhere(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { fun code(sbcOperand: String) { out(""" clc @@ -2058,7 +2061,7 @@ $repeatLabel lda $counterVar return code("P8ZP_SCRATCH_B1") } - private fun translateUwordLessOrEqualJump(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { + private fun translateUwordLessOrEqualOrJumpElsewhere(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { fun code(msbCpyOperand: String, lsbCmpOperand: String) { out(""" @@ -2110,7 +2113,7 @@ $repeatLabel lda $counterVar return out(" jsr prog8_lib.reg_lesseq_uw | beq $jumpIfFalseLabel") } - private fun translateWordLessOrEqualJump(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { + private fun translateWordLessOrEqualOrJumpElsewhere(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { fun code(leftName: String) { out(""" @@ -2165,7 +2168,7 @@ $repeatLabel lda $counterVar return out(" jsr prog8_lib.reg_lesseq_w | beq $jumpIfFalseLabel") } - private fun translateUbyteGreaterOrEqualJump(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { + private fun translateUbyteGreaterOrEqualOrJumpElsewhere(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { fun code(cmpOperand: String) { out(" cmp $cmpOperand | bcc $jumpIfFalseLabel") @@ -2208,7 +2211,7 @@ $repeatLabel lda $counterVar return code("P8ZP_SCRATCH_B1") } - private fun translateByteGreaterOrEqualJump(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { + private fun translateByteGreaterOrEqualOrJumpElsewhere(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { fun code(sbcOperand: String) { out(""" sec @@ -2248,7 +2251,7 @@ $repeatLabel lda $counterVar return code("P8ZP_SCRATCH_B1") } - private fun translateUwordGreaterOrEqualJump(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { + private fun translateUwordGreaterOrEqualOrJumpElsewhere(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { fun code(msbCpyOperand: String, lsbCmpOperand: String) { out(""" @@ -2291,7 +2294,7 @@ $repeatLabel lda $counterVar return out(" jsr prog8_lib.reg_lesseq_uw | beq $jumpIfFalseLabel") } - private fun translateWordGreaterOrEqualJump(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { + private fun translateWordGreaterOrEqualOrJumpElsewhere(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { fun code(msbCpyOperand: String, lsbCmpOperand: String) { out(""" @@ -2337,7 +2340,7 @@ $repeatLabel lda $counterVar return out(" jsr prog8_lib.reg_lesseq_w | beq $jumpIfFalseLabel") } - private fun translateByteEqualsJump(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { + private fun translateByteEqualsOrJumpElsewhere(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { fun code(cmpOperand: String) { out(" cmp $cmpOperand | bne $jumpIfFalseLabel") } @@ -2382,7 +2385,7 @@ $repeatLabel lda $counterVar out(" cmp P8ZP_SCRATCH_B1 | bne $jumpIfFalseLabel") } - private fun translateByteNotEqualsJump(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { + private fun translateByteNotEqualsOrJumpElsewhere(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { fun code(cmpOperand: String) { out(" cmp $cmpOperand | beq $jumpIfFalseLabel") @@ -2428,7 +2431,7 @@ $repeatLabel lda $counterVar return code("P8ZP_SCRATCH_B1") } - private fun translateWordEqualsJump(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { + private fun translateWordEqualsOrJumpElsewhere(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { if(rightConstVal!=null) { if(leftConstVal!=null) { if(rightConstVal!=leftConstVal) @@ -2512,7 +2515,7 @@ $repeatLabel lda $counterVar } - private fun translateWordNotEqualsJump(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { + private fun translateWordNotEqualsOrJumpElsewhere(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { if(rightConstVal!=null) { if(leftConstVal!=null) { @@ -2600,7 +2603,7 @@ $repeatLabel lda $counterVar } - private fun translateFloatEqualsJump(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { + private fun translateFloatEqualsOrJumpElsewhere(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { if(rightConstVal!=null) { if(leftConstVal!=null) { if(rightConstVal!=leftConstVal) @@ -2684,7 +2687,7 @@ $repeatLabel lda $counterVar } } - private fun translateFloatNotEqualsJump(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { + private fun translateFloatNotEqualsOrJumpElsewhere(left: PtExpression, right: PtExpression, leftConstVal: PtNumber?, rightConstVal: PtNumber?, jumpIfFalseLabel: String) { if(rightConstVal!=null) { if(leftConstVal!=null) { if(rightConstVal==leftConstVal) @@ -2769,7 +2772,7 @@ $repeatLabel lda $counterVar } } - private fun translateStringEqualsJump(left: PtIdentifier, right: PtIdentifier, jumpIfFalseLabel: String) { + private fun translateStringEqualsOrJumpElsewhere(left: PtIdentifier, right: PtIdentifier, jumpIfFalseLabel: String) { val leftNam = asmVariableName(left) val rightNam = asmVariableName(right) out(""" @@ -2780,11 +2783,10 @@ $repeatLabel lda $counterVar lda #<$leftNam ldy #>$leftNam jsr prog8_lib.strcmp_mem - cmp #0 bne $jumpIfFalseLabel""") } - private fun translateStringNotEqualsJump(left: PtIdentifier, right: PtIdentifier, jumpIfFalseLabel: String) { + private fun translateStringNotEqualsOrJumpElsewhere(left: PtIdentifier, right: PtIdentifier, jumpIfFalseLabel: String) { val leftNam = asmVariableName(left) val rightNam = asmVariableName(right) out(""" @@ -2795,11 +2797,10 @@ $repeatLabel lda $counterVar lda #<$leftNam ldy #>$leftNam jsr prog8_lib.strcmp_mem - cmp #0 beq $jumpIfFalseLabel""") } - private fun translateStringLessJump(left: PtIdentifier, right: PtIdentifier, jumpIfFalseLabel: String) { + private fun translateStringLessOrJumpElsewhere(left: PtIdentifier, right: PtIdentifier, jumpIfFalseLabel: String) { val leftNam = asmVariableName(left) val rightNam = asmVariableName(right) out(""" @@ -2813,7 +2814,7 @@ $repeatLabel lda $counterVar bpl $jumpIfFalseLabel""") } - private fun translateStringGreaterJump(left: PtIdentifier, right: PtIdentifier, jumpIfFalseLabel: String) { + private fun translateStringGreaterOrJumpElsewhere(left: PtIdentifier, right: PtIdentifier, jumpIfFalseLabel: String) { val leftNam = asmVariableName(left) val rightNam = asmVariableName(right) out(""" @@ -2828,7 +2829,7 @@ $repeatLabel lda $counterVar bmi $jumpIfFalseLabel""") } - private fun translateStringLessOrEqualJump(left: PtIdentifier, right: PtIdentifier, jumpIfFalseLabel: String) { + private fun translateStringLessOrEqualOrJumpElsewhere(left: PtIdentifier, right: PtIdentifier, jumpIfFalseLabel: String) { val leftNam = asmVariableName(left) val rightNam = asmVariableName(right) out(""" @@ -2844,7 +2845,7 @@ $repeatLabel lda $counterVar +""") } - private fun translateStringGreaterOrEqualJump(left: PtIdentifier, right: PtIdentifier, jumpIfFalseLabel: String) { + private fun translateStringGreaterOrEqualOrJumpElsewhere(left: PtIdentifier, right: PtIdentifier, jumpIfFalseLabel: String) { val leftNam = asmVariableName(left) val rightNam = asmVariableName(right) out(""" diff --git a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt index 2cd2c7f0d..e7284e706 100644 --- a/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt +++ b/codeGenCpu6502/src/prog8/codegen/cpu6502/assignment/AugmentableAssignmentAsmGen.kt @@ -668,43 +668,31 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, } "<" -> { asmgen.assignExpressionToRegister(value, RegisterOrPair.A) - asmgen.out(""" - cmp $name - bcc + - beq + - lda #1 - bne ++ -+ lda #0 -+ sta $name""") + if(dt==DataType.UBYTE) + TODO("ubyte <") + else + TODO("byte <") } "<=" -> { asmgen.assignExpressionToRegister(value, RegisterOrPair.A) - asmgen.out(""" - cmp $name - lda #0 - adc #0 - sta $name""") + if(dt==DataType.UBYTE) + TODO("ubyte <=") + else + TODO("byte <=") } ">" -> { asmgen.assignExpressionToRegister(value, RegisterOrPair.A) - asmgen.out(""" - cmp $name - bcc + - lda #0 - beq ++ -+ lda #1 -+ sta $name""") + if(dt==DataType.UBYTE) + TODO("ubyte >") + else + TODO("byte >") } ">=" -> { asmgen.assignExpressionToRegister(value, RegisterOrPair.A) - asmgen.out(""" - cmp $name - bcc + - beq + - lda #0 - beq ++ -+ lda #1 -+ sta $name""") + if(dt==DataType.UBYTE) + TODO("ubyte >=") + else + TODO("byte >=") } else -> throw AssemblyError("invalid operator for in-place modification $operator") } @@ -782,41 +770,106 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, + sta $name""") } "<" -> { - asmgen.out(""" - lda $name - cmp $otherName - bcs + - lda #1 - bne ++ -+ lda #0 -+ sta $name""") + if(dt==DataType.UBYTE) { + asmgen.out(""" + lda $name + cmp $otherName + bcc + + lda #0 + beq ++ ++ lda #1 ++ sta $name""") + } + else { + // see http://www.6502.org/tutorials/compare_beyond.html + asmgen.out(""" + lda $name + sec + sbc $otherName + bvc + + eor #$80 ++ bmi + + lda #0 + beq ++ ++ lda #1 ++ sta $name""") + } } "<=" -> { - asmgen.out(""" - lda $otherName - cmp $name - lda #0 - adc #0 - sta $name""") + if(dt==DataType.UBYTE) { + asmgen.out(""" + lda $otherName + cmp $name + bcs + + lda #0 + beq ++ ++ lda #1 ++ sta $name""") + } else { + // see http://www.6502.org/tutorials/compare_beyond.html + asmgen.out(""" + lda $name + clc + sbc $otherName + bvc + + eor #$80 ++ bmi + + lda #0 + beq ++ ++ lda #1 ++ sta $name""") + } } ">" -> { - asmgen.out(""" - lda $otherName - cmp $name - bcc + - lda #0 - beq ++ -+ lda #1 -+ sta $name""") + if(dt==DataType.UBYTE) { + asmgen.out(""" + lda $name + cmp $otherName + beq + + bcs ++ ++ lda #0 + beq ++ ++ lda #1 ++ sta $name""") + } else { + // see http://www.6502.org/tutorials/compare_beyond.html + asmgen.out(""" + lda $name + clc + sbc $otherName + bvc + + eor #$80 ++ bpl + + lda #0 + beq ++ ++ lda #1 ++ sta $name""") + } } ">=" -> { - asmgen.out(""" - lda $name - cmp $otherName - lda #0 - adc #0 - sta $name""") - } + if(dt==DataType.UBYTE) { + asmgen.out(""" + lda $name + cmp $otherName + bcs + + lda #0 + beq ++ ++ lda #1 ++ sta $name""") + } else { + // see http://www.6502.org/tutorials/compare_beyond.html + asmgen.out(""" + lda $name + sec + sbc $otherName + bvc + + eor #$80 ++ bpl + + lda #0 + beq ++ ++ lda #1 ++ sta $name""") + } } else -> throw AssemblyError("invalid operator for in-place modification $operator") } } @@ -908,40 +961,106 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, + sta $name""") } "<" -> { - asmgen.out(""" - lda $name - cmp #$value - bcs + - lda #1 - bne ++ -+ lda #0 -+ sta $name""") + if(dt==DataType.UBYTE) { + asmgen.out(""" + lda $name + cmp #$value + bcc + + lda #0 + beq ++ ++ lda #1 ++ sta $name""") + } + else { + // see http://www.6502.org/tutorials/compare_beyond.html + asmgen.out(""" + lda $name + sec + sbc #$value + bvc + + eor #$80 ++ bmi + + lda #0 + beq ++ ++ lda #1 ++ sta $name""") + } } "<=" -> { - asmgen.out(""" - lda #$value - cmp $name - lda #0 - adc #0 - sta $name""") + if(dt==DataType.UBYTE) { + asmgen.out(""" + lda #$value + cmp $name + bcs + + lda #0 + beq ++ ++ lda #1 ++ sta $name""") + } else { + // see http://www.6502.org/tutorials/compare_beyond.html + asmgen.out(""" + lda $name + clc + sbc #$value + bvc + + eor #$80 ++ bmi + + lda #0 + beq ++ ++ lda #1 ++ sta $name""") + } } ">" -> { - asmgen.out(""" - lda #$value - cmp $name - bcc + - lda #0 - beq ++ -+ lda #1 -+ sta $name""") + if(dt==DataType.UBYTE) { + asmgen.out(""" + lda $name + cmp #$value + beq + + bcs ++ ++ lda #0 + beq ++ ++ lda #1 ++ sta $name""") + } else { + // see http://www.6502.org/tutorials/compare_beyond.html + asmgen.out(""" + lda $name + clc + sbc #$value + bvc + + eor #$80 ++ bpl + + lda #0 + beq ++ ++ lda #1 ++ sta $name""") + } } ">=" -> { - asmgen.out(""" - lda $name - cmp #$value - lda #0 - adc #0 - sta $name""") + if(dt==DataType.UBYTE) { + asmgen.out(""" + lda $name + cmp #$value + bcs + + lda #0 + beq ++ ++ lda #1 ++ sta $name""") + } else { + // see http://www.6502.org/tutorials/compare_beyond.html + asmgen.out(""" + lda $name + sec + sbc #$value + bvc + + eor #$80 ++ bpl + + lda #0 + beq ++ ++ lda #1 ++ sta $name""") + } } else -> throw AssemblyError("invalid operator for in-place modification $operator") } @@ -1816,33 +1935,63 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, sta $name+1""") } "<=" -> { - val compareRoutine = if(dt==DataType.UWORD) "reg_lesseq_uw" else "reg_lesseq_w" - asmgen.out(""" + if(dt==DataType.UWORD) { + asmgen.out(""" lda $otherName ldy $otherName+1 sta P8ZP_SCRATCH_W2 sty P8ZP_SCRATCH_W2+1 lda $name ldy $name+1 - jsr prog8_lib.$compareRoutine + jsr prog8_lib.reg_lesseq_uw sta $name lda #0 sta $name+1""") + } else { + // note: reg_lesseq_w routine takes the arguments in reverse order + asmgen.out(""" + lda $name + ldy $name+1 + sta P8ZP_SCRATCH_W2 + sty P8ZP_SCRATCH_W2+1 + lda $otherName + ldy $otherName+1 + jsr prog8_lib.reg_lesseq_w + sta $name + lda #0 + sta $name+1""") + } } ">=" -> { // a>=b --> b<=a - val compareRoutine = if(dt==DataType.UWORD) "reg_lesseq_uw" else "reg_lesseq_w" - asmgen.out(""" + if(dt==DataType.UWORD) { + asmgen.out(""" lda $name ldy $name+1 sta P8ZP_SCRATCH_W2 sty P8ZP_SCRATCH_W2+1 lda $otherName ldy $otherName+1 - jsr prog8_lib.$compareRoutine + jsr prog8_lib.reg_lesseq_uw sta $name lda #0 - sta $name+1""") + sta $name+1""" + ) + } else { + // note: reg_lesseq_w routine takes the arguments in reverse order + asmgen.out(""" + lda $otherName + ldy $otherName+1 + sta P8ZP_SCRATCH_W2 + sty P8ZP_SCRATCH_W2+1 + lda $name + ldy $name+1 + jsr prog8_lib.reg_lesseq_w + sta $name + lda #0 + sta $name+1""" + ) + } } else -> throw AssemblyError("invalid operator for in-place modification $operator") } @@ -2177,9 +2326,12 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, """) } // pretty uncommon, who's going to assign a comparison boolean expresion to a float var: - "==", "!=", "<", "<=", ">", ">=" -> TODO("float-value-to-var comparisons") + "==" -> TODO("float-value-to-var comparison ==") + "!=" -> TODO("float-value-to-var comparison !=") + "<", "<=", ">", ">=" -> TODO("float-value-to-var comparisons") else -> throw AssemblyError("invalid operator for in-place float modification $operator") } + // store Fac1 back into memory asmgen.out(""" ldx #<$name ldy #>$name @@ -2232,7 +2384,67 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, """) } // pretty uncommon, who's going to assign a comparison boolean expresion to a float var: - "==", "!=", "<", "<=", ">", ">=" -> TODO("float-var-to-var comparisons") + "==" -> { + asmgen.out(""" + lda #<$name + ldy #>$name + jsr floats.MOVFM + lda #<$otherName + ldy #>$otherName + jsr floats.var_fac1_notequal_f + eor #1 + jsr floats.FREADSA""") + } + "!=" -> { + asmgen.out(""" + lda #<$name + ldy #>$name + jsr floats.MOVFM + lda #<$otherName + ldy #>$otherName + jsr floats.var_fac1_notequal_f + jsr floats.FREADSA""") + } + "<" -> { + asmgen.out(""" + lda #<$name + ldy #>$name + jsr floats.MOVFM + lda #<$otherName + ldy #>$otherName + jsr floats.var_fac1_less_f + jsr floats.FREADSA""") + } + "<=" -> { + asmgen.out(""" + lda #<$name + ldy #>$name + jsr floats.MOVFM + lda #<$otherName + ldy #>$otherName + jsr floats.var_fac1_lesseq_f + jsr floats.FREADSA""") + } + ">" -> { + asmgen.out(""" + lda #<$name + ldy #>$name + jsr floats.MOVFM + lda #<$otherName + ldy #>$otherName + jsr floats.var_fac1_greater_f + jsr floats.FREADSA""") + } + ">=" -> { + asmgen.out(""" + lda #<$name + ldy #>$name + jsr floats.MOVFM + lda #<$otherName + ldy #>$otherName + jsr floats.var_fac1_greatereq_f + jsr floats.FREADSA""") + } else -> throw AssemblyError("invalid operator for in-place float modification $operator") } // store Fac1 back into memory @@ -2299,41 +2511,22 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, asmgen.out(""" lda #<$name ldy #>$name - sta P8ZP_SCRATCH_W1 - sty P8ZP_SCRATCH_W1+1 + jsr floats.MOVFM lda #<$constValueName ldy #>$constValueName - jsr floats.vars_equal_f - bne +""") - val nameTarget = AsmAssignTarget(TargetStorageKind.VARIABLE, asmgen, DataType.FLOAT, scope, Position.DUMMY, variableAsmName = name) - assignmentAsmGen.assignConstantFloat(nameTarget, 0.0) - asmgen.out(""" - jmp ++ -+""") - assignmentAsmGen.assignConstantFloat(nameTarget, 1.0) - asmgen.out("+") - asmgen.restoreRegisterLocal(CpuRegister.X) - return + jsr floats.var_fac1_notequal_f + eor #1 + jsr floats.FREADSA""") } "!=" -> { asmgen.out(""" lda #<$name ldy #>$name - sta P8ZP_SCRATCH_W1 - sty P8ZP_SCRATCH_W1+1 + jsr floats.MOVFM lda #<$constValueName ldy #>$constValueName - jsr floats.vars_equal_f - beq +""") - val nameTarget = AsmAssignTarget(TargetStorageKind.VARIABLE, asmgen, DataType.FLOAT, scope, Position.DUMMY, variableAsmName = name) - assignmentAsmGen.assignConstantFloat(nameTarget, 0.0) - asmgen.out(""" - jmp ++ -+""") - assignmentAsmGen.assignConstantFloat(nameTarget, 1.0) - asmgen.out("+") - asmgen.restoreRegisterLocal(CpuRegister.X) - return + jsr floats.var_fac1_notequal_f + jsr floats.FREADSA""") } "<" -> { asmgen.out(""" @@ -2342,58 +2535,28 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, jsr floats.MOVFM lda #<$constValueName ldy #>$constValueName - jsr floats.FCOMP ; A = compare fac1 to mflpt in A/Y, 0=equal 1=fac1 is greater, 255=fac1 is less than - cmp #0 - bmi +""") - val nameTarget = AsmAssignTarget(TargetStorageKind.VARIABLE, asmgen, DataType.FLOAT, scope, Position.DUMMY, variableAsmName = name) - assignmentAsmGen.assignConstantFloat(nameTarget, 0.0) - asmgen.out(""" - jmp ++ -+""") - assignmentAsmGen.assignConstantFloat(nameTarget, 1.0) - asmgen.out("+") - asmgen.restoreRegisterLocal(CpuRegister.X) - return + jsr floats.var_fac1_less_f + jsr floats.FREADSA""") } "<=" -> { asmgen.out(""" - lda #<$constValueName - ldy #>$constValueName - jsr floats.MOVFM lda #<$name ldy #>$name - jsr floats.FCOMP ; A = compare fac1 to mflpt in A/Y, 0=equal 1=fac1 is greater, 255=fac1 is less than - cmp #0 - bpl +""") - val nameTarget = AsmAssignTarget(TargetStorageKind.VARIABLE, asmgen, DataType.FLOAT, scope, Position.DUMMY, variableAsmName = name) - assignmentAsmGen.assignConstantFloat(nameTarget, 0.0) - asmgen.out(""" - jmp ++ -+""") - assignmentAsmGen.assignConstantFloat(nameTarget, 1.0) - asmgen.out("+") - asmgen.restoreRegisterLocal(CpuRegister.X) - return + jsr floats.MOVFM + lda #<$constValueName + ldy #>$constValueName + jsr floats.var_fac1_lesseq_f + jsr floats.FREADSA""") } ">" -> { asmgen.out(""" - lda #<$constValueName - ldy #>$constValueName - jsr floats.MOVFM lda #<$name ldy #>$name - jsr floats.FCOMP ; A = compare fac1 to mflpt in A/Y, 0=equal 1=fac1 is greater, 255=fac1 is less than - cmp #0 - bmi +""") - val nameTarget = AsmAssignTarget(TargetStorageKind.VARIABLE, asmgen, DataType.FLOAT, scope, Position.DUMMY, variableAsmName = name) - assignmentAsmGen.assignConstantFloat(nameTarget, 0.0) - asmgen.out(""" - jmp ++ -+""") - assignmentAsmGen.assignConstantFloat(nameTarget, 1.0) - asmgen.out("+") - asmgen.restoreRegisterLocal(CpuRegister.X) - return + jsr floats.MOVFM + lda #<$constValueName + ldy #>$constValueName + jsr floats.var_fac1_greater_f + jsr floats.FREADSA""") } ">=" -> { asmgen.out(""" @@ -2402,18 +2565,8 @@ internal class AugmentableAssignmentAsmGen(private val program: PtProgram, jsr floats.MOVFM lda #<$constValueName ldy #>$constValueName - jsr floats.FCOMP ; A = compare fac1 to mflpt in A/Y, 0=equal 1=fac1 is greater, 255=fac1 is less than - cmp #0 - bpl +""") - val nameTarget = AsmAssignTarget(TargetStorageKind.VARIABLE, asmgen, DataType.FLOAT, scope, Position.DUMMY, variableAsmName = name) - assignmentAsmGen.assignConstantFloat(nameTarget, 0.0) - asmgen.out(""" - jmp ++ -+""") - assignmentAsmGen.assignConstantFloat(nameTarget, 1.0) - asmgen.out("+") - asmgen.restoreRegisterLocal(CpuRegister.X) - return + jsr floats.var_fac1_greatereq_f + jsr floats.FREADSA""") } else -> throw AssemblyError("invalid operator for in-place float modification $operator") } diff --git a/compiler/src/prog8/compiler/Compiler.kt b/compiler/src/prog8/compiler/Compiler.kt index c4f8de731..da67db0c2 100644 --- a/compiler/src/prog8/compiler/Compiler.kt +++ b/compiler/src/prog8/compiler/Compiler.kt @@ -413,7 +413,7 @@ private fun createAssemblyAndAssemble(program: PtProgram, if(compilerOptions.useNewExprCode) transformNewExpressions(program) - printAst(program, true) { println(it) } + // printAst(program, true) { println(it) } val stMaker = SymbolTableMaker(program, compilerOptions) val symbolTable = stMaker.make() @@ -561,7 +561,6 @@ private fun transformNewExpressions(program: PtProgram) { fun transform(node: PtNode, parent: PtNode) { if(node is PtBinaryExpression) { - println("BINEXPR AT ${node.position}") node.children.toTypedArray().forEach { transform(it, node) } diff --git a/compiler/src/prog8/compiler/astprocessing/CodeDesugarer.kt b/compiler/src/prog8/compiler/astprocessing/CodeDesugarer.kt index 5ed3c5578..7fa098bc1 100644 --- a/compiler/src/prog8/compiler/astprocessing/CodeDesugarer.kt +++ b/compiler/src/prog8/compiler/astprocessing/CodeDesugarer.kt @@ -79,7 +79,7 @@ if CONDITION==0 while CONDITION { STUFF } ==> _whileloop: - if CONDITION==0 goto _after + if INVERTED-CONDITION goto _after STUFF goto _whileloop _after: diff --git a/compiler/test/comparisons/test_compares.p8 b/compiler/test/comparisons/test_compares.p8 index e2ad47107..0e293eb17 100644 --- a/compiler/test/comparisons/test_compares.p8 +++ b/compiler/test/comparisons/test_compares.p8 @@ -1,12 +1,40 @@ %zeropage basicsafe %import textio +%import floats +%import string main { sub start() { + test_string() + txt.nl() + test_compare_variable() + txt.nl() + test_compare_literal() + } + + sub test_string() { + str name="john" + + if (string.compare(name, "aaa")==0) or (string.compare(name, "john")==0) or (string.compare(name, "bbb")==0) { + txt.print("name1 ok\n") + } + if (string.compare(name, "aaa")==0) or (string.compare(name, "zzz")==0) or (string.compare(name, "bbb")==0) { + txt.print("name2 fail!\n") + } + + if name=="aaa" or name=="john" or name=="bbb" + txt.print("name1b ok\n") + if name=="aaa" or name=="zzz" or name=="bbb" + txt.print("name2b fail!\n") + + } + + sub test_compare_literal() { byte b = -100 ubyte ub = 20 word w = -20000 uword uw = 2000 + float f = -100 txt.print("all 1: ") txt.print_ub(b == -100) @@ -34,7 +62,15 @@ main { txt.print_ub(uw <= 2000) txt.print_ub(uw > 1999) txt.print_ub(uw >= 2000) + txt.spc() + txt.print_ub(f == -100.0) + txt.print_ub(f != -99.0) + txt.print_ub(f < -99.0) + txt.print_ub(f <= -100.0) + txt.print_ub(f > -101.0) + txt.print_ub(f >= -100.0) txt.nl() + txt.print("all 0: ") txt.print_ub(b == -99) txt.print_ub(b != -100) @@ -61,6 +97,153 @@ main { txt.print_ub(uw <= 1999) txt.print_ub(uw > 2000) txt.print_ub(uw >= 2001) + txt.spc() + txt.print_ub(f == -99.0) + txt.print_ub(f != -100.0) + txt.print_ub(f < -100.0) + txt.print_ub(f <= -101.0) + txt.print_ub(f > -100.0) + txt.print_ub(f >= -99.0) + txt.nl() + + txt.print("all .: ") + if b == -100 txt.chrout('.') + if b != -99 txt.chrout('.') + if b < -99 txt.chrout('.') + if b <= -100 txt.chrout('.') + if b > -101 txt.chrout('.') + if b >= -100 txt.chrout('.') + if ub ==20 txt.chrout('.') + if ub !=19 txt.chrout('.') + if ub <21 txt.chrout('.') + if ub <=20 txt.chrout('.') + if ub>19 txt.chrout('.') + if ub>=20 txt.chrout('.') + txt.spc() + if w == -20000 txt.chrout('.') + if w != -19999 txt.chrout('.') + if w < -19999 txt.chrout('.') + if w <= -20000 txt.chrout('.') + if w > -20001 txt.chrout('.') + if w >= -20000 txt.chrout('.') + if uw == 2000 txt.chrout('.') + if uw != 2001 txt.chrout('.') + if uw < 2001 txt.chrout('.') + if uw <= 2000 txt.chrout('.') + if uw > 1999 txt.chrout('.') + if uw >= 2000 txt.chrout('.') + txt.spc() + if f == -100.0 txt.chrout('.') + if f != -99.0 txt.chrout('.') + if f < -99.0 txt.chrout('.') + if f <= -100.0 txt.chrout('.') + if f > -101.0 txt.chrout('.') + if f >= -100.0 txt.chrout('.') + txt.nl() + + txt.print(" no !: ") + if b == -99 txt.chrout('!') + if b != -100 txt.chrout('!') + if b < -100 txt.chrout('!') + if b <= -101 txt.chrout('!') + if b > -100 txt.chrout('!') + if b >= -99 txt.chrout('!') + if ub ==21 txt.chrout('!') + if ub !=20 txt.chrout('!') + if ub <20 txt.chrout('!') + if ub <=19 txt.chrout('!') + if ub>20 txt.chrout('!') + if ub>=21 txt.chrout('!') + txt.spc() + if w == -20001 txt.chrout('!') + if w != -20000 txt.chrout('!') + if w < -20000 txt.chrout('!') + if w <= -20001 txt.chrout('!') + if w > -20000 txt.chrout('!') + if w >= -19999 txt.chrout('!') + if uw == 1999 txt.chrout('!') + if uw != 2000 txt.chrout('!') + if uw < 2000 txt.chrout('!') + if uw <= 1999 txt.chrout('!') + if uw > 2000 txt.chrout('!') + if uw >= 2001 txt.chrout('!') + txt.spc() + if f == -99.0 txt.chrout('!') + if f != -100.0 txt.chrout('!') + if f < -100.0 txt.chrout('!') + if f <= -101.0 txt.chrout('!') + if f > -100.0 txt.chrout('!') + if f >= -99.0 txt.chrout('!') + txt.nl() + + txt.print("all .: ") + if b == -100 txt.chrout('.') else txt.chrout('!') + if b != -99 txt.chrout('.') else txt.chrout('!') + if b < -99 txt.chrout('.') else txt.chrout('!') + if b <= -100 txt.chrout('.') else txt.chrout('!') + if b > -101 txt.chrout('.') else txt.chrout('!') + if b >= -100 txt.chrout('.') else txt.chrout('!') + if ub ==20 txt.chrout('.') else txt.chrout('!') + if ub !=19 txt.chrout('.') else txt.chrout('!') + if ub <21 txt.chrout('.') else txt.chrout('!') + if ub <=20 txt.chrout('.') else txt.chrout('!') + if ub>19 txt.chrout('.') else txt.chrout('!') + if ub>=20 txt.chrout('.') else txt.chrout('!') + txt.spc() + if w == -20000 txt.chrout('.') else txt.chrout('!') + if w != -19999 txt.chrout('.') else txt.chrout('!') + if w < -19999 txt.chrout('.') else txt.chrout('!') + if w <= -20000 txt.chrout('.') else txt.chrout('!') + if w > -20001 txt.chrout('.') else txt.chrout('!') + if w >= -20000 txt.chrout('.') else txt.chrout('!') + if uw == 2000 txt.chrout('.') else txt.chrout('!') + if uw != 2001 txt.chrout('.') else txt.chrout('!') + if uw < 2001 txt.chrout('.') else txt.chrout('!') + if uw <= 2000 txt.chrout('.') else txt.chrout('!') + if uw > 1999 txt.chrout('.') else txt.chrout('!') + if uw >= 2000 txt.chrout('.') else txt.chrout('!') + txt.spc() + if f == -100.0 txt.chrout('.') else txt.chrout('!') + if f != -99.0 txt.chrout('.') else txt.chrout('!') + if f < -99.0 txt.chrout('.') else txt.chrout('!') + if f <= -100.0 txt.chrout('.') else txt.chrout('!') + if f > -101.0 txt.chrout('.') else txt.chrout('!') + if f >= -100.0 txt.chrout('.') else txt.chrout('!') + txt.nl() + + txt.print("all .: ") + if b == -99 txt.chrout('!') else txt.chrout('.') + if b != -100 txt.chrout('!') else txt.chrout('.') + if b < -100 txt.chrout('!') else txt.chrout('.') + if b <= -101 txt.chrout('!') else txt.chrout('.') + if b > -100 txt.chrout('!') else txt.chrout('.') + if b >= -99 txt.chrout('!') else txt.chrout('.') + if ub ==21 txt.chrout('!') else txt.chrout('.') + if ub !=20 txt.chrout('!') else txt.chrout('.') + if ub <20 txt.chrout('!') else txt.chrout('.') + if ub <=19 txt.chrout('!') else txt.chrout('.') + if ub>20 txt.chrout('!') else txt.chrout('.') + if ub>=21 txt.chrout('!') else txt.chrout('.') + txt.spc() + if w == -20001 txt.chrout('!') else txt.chrout('.') + if w != -20000 txt.chrout('!') else txt.chrout('.') + if w < -20000 txt.chrout('!') else txt.chrout('.') + if w <= -20001 txt.chrout('!') else txt.chrout('.') + if w > -20000 txt.chrout('!') else txt.chrout('.') + if w >= -19999 txt.chrout('!') else txt.chrout('.') + if uw == 1999 txt.chrout('!') else txt.chrout('.') + if uw != 2000 txt.chrout('!') else txt.chrout('.') + if uw < 2000 txt.chrout('!') else txt.chrout('.') + if uw <= 1999 txt.chrout('!') else txt.chrout('.') + if uw > 2000 txt.chrout('!') else txt.chrout('.') + if uw >= 2001 txt.chrout('!') else txt.chrout('.') + txt.spc() + if f == -99.0 txt.chrout('!') else txt.chrout('.') + if f != -100.0 txt.chrout('!') else txt.chrout('.') + if f < -100.0 txt.chrout('!') else txt.chrout('.') + if f <= -101.0 txt.chrout('!') else txt.chrout('.') + if f > -100.0 txt.chrout('!') else txt.chrout('.') + if f >= -99.0 txt.chrout('!') else txt.chrout('.') txt.nl() @@ -112,9 +295,311 @@ main { txt.print_uw(uw) txt.print(" 8000\n") -; float f -; while f<2.2 { -; f+=0.1 -; } + f = 0.0 + floats.print_f(f) + while f<2.2 { + f+=0.1 + floats.print_f(f) + } + floats.print_f(f) + txt.print(" 2.2\n") + } + + sub test_compare_variable() { + byte b = -100 + ubyte ub = 20 + word w = -20000 + uword uw = 2000 + float f = -100 + + byte minus_100 = -100 + byte minus_99 = -99 + byte minus_20 = -20 + byte minus_101 = -101 + ubyte nineteen = 19 + ubyte twenty = 20 + ubyte twenty1 = 21 + ubyte twohundred = 200 + float f_minus_100 = -100.0 + float f_minus_101 = -101.0 + float f_minus_99 = -99.0 + float twodottwo = 2.2 + word minus8000 = -8000 + word eightthousand = 8000 + word w_min_20000 = -20000 + word w_min_19999 = -19999 + word w_min_20001 = -20001 + uword twothousand = 2000 + uword twothousand1 = 2001 + uword nineteen99 = 1999 + + + txt.print("all 1: ") + txt.print_ub(b == minus_100) + txt.print_ub(b != minus_99) + txt.print_ub(b < minus_99) + txt.print_ub(b <= minus_100) + txt.print_ub(b > minus_101) + txt.print_ub(b >= minus_100) + txt.print_ub(ub ==twenty) + txt.print_ub(ub !=nineteen) + txt.print_ub(ub nineteen) + txt.print_ub(ub>=twenty) + txt.spc() + txt.print_ub(w == w_min_20000) + txt.print_ub(w != w_min_19999) + txt.print_ub(w < w_min_19999) + txt.print_ub(w <= w_min_20000) + txt.print_ub(w > w_min_20001) + txt.print_ub(w >= w_min_20000) + txt.print_ub(uw == twothousand) + txt.print_ub(uw != twothousand1) + txt.print_ub(uw < twothousand1) + txt.print_ub(uw <= twothousand) + txt.print_ub(uw > nineteen99) + txt.print_ub(uw >= twothousand) + txt.spc() + txt.print_ub(f == f_minus_100) + txt.print_ub(f != f_minus_99) + txt.print_ub(f < f_minus_99) + txt.print_ub(f <= f_minus_100) + txt.print_ub(f > f_minus_101) + txt.print_ub(f >= f_minus_100) + txt.nl() + + txt.print("all 0: ") + txt.print_ub(b == minus_99) + txt.print_ub(b != minus_100) + txt.print_ub(b < minus_100) + txt.print_ub(b <= minus_101) + txt.print_ub(b > minus_100) + txt.print_ub(b >= minus_99) + txt.print_ub(ub ==twenty1) + txt.print_ub(ub !=twenty) + txt.print_ub(ub twenty) + txt.print_ub(ub>=twenty1) + txt.spc() + txt.print_ub(w == w_min_20001) + txt.print_ub(w != w_min_20000) + txt.print_ub(w < w_min_20000) + txt.print_ub(w <= w_min_20001) + txt.print_ub(w > w_min_20000) + txt.print_ub(w >= w_min_19999) + txt.print_ub(uw == nineteen99) + txt.print_ub(uw != twothousand) + txt.print_ub(uw < twothousand) + txt.print_ub(uw <= nineteen99) + txt.print_ub(uw > twothousand) + txt.print_ub(uw >= twothousand1) + txt.spc() + txt.print_ub(f == f_minus_99) + txt.print_ub(f != f_minus_100) + txt.print_ub(f < f_minus_100) + txt.print_ub(f <= f_minus_101) + txt.print_ub(f > f_minus_100) + txt.print_ub(f >= f_minus_99) + txt.nl() + + txt.print("all .: ") + if b == minus_100 txt.chrout('.') + if b != minus_99 txt.chrout('.') + if b < minus_99 txt.chrout('.') + if b <= minus_100 txt.chrout('.') + if b > minus_101 txt.chrout('.') + if b >= minus_100 txt.chrout('.') + if ub == twenty txt.chrout('.') + if ub != nineteen txt.chrout('.') + if ub < twenty1 txt.chrout('.') + if ub <= twenty txt.chrout('.') + if ub> nineteen txt.chrout('.') + if ub>= twenty txt.chrout('.') + txt.spc() + if w == w_min_20000 txt.chrout('.') + if w != w_min_19999 txt.chrout('.') + if w < w_min_19999 txt.chrout('.') + if w <= w_min_20000 txt.chrout('.') + if w > w_min_20001 txt.chrout('.') + if w >= w_min_20000 txt.chrout('.') + if uw == twothousand txt.chrout('.') + if uw != twothousand1 txt.chrout('.') + if uw < twothousand1 txt.chrout('.') + if uw <= twothousand txt.chrout('.') + if uw > nineteen99 txt.chrout('.') + if uw >= twothousand txt.chrout('.') + txt.spc() + if f == f_minus_100 txt.chrout('.') + if f != f_minus_99 txt.chrout('.') + if f < f_minus_99 txt.chrout('.') + if f <= f_minus_100 txt.chrout('.') + if f > f_minus_101 txt.chrout('.') + if f >= f_minus_100 txt.chrout('.') + txt.nl() + + txt.print(" no !: ") + if b == minus_99 txt.chrout('!') + if b != minus_100 txt.chrout('!') + if b < minus_100 txt.chrout('!') + if b <= minus_101 txt.chrout('!') + if b > minus_100 txt.chrout('!') + if b >= minus_99 txt.chrout('!') + if ub == twenty1 txt.chrout('!') + if ub != twenty txt.chrout('!') + if ub < twenty txt.chrout('!') + if ub <= nineteen txt.chrout('!') + if ub> twenty txt.chrout('!') + if ub>= twenty1 txt.chrout('!') + txt.spc() + if w == w_min_20001 txt.chrout('!') + if w != w_min_20000 txt.chrout('!') + if w < w_min_20000 txt.chrout('!') + if w <= w_min_20001 txt.chrout('!') + if w > w_min_20000 txt.chrout('!') + if w >= w_min_19999 txt.chrout('!') + if uw == nineteen99 txt.chrout('!') + if uw != twothousand txt.chrout('!') + if uw < twothousand txt.chrout('!') + if uw <= nineteen99 txt.chrout('!') + if uw > twothousand txt.chrout('!') + if uw >= twothousand1 txt.chrout('!') + txt.spc() + if f == f_minus_99 txt.chrout('!') + if f != f_minus_100 txt.chrout('!') + if f < f_minus_100 txt.chrout('!') + if f <= f_minus_101 txt.chrout('!') + if f > f_minus_100 txt.chrout('!') + if f >= f_minus_99 txt.chrout('!') + txt.nl() + + txt.print("all .: ") + if b == minus_100 txt.chrout('.') else txt.chrout('!') + if b != minus_99 txt.chrout('.') else txt.chrout('!') + if b < minus_99 txt.chrout('.') else txt.chrout('!') + if b <= minus_100 txt.chrout('.') else txt.chrout('!') + if b > minus_101 txt.chrout('.') else txt.chrout('!') + if b >= minus_100 txt.chrout('.') else txt.chrout('!') + if ub == twenty txt.chrout('.') else txt.chrout('!') + if ub != nineteen txt.chrout('.') else txt.chrout('!') + if ub < twenty1 txt.chrout('.') else txt.chrout('!') + if ub <= twenty txt.chrout('.') else txt.chrout('!') + if ub> nineteen txt.chrout('.') else txt.chrout('!') + if ub>=twenty txt.chrout('.') else txt.chrout('!') + txt.spc() + if w == w_min_20000 txt.chrout('.') else txt.chrout('!') + if w != w_min_19999 txt.chrout('.') else txt.chrout('!') + if w < w_min_19999 txt.chrout('.') else txt.chrout('!') + if w <= w_min_20000 txt.chrout('.') else txt.chrout('!') + if w > w_min_20001 txt.chrout('.') else txt.chrout('!') + if w >= w_min_20000 txt.chrout('.') else txt.chrout('!') + if uw == twothousand txt.chrout('.') else txt.chrout('!') + if uw != twothousand1 txt.chrout('.') else txt.chrout('!') + if uw < twothousand1 txt.chrout('.') else txt.chrout('!') + if uw <= twothousand txt.chrout('.') else txt.chrout('!') + if uw > nineteen99 txt.chrout('.') else txt.chrout('!') + if uw >= twothousand txt.chrout('.') else txt.chrout('!') + txt.spc() + if f == f_minus_100 txt.chrout('.') else txt.chrout('!') + if f != f_minus_99 txt.chrout('.') else txt.chrout('!') + if f < f_minus_99 txt.chrout('.') else txt.chrout('!') + if f <= f_minus_100 txt.chrout('.') else txt.chrout('!') + if f > f_minus_101 txt.chrout('.') else txt.chrout('!') + if f >= f_minus_100 txt.chrout('.') else txt.chrout('!') + txt.nl() + + txt.print("all .: ") + if b == minus_99 txt.chrout('!') else txt.chrout('.') + if b != minus_100 txt.chrout('!') else txt.chrout('.') + if b < minus_100 txt.chrout('!') else txt.chrout('.') + if b <= minus_101 txt.chrout('!') else txt.chrout('.') + if b > minus_100 txt.chrout('!') else txt.chrout('.') + if b >= minus_99 txt.chrout('!') else txt.chrout('.') + if ub == twenty1 txt.chrout('!') else txt.chrout('.') + if ub !=twenty txt.chrout('!') else txt.chrout('.') + if ub twenty txt.chrout('!') else txt.chrout('.') + if ub>= twenty1 txt.chrout('!') else txt.chrout('.') + txt.spc() + if w == w_min_20001 txt.chrout('!') else txt.chrout('.') + if w != w_min_20000 txt.chrout('!') else txt.chrout('.') + if w < w_min_20000 txt.chrout('!') else txt.chrout('.') + if w <= w_min_20001 txt.chrout('!') else txt.chrout('.') + if w > w_min_20000 txt.chrout('!') else txt.chrout('.') + if w >= w_min_19999 txt.chrout('!') else txt.chrout('.') + if uw == nineteen99 txt.chrout('!') else txt.chrout('.') + if uw != twothousand txt.chrout('!') else txt.chrout('.') + if uw < twothousand txt.chrout('!') else txt.chrout('.') + if uw <= nineteen99 txt.chrout('!') else txt.chrout('.') + if uw > twothousand txt.chrout('!') else txt.chrout('.') + if uw >= twothousand1 txt.chrout('!') else txt.chrout('.') + txt.spc() + if f == f_minus_99 txt.chrout('!') else txt.chrout('.') + if f != f_minus_100 txt.chrout('!') else txt.chrout('.') + if f < f_minus_100 txt.chrout('!') else txt.chrout('.') + if f <= f_minus_101 txt.chrout('!') else txt.chrout('.') + if f > f_minus_100 txt.chrout('!') else txt.chrout('.') + if f >= f_minus_99 txt.chrout('!') else txt.chrout('.') + txt.nl() + + + b = minus_100 + while b <= minus_20 + b++ + txt.print_b(b) + txt.print(" -19\n") + b = minus_100 + while b < -minus_20 + b++ + txt.print_b(b) + txt.print(" -20\n") + + ub = 20 + while ub <= twohundred + ub++ + txt.print_ub(ub) + txt.print(" 201\n") + ub = 20 + while ub < twohundred + ub++ + txt.print_ub(ub) + txt.print(" 200\n") + + w = w_min_20000 + while w <= minus8000 { + w++ + } + txt.print_w(w) + txt.print(" -7999\n") + w = w_min_20000 + while w < minus8000 { + w++ + } + txt.print_w(w) + txt.print(" -8000\n") + + uw = 2000 + while uw <= eightthousand { + uw++ + } + txt.print_uw(uw) + txt.print(" 8001\n") + uw = 2000 + while uw < eightthousand { + uw++ + } + txt.print_uw(uw) + txt.print(" 8000\n") + + f = 0.0 + floats.print_f(f) + while f -101) -; txt.print_ub(b >= -100) -; txt.print_ub(ub ==20) -; txt.print_ub(ub !=19) -; txt.print_ub(ub <21) -; txt.print_ub(ub <=20) -; txt.print_ub(ub>19) -; txt.print_ub(ub>=20) -; txt.spc() -; txt.print_ub(w == -20000) -; txt.print_ub(w != -19999) -; txt.print_ub(w < -19999) -; txt.print_ub(w <= -20000) -; txt.print_ub(w > -20001) -; txt.print_ub(w >= -20000) -; txt.print_ub(uw == 2000) -; txt.print_ub(uw != 2001) -; txt.print_ub(uw < 2001) -; txt.print_ub(uw <= 2000) -; txt.print_ub(uw > 1999) -; txt.print_ub(uw >= 2000) -; txt.spc() -; txt.print_ub(f == -100.0) -; txt.print_ub(f != -99.0) -; txt.print_ub(f < -99.0) -; txt.print_ub(f <= -100.0) -; txt.print_ub(f > -101.0) -; txt.print_ub(f >= -100.0) -; txt.nl() -; -; txt.print("all 0: ") -; txt.print_ub(b == -99) -; txt.print_ub(b != -100) -; txt.print_ub(b < -100) -; txt.print_ub(b <= -101) -; txt.print_ub(b > -100) -; txt.print_ub(b >= -99) -; txt.print_ub(ub ==21) -; txt.print_ub(ub !=20) -; txt.print_ub(ub <20) -; txt.print_ub(ub <=19) -; txt.print_ub(ub>20) -; txt.print_ub(ub>=21) -; txt.spc() -; txt.print_ub(w == -20001) -; txt.print_ub(w != -20000) -; txt.print_ub(w < -20000) -; txt.print_ub(w <= -20001) -; txt.print_ub(w > -20000) -; txt.print_ub(w >= -19999) -; txt.print_ub(uw == 1999) -; txt.print_ub(uw != 2000) -; txt.print_ub(uw < 2000) -; txt.print_ub(uw <= 1999) -; txt.print_ub(uw > 2000) -; txt.print_ub(uw >= 2001) -; txt.spc() -; txt.print_ub(f == -99.0) -; txt.print_ub(f != -100.0) -; txt.print_ub(f < -100.0) -; txt.print_ub(f <= -101.0) -; txt.print_ub(f > -100.0) -; txt.print_ub(f >= -99.0) -; txt.nl() -; -; ; TODO ALL OF THE ABOVE BUT WITH A VARIABLE INSTEAD OF A CONST VALUE -; -; -; b = -100 -; while b <= -20 -; b++ -; txt.print_b(b) -; txt.print(" -19\n") -; b = -100 -; while b < -20 -; b++ -; txt.print_b(b) -; txt.print(" -20\n") -; -; ub = 20 -; while ub <= 200 -; ub++ -; txt.print_ub(ub) -; txt.print(" 201\n") -; ub = 20 -; while ub < 200 -; ub++ -; txt.print_ub(ub) -; txt.print(" 200\n") -; -; w = -20000 -; while w <= -8000 { -; w++ -; } -; txt.print_w(w) -; txt.print(" -7999\n") -; w = -20000 -; while w < -8000 { -; w++ -; } -; txt.print_w(w) -; txt.print(" -8000\n") -; -; uw = 2000 -; while uw <= 8000 { -; uw++ -; } -; txt.print_uw(uw) -; txt.print(" 8001\n") -; uw = 2000 -; while uw < 8000 { -; uw++ -; } -; txt.print_uw(uw) -; txt.print(" 8000\n") -; -; f = 0.0 -; while f<2.2 { -; f+=0.1 -; } -; floats.print_f(f) -; txt.print(" 2.2\n") + sub test_compare_literal() { + byte b = -100 + ubyte ub = 20 + word w = -20000 + uword uw = 2000 + float f = -100 + + txt.print("all 1: ") + txt.print_ub(b == -100) + txt.print_ub(b != -99) + txt.print_ub(b < -99) + txt.print_ub(b <= -100) + txt.print_ub(b > -101) + txt.print_ub(b >= -100) + txt.print_ub(ub ==20) + txt.print_ub(ub !=19) + txt.print_ub(ub <21) + txt.print_ub(ub <=20) + txt.print_ub(ub>19) + txt.print_ub(ub>=20) + txt.spc() + txt.print_ub(w == -20000) + txt.print_ub(w != -19999) + txt.print_ub(w < -19999) + txt.print_ub(w <= -20000) + txt.print_ub(w > -20001) + txt.print_ub(w >= -20000) + txt.print_ub(uw == 2000) + txt.print_ub(uw != 2001) + txt.print_ub(uw < 2001) + txt.print_ub(uw <= 2000) + txt.print_ub(uw > 1999) + txt.print_ub(uw >= 2000) + txt.spc() + txt.print_ub(f == -100.0) + txt.print_ub(f != -99.0) + txt.print_ub(f < -99.0) + txt.print_ub(f <= -100.0) + txt.print_ub(f > -101.0) + txt.print_ub(f >= -100.0) + txt.nl() + + txt.print("all 0: ") + txt.print_ub(b == -99) + txt.print_ub(b != -100) + txt.print_ub(b < -100) + txt.print_ub(b <= -101) + txt.print_ub(b > -100) + txt.print_ub(b >= -99) + txt.print_ub(ub ==21) + txt.print_ub(ub !=20) + txt.print_ub(ub <20) + txt.print_ub(ub <=19) + txt.print_ub(ub>20) + txt.print_ub(ub>=21) + txt.spc() + txt.print_ub(w == -20001) + txt.print_ub(w != -20000) + txt.print_ub(w < -20000) + txt.print_ub(w <= -20001) + txt.print_ub(w > -20000) + txt.print_ub(w >= -19999) + txt.print_ub(uw == 1999) + txt.print_ub(uw != 2000) + txt.print_ub(uw < 2000) + txt.print_ub(uw <= 1999) + txt.print_ub(uw > 2000) + txt.print_ub(uw >= 2001) + txt.spc() + txt.print_ub(f == -99.0) + txt.print_ub(f != -100.0) + txt.print_ub(f < -100.0) + txt.print_ub(f <= -101.0) + txt.print_ub(f > -100.0) + txt.print_ub(f >= -99.0) + txt.nl() + + txt.print("all .: ") + if b == -100 txt.chrout('.') + if b != -99 txt.chrout('.') + if b < -99 txt.chrout('.') + if b <= -100 txt.chrout('.') + if b > -101 txt.chrout('.') + if b >= -100 txt.chrout('.') + if ub ==20 txt.chrout('.') + if ub !=19 txt.chrout('.') + if ub <21 txt.chrout('.') + if ub <=20 txt.chrout('.') + if ub>19 txt.chrout('.') + if ub>=20 txt.chrout('.') + txt.spc() + if w == -20000 txt.chrout('.') + if w != -19999 txt.chrout('.') + if w < -19999 txt.chrout('.') + if w <= -20000 txt.chrout('.') + if w > -20001 txt.chrout('.') + if w >= -20000 txt.chrout('.') + if uw == 2000 txt.chrout('.') + if uw != 2001 txt.chrout('.') + if uw < 2001 txt.chrout('.') + if uw <= 2000 txt.chrout('.') + if uw > 1999 txt.chrout('.') + if uw >= 2000 txt.chrout('.') + txt.spc() + if f == -100.0 txt.chrout('.') + if f != -99.0 txt.chrout('.') + if f < -99.0 txt.chrout('.') + if f <= -100.0 txt.chrout('.') + if f > -101.0 txt.chrout('.') + if f >= -100.0 txt.chrout('.') + txt.nl() + + txt.print(" no !: ") + if b == -99 txt.chrout('!') + if b != -100 txt.chrout('!') + if b < -100 txt.chrout('!') + if b <= -101 txt.chrout('!') + if b > -100 txt.chrout('!') + if b >= -99 txt.chrout('!') + if ub ==21 txt.chrout('!') + if ub !=20 txt.chrout('!') + if ub <20 txt.chrout('!') + if ub <=19 txt.chrout('!') + if ub>20 txt.chrout('!') + if ub>=21 txt.chrout('!') + txt.spc() + if w == -20001 txt.chrout('!') + if w != -20000 txt.chrout('!') + if w < -20000 txt.chrout('!') + if w <= -20001 txt.chrout('!') + if w > -20000 txt.chrout('!') + if w >= -19999 txt.chrout('!') + if uw == 1999 txt.chrout('!') + if uw != 2000 txt.chrout('!') + if uw < 2000 txt.chrout('!') + if uw <= 1999 txt.chrout('!') + if uw > 2000 txt.chrout('!') + if uw >= 2001 txt.chrout('!') + txt.spc() + if f == -99.0 txt.chrout('!') + if f != -100.0 txt.chrout('!') + if f < -100.0 txt.chrout('!') + if f <= -101.0 txt.chrout('!') + if f > -100.0 txt.chrout('!') + if f >= -99.0 txt.chrout('!') + txt.nl() + + txt.print("all .: ") + if b == -100 txt.chrout('.') else txt.chrout('!') + if b != -99 txt.chrout('.') else txt.chrout('!') + if b < -99 txt.chrout('.') else txt.chrout('!') + if b <= -100 txt.chrout('.') else txt.chrout('!') + if b > -101 txt.chrout('.') else txt.chrout('!') + if b >= -100 txt.chrout('.') else txt.chrout('!') + if ub ==20 txt.chrout('.') else txt.chrout('!') + if ub !=19 txt.chrout('.') else txt.chrout('!') + if ub <21 txt.chrout('.') else txt.chrout('!') + if ub <=20 txt.chrout('.') else txt.chrout('!') + if ub>19 txt.chrout('.') else txt.chrout('!') + if ub>=20 txt.chrout('.') else txt.chrout('!') + txt.spc() + if w == -20000 txt.chrout('.') else txt.chrout('!') + if w != -19999 txt.chrout('.') else txt.chrout('!') + if w < -19999 txt.chrout('.') else txt.chrout('!') + if w <= -20000 txt.chrout('.') else txt.chrout('!') + if w > -20001 txt.chrout('.') else txt.chrout('!') + if w >= -20000 txt.chrout('.') else txt.chrout('!') + if uw == 2000 txt.chrout('.') else txt.chrout('!') + if uw != 2001 txt.chrout('.') else txt.chrout('!') + if uw < 2001 txt.chrout('.') else txt.chrout('!') + if uw <= 2000 txt.chrout('.') else txt.chrout('!') + if uw > 1999 txt.chrout('.') else txt.chrout('!') + if uw >= 2000 txt.chrout('.') else txt.chrout('!') + txt.spc() + if f == -100.0 txt.chrout('.') else txt.chrout('!') + if f != -99.0 txt.chrout('.') else txt.chrout('!') + if f < -99.0 txt.chrout('.') else txt.chrout('!') + if f <= -100.0 txt.chrout('.') else txt.chrout('!') + if f > -101.0 txt.chrout('.') else txt.chrout('!') + if f >= -100.0 txt.chrout('.') else txt.chrout('!') + txt.nl() + + txt.print("all .: ") + if b == -99 txt.chrout('!') else txt.chrout('.') + if b != -100 txt.chrout('!') else txt.chrout('.') + if b < -100 txt.chrout('!') else txt.chrout('.') + if b <= -101 txt.chrout('!') else txt.chrout('.') + if b > -100 txt.chrout('!') else txt.chrout('.') + if b >= -99 txt.chrout('!') else txt.chrout('.') + if ub ==21 txt.chrout('!') else txt.chrout('.') + if ub !=20 txt.chrout('!') else txt.chrout('.') + if ub <20 txt.chrout('!') else txt.chrout('.') + if ub <=19 txt.chrout('!') else txt.chrout('.') + if ub>20 txt.chrout('!') else txt.chrout('.') + if ub>=21 txt.chrout('!') else txt.chrout('.') + txt.spc() + if w == -20001 txt.chrout('!') else txt.chrout('.') + if w != -20000 txt.chrout('!') else txt.chrout('.') + if w < -20000 txt.chrout('!') else txt.chrout('.') + if w <= -20001 txt.chrout('!') else txt.chrout('.') + if w > -20000 txt.chrout('!') else txt.chrout('.') + if w >= -19999 txt.chrout('!') else txt.chrout('.') + if uw == 1999 txt.chrout('!') else txt.chrout('.') + if uw != 2000 txt.chrout('!') else txt.chrout('.') + if uw < 2000 txt.chrout('!') else txt.chrout('.') + if uw <= 1999 txt.chrout('!') else txt.chrout('.') + if uw > 2000 txt.chrout('!') else txt.chrout('.') + if uw >= 2001 txt.chrout('!') else txt.chrout('.') + txt.spc() + if f == -99.0 txt.chrout('!') else txt.chrout('.') + if f != -100.0 txt.chrout('!') else txt.chrout('.') + if f < -100.0 txt.chrout('!') else txt.chrout('.') + if f <= -101.0 txt.chrout('!') else txt.chrout('.') + if f > -100.0 txt.chrout('!') else txt.chrout('.') + if f >= -99.0 txt.chrout('!') else txt.chrout('.') + txt.nl() + + + b = -100 + while b <= -20 + b++ + txt.print_b(b) + txt.print(" -19\n") + b = -100 + while b < -20 + b++ + txt.print_b(b) + txt.print(" -20\n") + + ub = 20 + while ub <= 200 + ub++ + txt.print_ub(ub) + txt.print(" 201\n") + ub = 20 + while ub < 200 + ub++ + txt.print_ub(ub) + txt.print(" 200\n") + + w = -20000 + while w <= -8000 { + w++ + } + txt.print_w(w) + txt.print(" -7999\n") + w = -20000 + while w < -8000 { + w++ + } + txt.print_w(w) + txt.print(" -8000\n") + + uw = 2000 + while uw <= 8000 { + uw++ + } + txt.print_uw(uw) + txt.print(" 8001\n") + uw = 2000 + while uw < 8000 { + uw++ + } + txt.print_uw(uw) + txt.print(" 8000\n") + + f = 0.0 + floats.print_f(f) + while f<2.2 { + f+=0.1 + floats.print_f(f) + } + floats.print_f(f) + txt.print(" 2.2\n") + } + + sub test_compare_variable() { + byte b = -100 + ubyte ub = 20 + word w = -20000 + uword uw = 2000 + float f = -100 + + byte minus_100 = -100 + byte minus_99 = -99 + byte minus_20 = -20 + byte minus_101 = -101 + ubyte nineteen = 19 + ubyte twenty = 20 + ubyte twenty1 = 21 + ubyte twohundred = 200 + float f_minus_100 = -100.0 + float f_minus_101 = -101.0 + float f_minus_99 = -99.0 + float twodottwo = 2.2 + word minus8000 = -8000 + word eightthousand = 8000 + word w_min_20000 = -20000 + word w_min_19999 = -19999 + word w_min_20001 = -20001 + uword twothousand = 2000 + uword twothousand1 = 2001 + uword nineteen99 = 1999 + + + txt.print("all 1: ") + txt.print_ub(b == minus_100) + txt.print_ub(b != minus_99) + txt.print_ub(b < minus_99) + txt.print_ub(b <= minus_100) + txt.print_ub(b > minus_101) + txt.print_ub(b >= minus_100) + txt.print_ub(ub ==twenty) + txt.print_ub(ub !=nineteen) + txt.print_ub(ub nineteen) + txt.print_ub(ub>=twenty) + txt.spc() + txt.print_ub(w == w_min_20000) + txt.print_ub(w != w_min_19999) + txt.print_ub(w < w_min_19999) + txt.print_ub(w <= w_min_20000) + txt.print_ub(w > w_min_20001) + txt.print_ub(w >= w_min_20000) + txt.print_ub(uw == twothousand) + txt.print_ub(uw != twothousand1) + txt.print_ub(uw < twothousand1) + txt.print_ub(uw <= twothousand) + txt.print_ub(uw > nineteen99) + txt.print_ub(uw >= twothousand) + txt.spc() + txt.print_ub(f == f_minus_100) + txt.print_ub(f != f_minus_99) + txt.print_ub(f < f_minus_99) + txt.print_ub(f <= f_minus_100) + txt.print_ub(f > f_minus_101) + txt.print_ub(f >= f_minus_100) + txt.nl() + + txt.print("all 0: ") + txt.print_ub(b == minus_99) + txt.print_ub(b != minus_100) + txt.print_ub(b < minus_100) + txt.print_ub(b <= minus_101) + txt.print_ub(b > minus_100) + txt.print_ub(b >= minus_99) + txt.print_ub(ub ==twenty1) + txt.print_ub(ub !=twenty) + txt.print_ub(ub twenty) + txt.print_ub(ub>=twenty1) + txt.spc() + txt.print_ub(w == w_min_20001) + txt.print_ub(w != w_min_20000) + txt.print_ub(w < w_min_20000) + txt.print_ub(w <= w_min_20001) + txt.print_ub(w > w_min_20000) + txt.print_ub(w >= w_min_19999) + txt.print_ub(uw == nineteen99) + txt.print_ub(uw != twothousand) + txt.print_ub(uw < twothousand) + txt.print_ub(uw <= nineteen99) + txt.print_ub(uw > twothousand) + txt.print_ub(uw >= twothousand1) + txt.spc() + txt.print_ub(f == f_minus_99) + txt.print_ub(f != f_minus_100) + txt.print_ub(f < f_minus_100) + txt.print_ub(f <= f_minus_101) + txt.print_ub(f > f_minus_100) + txt.print_ub(f >= f_minus_99) + txt.nl() + + txt.print("all .: ") + if b == minus_100 txt.chrout('.') + if b != minus_99 txt.chrout('.') + if b < minus_99 txt.chrout('.') + if b <= minus_100 txt.chrout('.') + if b > minus_101 txt.chrout('.') + if b >= minus_100 txt.chrout('.') + if ub == twenty txt.chrout('.') + if ub != nineteen txt.chrout('.') + if ub < twenty1 txt.chrout('.') + if ub <= twenty txt.chrout('.') + if ub> nineteen txt.chrout('.') + if ub>= twenty txt.chrout('.') + txt.spc() + if w == w_min_20000 txt.chrout('.') + if w != w_min_19999 txt.chrout('.') + if w < w_min_19999 txt.chrout('.') + if w <= w_min_20000 txt.chrout('.') + if w > w_min_20001 txt.chrout('.') + if w >= w_min_20000 txt.chrout('.') + if uw == twothousand txt.chrout('.') + if uw != twothousand1 txt.chrout('.') + if uw < twothousand1 txt.chrout('.') + if uw <= twothousand txt.chrout('.') + if uw > nineteen99 txt.chrout('.') + if uw >= twothousand txt.chrout('.') + txt.spc() + if f == f_minus_100 txt.chrout('.') + if f != f_minus_99 txt.chrout('.') + if f < f_minus_99 txt.chrout('.') + if f <= f_minus_100 txt.chrout('.') + if f > f_minus_101 txt.chrout('.') + if f >= f_minus_100 txt.chrout('.') + txt.nl() + + txt.print(" no !: ") + if b == minus_99 txt.chrout('!') + if b != minus_100 txt.chrout('!') + if b < minus_100 txt.chrout('!') + if b <= minus_101 txt.chrout('!') + if b > minus_100 txt.chrout('!') + if b >= minus_99 txt.chrout('!') + if ub == twenty1 txt.chrout('!') + if ub != twenty txt.chrout('!') + if ub < twenty txt.chrout('!') + if ub <= nineteen txt.chrout('!') + if ub> twenty txt.chrout('!') + if ub>= twenty1 txt.chrout('!') + txt.spc() + if w == w_min_20001 txt.chrout('!') + if w != w_min_20000 txt.chrout('!') + if w < w_min_20000 txt.chrout('!') + if w <= w_min_20001 txt.chrout('!') + if w > w_min_20000 txt.chrout('!') + if w >= w_min_19999 txt.chrout('!') + if uw == nineteen99 txt.chrout('!') + if uw != twothousand txt.chrout('!') + if uw < twothousand txt.chrout('!') + if uw <= nineteen99 txt.chrout('!') + if uw > twothousand txt.chrout('!') + if uw >= twothousand1 txt.chrout('!') + txt.spc() + if f == f_minus_99 txt.chrout('!') + if f != f_minus_100 txt.chrout('!') + if f < f_minus_100 txt.chrout('!') + if f <= f_minus_101 txt.chrout('!') + if f > f_minus_100 txt.chrout('!') + if f >= f_minus_99 txt.chrout('!') + txt.nl() + + txt.print("all .: ") + if b == minus_100 txt.chrout('.') else txt.chrout('!') + if b != minus_99 txt.chrout('.') else txt.chrout('!') + if b < minus_99 txt.chrout('.') else txt.chrout('!') + if b <= minus_100 txt.chrout('.') else txt.chrout('!') + if b > minus_101 txt.chrout('.') else txt.chrout('!') + if b >= minus_100 txt.chrout('.') else txt.chrout('!') + if ub == twenty txt.chrout('.') else txt.chrout('!') + if ub != nineteen txt.chrout('.') else txt.chrout('!') + if ub < twenty1 txt.chrout('.') else txt.chrout('!') + if ub <= twenty txt.chrout('.') else txt.chrout('!') + if ub> nineteen txt.chrout('.') else txt.chrout('!') + if ub>=twenty txt.chrout('.') else txt.chrout('!') + txt.spc() + if w == w_min_20000 txt.chrout('.') else txt.chrout('!') + if w != w_min_19999 txt.chrout('.') else txt.chrout('!') + if w < w_min_19999 txt.chrout('.') else txt.chrout('!') + if w <= w_min_20000 txt.chrout('.') else txt.chrout('!') + if w > w_min_20001 txt.chrout('.') else txt.chrout('!') + if w >= w_min_20000 txt.chrout('.') else txt.chrout('!') + if uw == twothousand txt.chrout('.') else txt.chrout('!') + if uw != twothousand1 txt.chrout('.') else txt.chrout('!') + if uw < twothousand1 txt.chrout('.') else txt.chrout('!') + if uw <= twothousand txt.chrout('.') else txt.chrout('!') + if uw > nineteen99 txt.chrout('.') else txt.chrout('!') + if uw >= twothousand txt.chrout('.') else txt.chrout('!') + txt.spc() + if f == f_minus_100 txt.chrout('.') else txt.chrout('!') + if f != f_minus_99 txt.chrout('.') else txt.chrout('!') + if f < f_minus_99 txt.chrout('.') else txt.chrout('!') + if f <= f_minus_100 txt.chrout('.') else txt.chrout('!') + if f > f_minus_101 txt.chrout('.') else txt.chrout('!') + if f >= f_minus_100 txt.chrout('.') else txt.chrout('!') + txt.nl() + + txt.print("all .: ") + if b == minus_99 txt.chrout('!') else txt.chrout('.') + if b != minus_100 txt.chrout('!') else txt.chrout('.') + if b < minus_100 txt.chrout('!') else txt.chrout('.') + if b <= minus_101 txt.chrout('!') else txt.chrout('.') + if b > minus_100 txt.chrout('!') else txt.chrout('.') + if b >= minus_99 txt.chrout('!') else txt.chrout('.') + if ub == twenty1 txt.chrout('!') else txt.chrout('.') + if ub !=twenty txt.chrout('!') else txt.chrout('.') + if ub twenty txt.chrout('!') else txt.chrout('.') + if ub>= twenty1 txt.chrout('!') else txt.chrout('.') + txt.spc() + if w == w_min_20001 txt.chrout('!') else txt.chrout('.') + if w != w_min_20000 txt.chrout('!') else txt.chrout('.') + if w < w_min_20000 txt.chrout('!') else txt.chrout('.') + if w <= w_min_20001 txt.chrout('!') else txt.chrout('.') + if w > w_min_20000 txt.chrout('!') else txt.chrout('.') + if w >= w_min_19999 txt.chrout('!') else txt.chrout('.') + if uw == nineteen99 txt.chrout('!') else txt.chrout('.') + if uw != twothousand txt.chrout('!') else txt.chrout('.') + if uw < twothousand txt.chrout('!') else txt.chrout('.') + if uw <= nineteen99 txt.chrout('!') else txt.chrout('.') + if uw > twothousand txt.chrout('!') else txt.chrout('.') + if uw >= twothousand1 txt.chrout('!') else txt.chrout('.') + txt.spc() + if f == f_minus_99 txt.chrout('!') else txt.chrout('.') + if f != f_minus_100 txt.chrout('!') else txt.chrout('.') + if f < f_minus_100 txt.chrout('!') else txt.chrout('.') + if f <= f_minus_101 txt.chrout('!') else txt.chrout('.') + if f > f_minus_100 txt.chrout('!') else txt.chrout('.') + if f >= f_minus_99 txt.chrout('!') else txt.chrout('.') + txt.nl() + + + b = minus_100 + while b <= minus_20 + b++ + txt.print_b(b) + txt.print(" -19\n") + b = minus_100 + while b < -minus_20 + b++ + txt.print_b(b) + txt.print(" -20\n") + + ub = 20 + while ub <= twohundred + ub++ + txt.print_ub(ub) + txt.print(" 201\n") + ub = 20 + while ub < twohundred + ub++ + txt.print_ub(ub) + txt.print(" 200\n") + + w = w_min_20000 + while w <= minus8000 { + w++ + } + txt.print_w(w) + txt.print(" -7999\n") + w = w_min_20000 + while w < minus8000 { + w++ + } + txt.print_w(w) + txt.print(" -8000\n") + + uw = 2000 + while uw <= eightthousand { + uw++ + } + txt.print_uw(uw) + txt.print(" 8001\n") + uw = 2000 + while uw < eightthousand { + uw++ + } + txt.print_uw(uw) + txt.print(" 8000\n") + + f = 0.0 + floats.print_f(f) + while f