Skip to content

Commit

Permalink
Fixed type inference for float literals, added some Viper-level depen…
Browse files Browse the repository at this point in the history
…dencies
  • Loading branch information
marcoeilers committed Dec 6, 2023
1 parent f3ee12f commit bcf5ec7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/nagini_translation/lib/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
BUILTINS,
BYTES_TYPE,
DICT_TYPE,
FLOAT_TYPE,
INT_TYPE,
LIST_TYPE,
OBJECT_TYPE,
Expand Down Expand Up @@ -261,7 +262,10 @@ def _do_get_type(node: ast.AST, containers: List[ContainerInterface],
# the node refers to something unknown in the given context.
return None
if isinstance(node, ast.Num):
return module.global_module.classes[INT_TYPE]
if isinstance(node.n, int):
return module.global_module.classes[INT_TYPE]
if isinstance(node.n, float):
return module.global_module.classes[FLOAT_TYPE]
elif isinstance(node, ast.Tuple):
args = [get_type(arg, containers, container) for arg in node.elts]
return GenericType(module.global_module.classes[TUPLE_TYPE],
Expand Down
7 changes: 4 additions & 3 deletions src/nagini_translation/resources/preamble.index
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@
"functions": {
"__create__": {
"args": ["__prim__int"],
"type": "float"
"type": "float",
"requires": ["__prim__perm___box__"]
},
"__unbox__": {
"args": ["float"],
Expand All @@ -290,7 +291,7 @@
"__bool__": {
"args": ["float"],
"type": "__prim__bool",
"requires": ["int___bool__", "int___unbox__", "unbox", "__prim__perm___box__"]
"requires": ["int___bool__", "int___unbox__", "unbox", "__prim__perm___box__", "___float32_zero"]
},
"__eq__": {
"args": ["float", "object"],
Expand All @@ -315,7 +316,7 @@
"__div__": {
"args": ["float", "float"],
"type": "float",
"requires": ["int___div__", "int___unbox__", "unbox", "__prim__perm___box__"]
"requires": ["int___div__", "int___unbox__", "unbox", "__prim__perm___box__", "___float32_zero"]
},
"__ge__": {
"args": ["float", "float"],
Expand Down

0 comments on commit bcf5ec7

Please sign in to comment.