-
Notifications
You must be signed in to change notification settings - Fork 5
feat: [FYI] RangeChecker/RangeCompiler to support 1/2/3 args #453
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
Draft
acl-cqc
wants to merge
9
commits into
main
Choose a base branch
from
acl/range_custom
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
880db7d
Single-arg version of range, test_range.py sums in loop
acl-cqc b4d4202
Fix ipython: getsourcelines, etc., works for guppy builtins
acl-cqc b663e8c
Fix test_func_name, stdlib is there too
acl-cqc 616795e
XFAIL the various broken tests
acl-cqc 3b20af8
typing.overload to reduce errors on @guppy(builtin)
acl-cqc e994d9e
type:ignore[call-arg] for Range(Iter)-constructors
acl-cqc ab96665
Merge remote-tracking branch 'origin/main' into acl/range_one
acl-cqc 6d40278
Test tidies
acl-cqc 7f72deb
RangeChecker/RangeCompiler to support 1/2/3 args
acl-cqc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
from guppylang.decorator import guppy | ||
from guppylang.prelude.builtins import nat, range | ||
from guppylang.module import GuppyModule | ||
from tests.util import compile_guppy | ||
|
||
|
||
def test_stop_only(validate, run_int_fn): | ||
module = GuppyModule("test_range1") | ||
|
||
@guppy(module) | ||
def main() -> int: | ||
total = 0 | ||
for x in range(5): | ||
total += x + 100 # Make the initial 0 obvious | ||
return total | ||
|
||
@guppy(module) | ||
def negative() -> int: | ||
total = 0 | ||
for x in range(-3): | ||
total += 100 + x | ||
return total | ||
|
||
compiled = module.compile() | ||
validate(compiled) | ||
run_int_fn(compiled, expected=510) | ||
run_int_fn(compiled, expected=0, fn_name="negative") | ||
|
||
def test_start_stop(validate, run_int_fn): | ||
module = GuppyModule("test_range2") | ||
|
||
@guppy(module) | ||
def simple() -> int: | ||
total = 0 | ||
for x in range(3, 5): | ||
total += x | ||
return total | ||
|
||
@guppy(module) | ||
def empty() -> int: | ||
total = 0 | ||
for x in range(5, 3): | ||
total += x + 100 | ||
return total | ||
|
||
compiled=module.compile() | ||
validate(compiled) | ||
run_int_fn(compiled, expected=7, fn_name="simple") | ||
run_int_fn(compiled, expected=0, fn_name="empty") | ||
|
||
def test_with_step(validate, run_int_fn): | ||
module =GuppyModule("test_range3") | ||
|
||
@guppy(module) | ||
def evens() -> int: | ||
total = 0 | ||
for x in range(2, 7, 2): | ||
total += x | ||
return total | ||
|
||
@guppy(module) | ||
def negative_step() -> int: | ||
total = 0 | ||
for x in range(5, 3, -1): | ||
total += x | ||
return total | ||
|
||
@guppy(module) | ||
def empty() -> int: | ||
total = 0 | ||
for x in range(3, 5, -1): | ||
total += 100 + x | ||
return total | ||
|
||
compiled = module.compile() | ||
validate(compiled) | ||
run_int_fn(compiled, expected=12, fn_name="evens") | ||
run_int_fn(compiled, expected=9, fn_name="negative_step") | ||
run_int_fn(compiled, expected=0, fn_name="empty") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the worst bit! Custom Checkers get access to the Func + full Context, Compilers only get the CompiledGlobals which is rather hard to use