@@ -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
791790end Strata
0 commit comments