compileAddIndexIdentifierToReg(opts) {
        let program = this._program;
        let scope   = this._scope;
        if (opts.indexIdentifier.getWithOffset() === null) {
            if (this._compiler.getRangeCheck()) {
                program
                    .addCommand(
                        $.CMD_SET, $.T_NUM_G, $.REG_RANGE0, $.T_NUM_C,      opts.maxArraySize,
                        $.CMD_SET, $.T_NUM_G, $.REG_RANGE1, opts.paramType, opts.indexIdentifier.getOffset(),
                        $.CMD_MOD, $.T_NUM_C, 0,            $.T_NUM_C,      0
                    )
                    .addInfoToLastCommand({token: opts.indexToken, scope: this._scope});
            }
            // It's a single dimensional array or the last array of a multidemensional array...
            helper.addToReg(this._program, opts.reg, opts.paramType, opts.indexIdentifier.getOffset());
            if (!opts.identifier.getPointer() && opts.identifier.getType().typePointer &&
                !opts.forWriting && (opts.selfPointerStackOffset === false)) {
                opts = this.compileDerefecencePointer(opts);
            }
            return opts;
        }
        // It's a self pointer or a field of a "with" record...
        if (opts.reg === $.REG_PTR) {
            // Todo: add range check...
            program.addCommand(
                $.CMD_SET, $.T_NUM_L, scope.getStackOffset() + 1, $.T_NUM_G, $.REG_PTR,                     // Save ptr on stack...
                $.CMD_SET, $.T_NUM_G, $.REG_PTR,                  $.T_NUM_L, opts.indexIdentifier.getWithOffset(),
                $.CMD_ADD, $.T_NUM_G, $.REG_PTR,                  $.T_NUM_C, opts.indexIdentifier.getOffset(),
                $.CMD_SET, $.T_NUM_L, scope.getStackOffset() + 2, $.T_NUM_P, 0,
                $.CMD_SET, $.T_NUM_G, $.REG_PTR,                  $.T_NUM_L, scope.getStackOffset() + 1,
                $.CMD_ADD, $.T_NUM_G, $.REG_PTR,                  $.T_NUM_L, scope.getStackOffset() + 2     // Restore the ptr...
            );
        } else {
            // Todo: add range check...
            program.addCommand(
                $.CMD_SET, $.T_NUM_G, $.REG_PTR,                  $.T_NUM_L, opts.indexIdentifier.getWithOffset(),
                $.CMD_ADD, $.T_NUM_G, $.REG_PTR,                  $.T_NUM_C, opts.indexIdentifier.getOffset(),
                $.CMD_ADD, $.T_NUM_G, reg,                        $.T_NUM_P, 0
            );
        }
        return opts;
    }
/**
     * Add the value of the index identifier to the register.
     * This happens when the index identifier is a single token and the array element size is 1.
    **/
Add the value of the index identifier to the register.
This happens when the index identifier is a single token and the array element size is 1.
Add the value of the index identifier to the register . This happens when the index identifier is a single token and the array element size is 1 .
compileAddIndexIdentifierToReg(opts) {
        let program = this._program;
        let scope   = this._scope;
        if (opts.indexIdentifier.getWithOffset() === null) {
            if (this._compiler.getRangeCheck()) {
                program
                    .addCommand(
                        $.CMD_SET, $.T_NUM_G, $.REG_RANGE0, $.T_NUM_C,      opts.maxArraySize,
                        $.CMD_SET, $.T_NUM_G, $.REG_RANGE1, opts.paramType, opts.indexIdentifier.getOffset(),
                        $.CMD_MOD, $.T_NUM_C, 0,            $.T_NUM_C,      0
                    )
                    .addInfoToLastCommand({token: opts.indexToken, scope: this._scope});
            }
            helper.addToReg(this._program, opts.reg, opts.paramType, opts.indexIdentifier.getOffset());
            if (!opts.identifier.getPointer() && opts.identifier.getType().typePointer &&
                !opts.forWriting && (opts.selfPointerStackOffset === false)) {
                opts = this.compileDerefecencePointer(opts);
            }
            return opts;
        }
        if (opts.reg === $.REG_PTR) {
            program.addCommand(
                $.CMD_SET, $.T_NUM_L, scope.getStackOffset() + 1, $.T_NUM_G, $.REG_PTR,                     
                $.CMD_SET, $.T_NUM_G, $.REG_PTR,                  $.T_NUM_L, opts.indexIdentifier.getWithOffset(),
                $.CMD_ADD, $.T_NUM_G, $.REG_PTR,                  $.T_NUM_C, opts.indexIdentifier.getOffset(),
                $.CMD_SET, $.T_NUM_L, scope.getStackOffset() + 2, $.T_NUM_P, 0,
                $.CMD_SET, $.T_NUM_G, $.REG_PTR,                  $.T_NUM_L, scope.getStackOffset() + 1,
                $.CMD_ADD, $.T_NUM_G, $.REG_PTR,                  $.T_NUM_L, scope.getStackOffset() + 2     
            );
        } else {
            program.addCommand(
                $.CMD_SET, $.T_NUM_G, $.REG_PTR,                  $.T_NUM_L, opts.indexIdentifier.getWithOffset(),
                $.CMD_ADD, $.T_NUM_G, $.REG_PTR,                  $.T_NUM_C, opts.indexIdentifier.getOffset(),
                $.CMD_ADD, $.T_NUM_G, reg,                        $.T_NUM_P, 0
            );
        }
        return opts;
    }
