-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
515 additions
and
384 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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 textwrap import dedent | ||
from verified_cogen.runners.languages import LanguageDatabase, init_basic_languages | ||
|
||
init_basic_languages() | ||
|
||
|
||
def test_dafny_generate(): | ||
dafny_lang = LanguageDatabase().get("dafny") | ||
code = dedent( | ||
"""\ | ||
method main(value: int) returns (result: int) | ||
requires value >= 10 | ||
ensures result >= 20 | ||
{ | ||
assert value * 2 >= 20; // assert-line | ||
result := value * 2; | ||
}""" | ||
) | ||
assert dafny_lang.generate_validators(code) == dedent( | ||
"""\ | ||
method main_valid(value: int) returns (result: int) | ||
requires value >= 10 | ||
ensures result >= 20 | ||
{ var ret := main(value); return ret; } | ||
""" | ||
) |
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 textwrap import dedent | ||
# from verified_cogen.runners.languages import LanguageDatabase, init_basic_languages | ||
|
||
# init_basic_languages() | ||
|
||
|
||
# def test_nagini_generate(): | ||
# nagini_lang = LanguageDatabase().get("nagini") | ||
# code = dedent( | ||
# """\ | ||
# def main(value: int) -> int: | ||
# Requires(value >= 10) | ||
# Ensures(Result() >= 20) | ||
# Assert(value * 2 >= 20) // assert-line | ||
# return value * 2""" | ||
# ) | ||
# assert nagini_lang.generate_validators(code) == dedent( | ||
# """\ | ||
# def main_valid(value: int) -> int: | ||
# Requires(value >= 10) | ||
# Ensures(Result() >= 20) | ||
# ret = main(value) | ||
# return ret""" | ||
# ) | ||
|
||
# print(nagini_lang.generate_validators(code)) |
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,8 @@ | ||
from verified_cogen.runners.languages.dafny import DafnyLanguage | ||
from verified_cogen.runners.languages.language import LanguageDatabase | ||
from verified_cogen.runners.languages.nagini import NaginiLanguage | ||
|
||
|
||
def init_basic_languages(): | ||
LanguageDatabase().add("dafny", ["dfy"], DafnyLanguage()) | ||
LanguageDatabase().add("nagini", ["py", "python"], NaginiLanguage()) |
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,21 @@ | ||
from typing import Pattern | ||
from verified_cogen.runners.languages.language import GenericLanguage | ||
import re | ||
|
||
DAFNY_VALIDATOR_TEMPLATE = """\ | ||
def {method_name}_valid({parameters}) -> ({returns}):{specs}\ | ||
ret = {method_name}({param_names}) | ||
return ret | ||
""" | ||
|
||
|
||
class DafnyLanguage(GenericLanguage): | ||
method_regex: Pattern[str] | ||
|
||
def __init__(self): | ||
super().__init__( | ||
re.compile( | ||
r"method\s+(\w+)\s*\((.*?)\)\s*returns\s*\((.*?)\)(.*?)\{", re.DOTALL | ||
), | ||
DAFNY_VALIDATOR_TEMPLATE, | ||
) |
Oops, something went wrong.