Skip to content

Commit 816d68e

Browse files
authored
Merge branch 'main' into josh/adt-alias
2 parents ff3e2d5 + e85f517 commit 816d68e

File tree

4 files changed

+41
-12
lines changed

4 files changed

+41
-12
lines changed

Strata/Languages/Python/PythonToCore.lean

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -209,18 +209,14 @@ def PyExprToMonoTy (e : Python.expr SourceRange) : Lambda.LMonoTy :=
209209
match e with
210210
| .Name _ n _ =>
211211
match n.val with
212-
| "bool" => .tcons "bool" []
213-
| "int" => .tcons "int" []
214212
| "str" => .tcons "string" []
215213
| "float" => .tcons "string" []
216214
| "Dict[str Any]" => .tcons "DictStrAny" []
217215
| "List[str]" => .tcons "ListStr" []
218216
| "datetime" => .tcons "Datetime" []
219217
| "date" => .tcons "Date" []
220218
| "timedelta" => .tcons "Timedelta" []
221-
| "Client" => .tcons "Client" []
222-
| "LatencyAnalyzer" => .tcons "LatencyAnalyzer" []
223-
| _ => panic! s!"Unhandled name: {repr e}"
219+
| _ => .tcons n.val []
224220
| .Subscript _ val _slice _ =>
225221
match val with
226222
| .Name _ n _ =>
@@ -775,17 +771,20 @@ def pythonToCore (signatures : Python.Signatures) (pgm: Strata.Program): Core.Pr
775771
let new_acc := update acc info
776772
let (ys, acc'') := helper f update new_acc xs
777773
(y ++ ys, acc'')
778-
let func_info : TranslationContext := { signatures }
779774

780-
let func_defs_and_infos := helper PyFuncDefToCore (fun acc info => {acc with func_infos := info :: acc.func_infos}) func_info func_defs.toList
781-
let func_defs := func_defs_and_infos.fst
782-
let func_infos := func_defs_and_infos.snd
775+
-- TODO: in Python, declarations can be circular
776+
let base_ctx : TranslationContext := { signatures }
783777

784-
let class_defs_and_infos := helper PyClassDefToCore (fun acc info => {acc with class_infos := info :: acc.class_infos}) func_infos class_defs.toList
778+
let class_defs_and_infos := helper PyClassDefToCore (fun acc info => {acc with class_infos := info :: acc.class_infos}) base_ctx class_defs.toList
785779
let class_defs := class_defs_and_infos.fst
786780
let class_infos := class_defs_and_infos.snd
787-
let class_ty_decls := [(.type (.con {name := "LatencyAnalyzer", numargs := 0})) ]
788781

789-
{decls := globals ++ class_ty_decls ++ func_defs ++ class_defs ++ [.proc (pythonFuncToCore "__main__" [] non_func_blocks none default class_infos)]}
782+
let class_ty_decls := class_infos.class_infos.map (λ info => .type (.con {name := info.name, numargs := 0}))
783+
784+
let func_defs_and_infos := helper PyFuncDefToCore (fun acc info => {acc with func_infos := info :: acc.func_infos}) class_infos func_defs.toList
785+
let func_defs := func_defs_and_infos.fst
786+
let func_infos := func_defs_and_infos.snd
787+
788+
{decls := globals ++ class_ty_decls ++ func_defs ++ class_defs ++ [.proc (pythonFuncToCore "__main__" [] non_func_blocks none default func_infos)]}
790789

791790
end Strata
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
datetime_now_ensures_0: ✅ pass
3+
4+
datetime_utcnow_ensures_0: ✅ pass
5+
6+
ensures_str_strp_reverse: ✅ pass
7+
8+
assert_name_is_foo: ✅ pass
9+
10+
assert_opt_name_none_or_str: ✅ pass
11+
12+
assert_opt_name_none_or_bar: ✅ pass
13+
14+
ensures_maybe_except_none: ✅ pass

StrataTest/Languages/Python/run_py_analyze.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ for test_file in tests/test_*.py; do
1717
echo "ERROR: Analysis output for $base_name does not match expected result"
1818
echo "$output" | diff "$expected_file" -
1919
failed=1
20+
else
21+
echo "Test passed: " $base_name
2022
fi
2123
fi
2224
fi
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import test_helper
2+
from typing import List
3+
4+
class CircularBuffer:
5+
def __init__(self, n: int):
6+
print("Hi")
7+
8+
def main():
9+
my_buf: CircularBuffer = CircularBuffer(5)
10+
11+
print("Bye")
12+
13+
if __name__ == "__main__":
14+
main()

0 commit comments

Comments
 (0)