-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rpc): newtype (and other complex value) support for RPC server/c…
…lients
- Loading branch information
Andrew Kent
committed
May 27, 2021
1 parent
282613d
commit 02aa4d9
Showing
16 changed files
with
585 additions
and
190 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
class Opaque(): | ||
unique : int | ||
identifier : str | ||
|
||
def __init__(self, unique : int, identifier : str) -> None: | ||
self.unique = unique | ||
self.identifier = identifier | ||
|
||
def __repr__(self) -> str: | ||
return f"Opaque({self.unique!r}, {self.identifier!r})" |
50 changes: 50 additions & 0 deletions
50
cryptol-remote-api/python/tests/cryptol/test-files/CplxQNewtype.cry
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,50 @@ | ||
// This is a development of rational complex numbers | ||
|
||
type Q = Rational | ||
|
||
fortyTwo : Q | ||
fortyTwo = 42 | ||
|
||
// Complex rational numbers in rectangular coordinates | ||
newtype CplxQ = | ||
{ real : Q, imag : Q } | ||
|
||
embedQ : Q -> CplxQ | ||
embedQ x = CplxQ{ real = x, imag = 0 } | ||
|
||
cplxTwo : CplxQ | ||
cplxTwo = embedQ 2 | ||
|
||
cplxForty : CplxQ | ||
cplxForty = embedQ 40 | ||
|
||
cplxFortyTwo : CplxQ | ||
cplxFortyTwo = embedQ 42 | ||
|
||
|
||
cplxAdd : CplxQ -> CplxQ -> CplxQ | ||
cplxAdd x y = CplxQ { real = r, imag = i } | ||
where | ||
r = x.real + y.real | ||
i = x.imag + y.imag | ||
|
||
cplxMul : CplxQ -> CplxQ -> CplxQ | ||
cplxMul x y = CplxQ { real = r, imag = i } | ||
where | ||
r = x.real * y.real - x.imag * y.imag | ||
i = x.real * y.imag + x.imag * y.real | ||
|
||
cplxEq : CplxQ -> CplxQ -> Bit | ||
cplxEq x y = (x.real == y.real) && (x.imag == y.imag) | ||
|
||
property cplxAddAssoc x y z = | ||
cplxEq (cplxAdd (cplxAdd x y) z) | ||
(cplxAdd x (cplxAdd y z)) | ||
|
||
property cplxMulAssoc x y z = | ||
cplxEq (cplxMul (cplxMul x y) z) | ||
(cplxMul x (cplxMul y z)) | ||
|
||
property cplxMulDistrib x y z = | ||
cplxEq (cplxMul x (cplxAdd y z)) | ||
(cplxAdd (cplxMul x y) (cplxMul x z)) |
41 changes: 41 additions & 0 deletions
41
cryptol-remote-api/python/tests/cryptol/test_CplxQNewtype.py
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,41 @@ | ||
import unittest | ||
from pathlib import Path | ||
import unittest | ||
import cryptol | ||
from cryptol.bitvector import BV | ||
|
||
|
||
class TestCplxQ(unittest.TestCase): | ||
def test_CplxQ(self): | ||
c = cryptol.connect(reset_server=True) | ||
c.load_file(str(Path('tests','cryptol','test-files', 'CplxQNewtype.cry'))) | ||
|
||
forty_two = c.eval("fortyTwo").result() | ||
cplx_forty_two1 = c.call("embedQ", forty_two).result() | ||
cplx_forty_two2 = c.eval("CplxQ{ real = 42, imag = 0 }").result() | ||
cplx_two = c.eval("cplxTwo").result() | ||
cplx_forty = c.eval("cplxForty").result() | ||
cplx_forty_two3 = c.call("cplxAdd", cplx_two, cplx_forty).result() | ||
cplx_forty_two4 = c.eval("cplxMul (CplxQ{ real = 21, imag = 0 }) (CplxQ{ real = 2, imag = 0 })").result() | ||
cplx_forty_two5 = c.eval("cplxAdd (CplxQ{ real = 41, imag = 0 }) (CplxQ{ real = 1, imag = 0 })").result() | ||
cplx_forty_two6 = c.eval("CplxQ{ real = 42, imag = 0 }").result() | ||
|
||
res = c.call("cplxEq", cplx_forty_two1, cplx_forty_two2).result() | ||
self.assertTrue(res) | ||
res = c.call("cplxEq", cplx_two, cplx_forty_two2).result() | ||
self.assertFalse(res) | ||
res = c.call("cplxEq", cplx_forty_two1, cplx_forty_two3).result() | ||
self.assertTrue(res) | ||
res = c.call("cplxEq", cplx_forty_two1, cplx_forty_two4).result() | ||
self.assertTrue(res) | ||
res = c.call("cplxEq", cplx_forty_two1, cplx_forty_two5).result() | ||
self.assertTrue(res) | ||
res = c.call("cplxEq", cplx_forty_two1, cplx_forty_two6).result() | ||
self.assertTrue(res) | ||
|
||
# self.assertTrue(c.check("cplxMulAssoc").result().success) | ||
|
||
|
||
|
||
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
Oops, something went wrong.