Skip to content

Commit

Permalink
Encoding and decoding llvm pattern's functions
Browse files Browse the repository at this point in the history
Modifying string tests to only test non-unicode string for bindings.
  • Loading branch information
Robertorosmaninho committed Aug 7, 2024
1 parent 0a794a7 commit 7ab90da
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pyk/src/pyk/kllvm/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def sentence_to_llvm(sentence: Sentence) -> kllvm.Declaration:
def pattern_to_llvm(pattern: Pattern) -> kllvm.Pattern:
match pattern:
case String(value):
return kllvm.StringPattern(value)
return kllvm.StringPattern(value.encode('latin-1'))
case VarPattern(name, sort):
return kllvm.VariablePattern(name, sort_to_llvm(sort))
case App(symbol, sorts, args):
Expand Down Expand Up @@ -201,7 +201,7 @@ def llvm_to_sentence(decl: kllvm.Declaration) -> Sentence:
def llvm_to_pattern(pattern: kllvm.Pattern) -> Pattern:
match pattern:
case kllvm.StringPattern(): # type: ignore
return String(pattern.contents)
return String(pattern.contents.decode('latin-1'))
case kllvm.VariablePattern(): # type: ignore
if pattern.name and pattern.name[0] == '@':
return SVar(pattern.name, llvm_to_sort(pattern.sort))
Expand Down
9 changes: 8 additions & 1 deletion pyk/src/tests/integration/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
'🙂',
)

BINDINGS_TEST_DATA: Final = (
'hello',
'\n',
'\x01',
'£',
)

KOMPILE_DEFINITION = """
module STRING-REWRITE
imports STRING-SYNTAX
Expand Down Expand Up @@ -213,7 +220,7 @@ def test_krun(backend: str, definition_dir: Path, text: str) -> None:
assert actual == expected


@pytest.mark.parametrize('text', TEST_DATA, ids=TEST_DATA)
@pytest.mark.parametrize('text', BINDINGS_TEST_DATA, ids=BINDINGS_TEST_DATA)
def test_bindings(runtime: Runtime, text: str) -> None:
from pyk.kllvm.convert import llvm_to_pattern, pattern_to_llvm

Expand Down

0 comments on commit 7ab90da

Please sign in to comment.