Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ranges and for loops #343

Merged
merged 41 commits into from
Mar 1, 2024
Merged

Ranges and for loops #343

merged 41 commits into from
Mar 1, 2024

Conversation

MichalMarsalek
Copy link
Collaborator

@MichalMarsalek MichalMarsalek commented Jan 1, 2024

Big refactor of integer ranges and loops. The main motivation is to simplify the AST, reduce repetition and special casing in plugins and emitters and to simplify the control flow analysis in the future.

  • Closes Make syntax for range types and for looping over ranges consistent #33
  • Closes Range op #127
  • Renames concat alias to + (.. is understood, but emits deprecation warning (this was kind of tricky to implement since it needs type info))
  • Removes ForRange, ForDifferenceRange nodes
  • Adds range_incl (alias ..), range_excl (alias ..<) as frontend and range_diff_excl as backend opcodes to fill in the functionality
  • Adds text_to_list[Ascii], (alias text_to_list) text_to_list[byte], text_to_list[codepoint] opcodes, to be used for iterating over characters.
  • Removes ForEachKey & ForEachPair. They were not used and I'm not sure target langs would agree on iteration order. If we decide to add this functionality later, we can do so via a table_keys_list opcode over which we would iterate using a ForEach = for.
  • Adds default values for opcodes. These are used when parsing Polygolf and encountering less arguments than the nominal arity and also by mapOps plugin, if the target lang shares the defaults with Polygolf.
  • Adds Cast node. This node is used when explicit conversion from/to a type that doesn't exist in Polygolf is needed in the target language.

Polygolf's for now means a for each loop over list items and it should be used for iterating over a range as well, similar to Python.
for $i $a $b {}; should now be written for $i ($a ..< $b) {}. Old form is understood (as implicit range_excl), but emits a deprecation warning. for $i 10 {}; and for 10 {}; forms are preserved without a warning.
for $i $text {}; is a syntax sugar for for $i (text_to_list $text) {};, for[byte] $i $text {}; is a syntax sugar for for $i (text_to_list[byte] $text) {}; similar for[codepoint].

@MichalMarsalek MichalMarsalek marked this pull request as draft January 1, 2024 17:35
@MichalMarsalek MichalMarsalek mentioned this pull request Jan 21, 2024
@Steffan153
Copy link
Contributor

I think several of the language-specific tests need updated, as they still have the old for $i $a $b in them

@MichalMarsalek MichalMarsalek merged commit 5d3b63c into main Mar 1, 2024
1 check passed
@MichalMarsalek MichalMarsalek deleted the ranges-and-for-loops branch March 2, 2024 13:40
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.

Range op Make syntax for range types and for looping over ranges consistent
2 participants