lastc_stmt.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Copyright (c) 2020 Rocky Bernstein
  2. # This program is free software: you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License as published by
  4. # the Free Software Foundation, either version 3 of the License, or
  5. # (at your option) any later version.
  6. #
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. def lastc_stmt(
  15. self, lhs: str, n: int, rule, ast, tokens: list, first: int, last: int
  16. ) -> bool:
  17. # A lastc_stmt really has to be the last thing in a block,
  18. # a statement that doesn't fall through to the next instruction, or
  19. # in the case of "POP_BLOCK" is about to end.
  20. # Otherwise this kind of stmt should flow through to the next.
  21. # However that larger, set of stmts could be a lastc_stmt, but come back
  22. # here with that larger set of stmts.
  23. # print("XXX", first, last, rule)
  24. # for t in range(first, last): print(tokens[t])
  25. # print("="*40)
  26. if tokens[last] == "COME_FROM":
  27. last -= 1
  28. # FIXME: use instruction properties.
  29. return tokens[last] not in (
  30. "BREAK_LOOP",
  31. "COME_FROM_LOOP",
  32. "CONTINUE",
  33. "JUMP_LOOP",
  34. "POP_BLOCK",
  35. "RETURN_VALUE",
  36. )