-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Part of: #905 In #905, we are implementing a Python binding for the backend's function evaluator: given a function label and list of argument `Pattern`s, construct runtime terms for the arguments, evaluate the function with the given label, and return the result as an AST pattern. To safely reify the runtime term produced by the function call to an AST pattern, we need to know its sort (so that the machinery in #907, #908 can be used correctly). In some places in the bindings, we have to require that callers provide a sort when reifying terms back to patterns. However, when calling a function, the label of the function determines precisely the correct sort to use. This PR emits a new table of global data into compiled interpreters that maps tags to declared return sorts, along with a function that abstracts away indexing into this table. This change is similar to (but simpler than) an existing table of _argument sorts_ for each symbol that we already emit. Testing is handled by binding the new function to Python.
- Loading branch information
Showing
13 changed files
with
6,268 additions
and
0 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
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,12 @@ | ||
module SORTS | ||
imports DOMAINS | ||
|
||
syntax Int ::= func() [function, label(func), symbol] | ||
|
||
syntax Foo ::= foo() [label(foo), symbol] | ||
syntax Bar ::= Foo | ||
| bar() [label(bar), symbol] | ||
|
||
rule func() => 0 | ||
rule foo() => bar() | ||
endmodule |
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 @@ | ||
# RUN: mkdir -p %t | ||
# RUN: export IN=$(realpath Inputs/sorts.kore) | ||
# RUN: cd %t && %kompile "$IN" python --python %py-interpreter --python-output-dir . | ||
# RUN: KLLVM_DEFINITION=%t %python -u %s | ||
|
||
from test_bindings import kllvm | ||
|
||
import unittest | ||
|
||
class TestReturnSorts(unittest.TestCase): | ||
|
||
def _check_sort(self, label, sort): | ||
self.assertEqual(kllvm.runtime.return_sort_for_label(label), sort) | ||
|
||
def test_function(self): | ||
self._check_sort('Lblfunc{}', 'SortInt{}') | ||
|
||
def test_constructor(self): | ||
self._check_sort('Lblfoo{}', 'SortFoo{}') | ||
|
||
def test_subsort(self): | ||
self._check_sort('Lblbar{}', 'SortBar{}') | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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