315 let |
315 let |
316 val dummy_name = ""; |
316 val dummy_name = ""; |
317 val dummy_type = ITyVar dummy_name; |
317 val dummy_type = ITyVar dummy_name; |
318 val dummy_case_term = IVar dummy_name; |
318 val dummy_case_term = IVar dummy_name; |
319 (*assumption: dummy values are not relevant for serialization*) |
319 (*assumption: dummy values are not relevant for serialization*) |
320 val unitt = IConst (unit', ([], [])); |
320 val unitt = IConst (unit', (([], []), [])); |
321 fun dest_abs ((v, ty) `|-> t, _) = ((v, ty), t) |
321 fun dest_abs ((v, ty) `|-> t, _) = ((v, ty), t) |
322 | dest_abs (t, ty) = |
322 | dest_abs (t, ty) = |
323 let |
323 let |
324 val vs = Code_Thingol.fold_varnames cons t []; |
324 val vs = Code_Thingol.fold_varnames cons t []; |
325 val v = Name.variant vs "x"; |
325 val v = Name.variant vs "x"; |
351 | (t, ts) => imp_monad_bind bind' return' unit' t `$$ map (imp_monad_bind bind' return' unit') ts) |
351 | (t, ts) => imp_monad_bind bind' return' unit' t `$$ map (imp_monad_bind bind' return' unit') ts) |
352 | imp_monad_bind bind' return' unit' (v_ty `|-> t) = v_ty `|-> imp_monad_bind bind' return' unit' t |
352 | imp_monad_bind bind' return' unit' (v_ty `|-> t) = v_ty `|-> imp_monad_bind bind' return' unit' t |
353 | imp_monad_bind bind' return' unit' (ICase (((t, ty), pats), t0)) = ICase |
353 | imp_monad_bind bind' return' unit' (ICase (((t, ty), pats), t0)) = ICase |
354 (((imp_monad_bind bind' return' unit' t, ty), (map o pairself) (imp_monad_bind bind' return' unit') pats), imp_monad_bind bind' return' unit' t0); |
354 (((imp_monad_bind bind' return' unit' t, ty), (map o pairself) (imp_monad_bind bind' return' unit') pats), imp_monad_bind bind' return' unit' t0); |
355 |
355 |
356 fun imp_program naming = (Graph.map_nodes o map_terms_stmt) |
356 fun imp_program naming = (Graph.map_nodes o map_terms_stmt) |
357 (imp_monad_bind (lookup naming @{const_name bindM}) |
357 (imp_monad_bind (lookup naming @{const_name bindM}) |
358 (lookup naming @{const_name return}) |
358 (lookup naming @{const_name return}) |
359 (lookup naming @{const_name Unity})); |
359 (lookup naming @{const_name Unity})); |
360 |
360 |
361 in |
361 in |
362 |
362 |
363 Code_Target.extend_target ("SML_imp", ("SML", imp_program)) |
363 Code_Target.extend_target ("SML_imp", ("SML", imp_program)) |
364 #> Code_Target.extend_target ("OCaml_imp", ("OCaml", imp_program)) |
364 #> Code_Target.extend_target ("OCaml_imp", ("OCaml", imp_program)) |