-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: range() with single-argument (#452)
Addresses #429 but maybe only partially. * `xfail` some tests that look for single nodes in the compiled Hugr, as this currently includes the whole stdlib. See #470. * `@typing.overload` the `@guppy` decorator to remove mypy error when using `@guppy(module)` * `parse_py_class` attempts `inspect.getsourcelines` when running IPython, as this works for the stdlib
- Loading branch information
Showing
7 changed files
with
109 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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,26 @@ | ||
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_range(validate, run_int_fn): | ||
module = GuppyModule("test_range") | ||
|
||
@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") |