RegisterReadOpArg constructor Null safety

RegisterReadOpArg(
  1. {required int maxDigit,
  2. required double f(
    1. double,
    2. double
    )}
)

Implementation

RegisterReadOpArg({required int maxDigit, required this.f})
    : super(synonyms: Operations15._letterAndRegisterISynonyms, children: [
        KeyArg(
            key: Arg.kParenI,
            child: RegisterReadOpArgDone((m) {
              final mi = m.memory.registers.index.asMatrix;
              if (mi == null) {
                m.xRealF = f(m.xF, m.memory.registers.indirectIndex.asDouble);
                // Do not set LastX, as per real 15C's behavior, so no resultX
                // Do not alter imaginary part
              } else {
                // See bottom of page 173
                _forMatrix(m as Model15, mi, f);
              }
            })),
        KeyArg(key: Arg.kI, child: RegisterReadOpArgDone(
            // Do not set LastX, as per real 15C's behavior
            (m) => m.xRealF = f(m.xF, m.memory.registers.index.asDouble))),
        DigitArg(
            max: maxDigit,
            calc: (m, i) =>
                m.xRealF = f(m.xF, m.memory.registers[i].asDouble),
            // The 15C doesn't doesn't do real complex operation, it just
            // maintains imaginary part.  So, if x contains 1+2i, and you
            // multiply by a register containing 3, you get 3+2i.  Oopsie!'
            //
            // Also, here we do not set LastX, as per real 15C's behavior.
            argDoneFactory: (calc) => RegisterReadOpArgDone(calc)),
        ...List.generate(
            _letterLabelsList.length,
            (i) => KeyArg(
                key: _letterLabelsList[i],
                child: RegisterReadOpArgDone((m) {
                  _forMatrix(m as Model15, i, f);
                }))),
      ]);