sto15 property Null safety

NormalArgOperation sto15
final

Implementation

static final NormalArgOperation sto15 = NormalArgOperation(
    maxOneByteOpcodes: 34,
    arg: ArgAlternates(synonyms: _matrixSynonymsPlusRandom, children: [
      // 0-.9, I
      RegisterWriteArg(
          maxDigit: 19, noParenI: true, f: (m) => m.x), // 21 opcodes
      KeyArg(
          key: Operations15.ranNum,
          child: ArgDone(((m) {
            (m as Model15).rand.setSeed(m.xF);
          }))),
      KeyArg(
          key: Operations15.resultOp,
          child: ArgDone((m) {
            final matrix = (m as Model15).x.asMatrix;
            if (matrix == null) {
              throw CalculatorError(11);
            } else {
              m.resultMatrix = matrix;
            }
          })),
      // g A..E:
      KeysArg(
          keys: _letterLabelsGShifted,
          generator: (i) => ArgDone((m) {
                final matrix = (m as Model15).matrices[i];
                final int row = m.yF.truncate().abs() - 1;
                final int col = m.xF.truncate().abs() - 1;
                m.z.asDouble; // Make sure it's a float
                matrix.set(row, col, m.z);
                m.popStack();
                m.popStack();
              })),
      // Not user mode, A..E, (i)
      UserArg(
          userMode: false,
          child:
              ArgAlternates(synonyms: _letterAndRegisterISynonyms, children: [
            KeysArg(
                keys: _letterLabels,
                generator: (i) =>
                    ArgDone((m) => _storeToMatrix(m, false, i))),
            KeyArg(
                key: Operations15.parenI15,
                child: ArgDone((m) => _storeToParenI(m, false)))
          ])),
      UserArg(
          userMode: true,
          child: ArgAlternates(
            synonyms: _letterAndRegisterISynonyms,
            children: [
              KeysArg(
                  keys: _letterLabels,
                  generator: (i) =>
                      ArgDone((m) => _storeToMatrix(m, true, i))),
              KeyArg(
                  key: Operations15.parenI15,
                  child: ArgDone((m) => _storeToParenI(m, true)))
            ],
          )),
      KeyArg(
          // STO MATRIX A..E.  These are two-byte opcodes.
          key: Operations15.matrix,
          child: KeysArg(
              synonyms: _matrixSynonyms,
              keys: _letterLabels,
              generator: (i) => ArgDone((m) => _storeMatrix(m, i)))),
      KeyArg(
          key: Operations15.plus,
          child: RegisterWriteOpArg(
              maxDigit: 19,
              f: (m, r, x) => Value.fromDouble(r.asDouble + x.asDouble))),
      KeyArg(
          key: Operations15.minus,
          child: RegisterWriteOpArg(
              maxDigit: 19,
              f: (m, r, x) => Value.fromDouble(r.asDouble - x.asDouble))),
      KeyArg(
          key: Operations15.mult,
          child: RegisterWriteOpArg(
              maxDigit: 19,
              f: (m, r, x) => Value.fromDouble(r.asDouble * x.asDouble))),
      KeyArg(
          key: Operations15.div,
          child: RegisterWriteOpArg(
              maxDigit: 19,
              f: (m, r, x) => Value.fromDouble(r.asDouble / x.asDouble))),
      KeyArg(
          key: Operations15.cosInverse, // That's g (i)
          child: ArgDone((m) {
            final Value iv = m.memory.registers.index;
            final int? miv = iv.asMatrix;
            if (miv != null) {
              _storeToMatrixRC(m, miv, m.y, m.x);
            } else {
              final int reg = iv.asDouble.floor().abs();
              m.memory.registers[reg] = m.z;
            }
            // I checked on a real 15C:  Even when I is a register,
            // it stores value in z, and pops stack twice.
            m.popStack();
            m.popStack();
          }))
    ]),
    name: 'STO');