compileAddIndexIdentifierToReg ( opts ) { let program = this . _program ; let scope = this . _scope ; if ( opts . indexIdentifier . getWithOffset ( ) === null ) { if ( this . _compiler . getRangeCheck ( ) ) { program . addCommand ( $ . CMD_SET , $ . T_NUM_G , $ . REG_RANGE0 , $ . T_NUM_C , opts . maxArraySize , $ . CMD_SET , $ . T_NUM_G , $ . REG_RANGE1 , opts . paramType , opts . indexIdentifier . getOffset ( ) , $ . CMD_MOD , $ . T_NUM_C , 0 , $ . T_NUM_C , 0 ) . addInfoToLastCommand ( { token : opts . indexToken , scope : this . _scope } ) ; } helper . addToReg ( this . _program , opts . reg , opts . paramType , opts . indexIdentifier . getOffset ( ) ) ; if ( ! opts . identifier . getPointer ( ) && opts . identifier . getType ( ) . typePointer && ! opts . forWriting && ( opts . selfPointerStackOffset === false ) ) { opts = this . compileDerefecencePointer ( opts ) ; } return opts ; } if ( opts . reg === $ . REG_PTR ) { program . addCommand ( $ . CMD_SET , $ . T_NUM_L , scope . getStackOffset ( ) + 1 , $ . T_NUM_G , $ . REG_PTR , $ . CMD_SET , $ . T_NUM_G , $ . REG_PTR , $ . T_NUM_L , opts . indexIdentifier . getWithOffset ( ) , $ . CMD_ADD , $ . T_NUM_G , $ . REG_PTR , $ . T_NUM_C , opts . indexIdentifier . getOffset ( ) , $ . CMD_SET , $ . T_NUM_L , scope . getStackOffset ( ) + 2 , $ . T_NUM_P , 0 , $ . CMD_SET , $ . T_NUM_G , $ . REG_PTR , $ . T_NUM_L , scope . getStackOffset ( ) + 1 , $ . CMD_ADD , $ . T_NUM_G , $ . REG_PTR , $ . T_NUM_L , scope . getStackOffset ( ) + 2 ) ; } else { program . addCommand ( $ . CMD_SET , $ . T_NUM_G , $ . REG_PTR , $ . T_NUM_L , opts . indexIdentifier . getWithOffset ( ) , $ . CMD_ADD , $ . T_NUM_G , $ . REG_PTR , $ . T_NUM_C , opts . indexIdentifier . getOffset ( ) , $ . CMD_ADD , $ . T_NUM_G , reg , $ . T_NUM_P , 0 ) ; } return opts ; }
Add the value of the index identifier to the register.
Add the value of the index identifier to the register .
// It's a single dimensional array or the last array of a multidemensional array... // It's a self pointer or a field of a "with" record... // Todo: add range check... // Save ptr on stack... // Restore the ptr... // Todo: add range check...