@@ -1181,19 +1181,18 @@ def improve_closure(closure: Closure) -> Closure:
11811181 return Closure (env , closure .func )
11821182
11831183
1184- def lift_simple (x : object ) -> Object :
1184+ def as_record (x : object ) -> Object :
11851185 if isinstance (x , int ):
11861186 return Int (x )
11871187 if isinstance (x , str ):
11881188 return String (x )
1189+ if isinstance (x , list ):
1190+ return List ([as_record (item ) for item in x ])
1191+ if isinstance (x , dict ):
1192+ return Record ({key : as_record (value ) for key , value in x .items ()})
11891193 raise NotImplementedError (type (x ))
11901194
11911195
1192- def as_record (obj : dict [str , object ]) -> Record :
1193- conv : Callable [[object ], Object ] = lambda x : as_record (x ) if isinstance (x , dict ) else lift_simple (x )
1194- return Record ({key : conv (value ) for key , value in obj .items ()})
1195-
1196-
11971196# pylint: disable=redefined-builtin
11981197def eval_exp (env : Env , exp : Object ) -> Object :
11991198 logger .debug (exp )
@@ -4409,6 +4408,20 @@ def int_as_str(obj: Object) -> String:
44094408PRELUDE = """
44104409id = x -> x
44114410
4411+ . compile =
4412+ | {type = "Int", value = value} -> $$int_as_str value
4413+ | {type = "Var", name = name} -> name
4414+ | {type = "Binop", op = op, left = left, right = right} -> (compile left) ++ op ++ (compile right)
4415+ | {type = "List", items = items} -> "[" ++ (join ", " (map compile items)) ++ "]"
4416+ | {type = "Assign", name = name, value = value} -> "((" ++ name ++ ") =>" ++ (compile value) ++ ")("
4417+ | {type = "Where", binding={type="Assign", name=name, value=value}, body=body} ->
4418+ "(" ++ (compile name) ++ " => " ++ (compile body) ++ ")(" ++ (compile value) ++ ")"
4419+
4420+ . join = sep ->
4421+ | [] -> ""
4422+ | [x] -> x
4423+ | [x, ...xs] -> x ++ sep ++ (join sep xs)
4424+
44124425. quicksort =
44134426 | [] -> []
44144427 | [p, ...xs] -> (concat ((quicksort (ltp xs p)) +< p) (quicksort (gtp xs p))
@@ -4449,11 +4462,6 @@ def int_as_str(obj: Object) -> String:
44494462. any = f ->
44504463 | [] -> #false
44514464 | [x, ...xs] -> f x || any f xs
4452-
4453- . compile =
4454- | {type = "Int", value = value} -> $$int_as_str value
4455- | {type = "Var", name = name} -> name
4456- | {type = "Binop", op = op, left = left, right = right } -> (compile left) ++ op ++ (compile right)
44574465"""
44584466
44594467
0 commit comments