Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix integer/float comparison and expand legal magic methods whitelist #181

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/nagini_translation/lib/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,43 @@
'__ge__',
'__lt__',
'__le__',

'__add__',
'__sub_',
'__sub__',
'__mul__',
'__truediv__',
'__floordiv__',
'__mod__',
'__divmod__',
'__pow__',
'__lshift__',
'__rshift__',
'__and__',
'__or__',
'__xor__',

'__radd__',
'__rsub__',
'__rmul__',
'__rmatmul__',
'__rtruediv__',
'__rfloordiv__',
'__rmod__',
'__rdivmod__',
'__rpow__(self,',
'__rlshift__',
'__rrshift__',
'__rand__',
'__rxor__',
'__ror__',

'__init__',
'__enter__',
'__exit__',
'__str__',
'__len__',
'__bool__',

'__getitem__',
'__setitem__',
}
Expand Down
32 changes: 24 additions & 8 deletions src/nagini_translation/resources/bool.sil
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,44 @@ function bool___eq__(self: Ref, other: Ref): Bool
ensures result == object___eq__(self, other)


function int___ge__(self: Int, other: Int): Bool
function int___ge__(self: Ref, other: Ref): Bool
decreases _
requires issubtype(typeof(self), int())
requires issubtype(typeof(other), float())
{
self >= other
issubtype(typeof(other), int())
? int___unbox__(self) >= int___unbox__(other)
: float___ge__(self, other)
}

function int___gt__(self: Int, other: Int): Bool
function int___gt__(self: Ref, other: Ref): Bool
decreases _
requires issubtype(typeof(self), int())
requires issubtype(typeof(other), float())
{
self > other
issubtype(typeof(other), int())
? int___unbox__(self) >= int___unbox__(other)
: float___gt__(self, other)
}

function int___le__(self: Int, other: Int): Bool
function int___le__(self: Ref, other: Ref): Bool
decreases _
requires issubtype(typeof(self), int())
requires issubtype(typeof(other), float())
{
self <= other
issubtype(typeof(other), int())
? int___unbox__(self) >= int___unbox__(other)
: float___le__(self, other)
}

function int___lt__(self: Int, other: Int): Bool
function int___lt__(self: Ref, other: Ref): Bool
decreases _
requires issubtype(typeof(self), int())
requires issubtype(typeof(other), float())
{
self < other
issubtype(typeof(other), int())
? int___unbox__(self) >= int___unbox__(other)
: float___lt__(self, other)
}

function int___add__(self: Int, other: Int): Int
Expand Down
20 changes: 12 additions & 8 deletions src/nagini_translation/resources/preamble.index
Original file line number Diff line number Diff line change
Expand Up @@ -254,20 +254,24 @@
"type": "__prim__int"
},
"__ge__": {
"args": ["__prim__int", "__prim__int"],
"type": "__prim__bool"
"args": ["int", "float"],
"type": "__prim__bool",
"requires": []
},
"__gt__": {
"args": ["__prim__int", "__prim__int"],
"type": "__prim__bool"
"args": ["int", "float"],
"type": "__prim__bool",
"requires": []
},
"__lt__": {
"args": ["__prim__int", "__prim__int"],
"type": "__prim__bool"
"args": ["int", "float"],
"type": "__prim__bool",
"requires": []
},
"__le__": {
"args": ["__prim__int", "__prim__int"],
"type": "__prim__bool"
"args": ["int", "float"],
"type": "__prim__bool",
"requires": []
},
"__int__": {
"args": ["int"],
Expand Down
Loading