Skip to content

Fix python loop#4007

Merged
moniika merged 5 commits into
RaspberryPiFoundation:developfrom
moniika:fix-python-loop
Jun 30, 2020
Merged

Fix python loop#4007
moniika merged 5 commits into
RaspberryPiFoundation:developfrom
moniika:fix-python-loop

Conversation

@moniika

@moniika moniika commented Jun 27, 2020

Copy link
Copy Markdown
Contributor

The basics

  • I branched from develop
  • My pull request is against develop
  • My code follows the style guide

The details

Resolves

Fixes #4000

Proposed Changes

Fixes error in controls_for code generation when start, end, or increment is not a simple number.

Reason for Changes

This change produces valid python, where before the code generated had syntax error.

Test Coverage

Updated golden file for generator and ran against python interpreter to see that all tests pass.

Manually tested on advanced playground with:

<xml xmlns="https://developers.google.com/blockly/xml">
  <variables>
    <variable>j</variable>
    <variable>i</variable>
    <variable>k</variable>
  </variables>
  <block type="variables_set">
    <field name="VAR">j</field>
    <value name="VALUE">
      <block type="math_number">
        <field name="NUM">0</field>
      </block>
    </value>
    <next>
      <block type="controls_for">
        <field name="VAR">i</field>
        <value name="FROM">
          <shadow type="math_number">
            <field name="NUM">1</field>
          </shadow>
        </value>
        <value name="TO">
          <shadow type="math_number">
            <field name="NUM">10</field>
          </shadow>
          <block type="procedures_callreturn">
            <mutation name="changej"></mutation>
          </block>
        </value>
        <value name="BY">
          <shadow type="math_number">
            <field name="NUM">2</field>
          </shadow>
          <block type="procedures_callreturn">
            <mutation name="changek"></mutation>
          </block>
        </value>
        <statement name="DO">
          <block type="text_print">
            <value name="TEXT">
              <shadow type="text">
                <field name="TEXT">abc</field>
              </shadow>
              <block type="variables_get">
                <field name="VAR">i</field>
              </block>
            </value>
          </block>
        </statement>
      </block>
    </next>
  </block>
  <block type="procedures_defreturn">
    <field name="NAME">changej</field>
    <comment pinned="false" h="80" w="160">Describe this function...</comment>
    <statement name="STACK">
      <block type="math_change">
        <field name="VAR">j</field>
        <value name="DELTA">
          <shadow type="math_number">
            <field name="NUM">1</field>
          </shadow>
        </value>
      </block>
    </statement>
    <value name="RETURN">
      <block type="variables_get">
        <field name="VAR">j</field>
      </block>
    </value>
  </block>
  <block type="procedures_defreturn">
    <field name="NAME">changek</field>
    <comment pinned="false" h="80" w="160">Describe this function...</comment>
    <statement name="STACK">
      <block type="math_change">
        <field name="VAR">k</field>
        <value name="DELTA">
          <shadow type="math_number">
            <field name="NUM">1</field>
          </shadow>
        </value>
      </block>
    </statement>
    <value name="RETURN">
      <block type="variables_get">
        <field name="VAR">k</field>
      </block>
    </value>
  </block>
</xml>

@moniika
moniika merged commit fcc3a09 into RaspberryPiFoundation:develop Jun 30, 2020
@moniika
moniika deleted the fix-python-loop branch July 6, 2020 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants