equal
deleted
inserted
replaced
434 (*see also signature*); |
434 (*see also signature*); |
435 |
435 |
436 type program = stmt Graph.T; |
436 type program = stmt Graph.T; |
437 |
437 |
438 fun empty_funs program = |
438 fun empty_funs program = |
439 Graph.fold (fn (name, (Fun (c, ((_, []), _)), _)) => cons c |
439 Graph.fold (fn (_, (Fun (c, ((_, []), _)), _)) => cons c | _ => I) program []; |
440 | _ => I) program []; |
|
441 |
440 |
442 fun map_terms_bottom_up f (t as IConst _) = f t |
441 fun map_terms_bottom_up f (t as IConst _) = f t |
443 | map_terms_bottom_up f (t as IVar _) = f t |
442 | map_terms_bottom_up f (t as IVar _) = f t |
444 | map_terms_bottom_up f (t1 `$ t2) = f |
443 | map_terms_bottom_up f (t1 `$ t2) = f |
445 (map_terms_bottom_up f t1 `$ map_terms_bottom_up f t2) |
444 (map_terms_bottom_up f t1 `$ map_terms_bottom_up f t2) |
531 fun add_dep name = case dep of NONE => I |
530 fun add_dep name = case dep of NONE => I |
532 | SOME dep => Graph.add_edge (dep, name); |
531 | SOME dep => Graph.add_edge (dep, name); |
533 val (name, naming') = case lookup naming thing |
532 val (name, naming') = case lookup naming thing |
534 of SOME name => (name, naming) |
533 of SOME name => (name, naming) |
535 | NONE => declare thing naming; |
534 | NONE => declare thing naming; |
536 in case try (Graph.get_node program) name |
535 in |
537 of SOME stmt => program |
536 if can (Graph.get_node program) name |
538 |> add_dep name |
537 then |
539 |> pair naming' |
538 program |
540 |> pair dep |
539 |> add_dep name |
541 |> pair name |
540 |> pair naming' |
542 | NONE => program |
541 |> pair dep |
543 |> Graph.default_node (name, NoStmt) |
542 |> pair name |
544 |> add_dep name |
543 else |
545 |> pair naming' |
544 program |
546 |> curry generate (SOME name) |
545 |> Graph.default_node (name, NoStmt) |
547 ||> snd |
546 |> add_dep name |
548 |-> (fn stmt => (apsnd o Graph.map_node name) (K stmt)) |
547 |> pair naming' |
549 |> pair dep |
548 |> curry generate (SOME name) |
550 |> pair name |
549 ||> snd |
|
550 |-> (fn stmt => (apsnd o Graph.map_node name) (K stmt)) |
|
551 |> pair dep |
|
552 |> pair name |
551 end; |
553 end; |
552 |
554 |
553 exception PERMISSIVE of unit; |
555 exception PERMISSIVE of unit; |
554 |
556 |
555 fun translation_error thy permissive some_thm msg sub_msg = |
557 fun translation_error thy permissive some_thm msg sub_msg = |
586 val untag_term = map_types (snd o dest_tagged_type); |
588 val untag_term = map_types (snd o dest_tagged_type); |
587 |
589 |
588 fun tag_term (proj_sort, _) eqngr = |
590 fun tag_term (proj_sort, _) eqngr = |
589 let |
591 let |
590 val has_sort_constraints = exists (not o null) o map proj_sort o Code_Preproc.sortargs eqngr; |
592 val has_sort_constraints = exists (not o null) o map proj_sort o Code_Preproc.sortargs eqngr; |
591 fun tag (Const (c', T')) (Const (c, T)) = |
593 fun tag (Const (_, T')) (Const (c, T)) = |
592 Const (c, |
594 Const (c, |
593 mk_tagged_type (not (null (Term.add_tvarsT T' [])) andalso has_sort_constraints c, T)) |
595 mk_tagged_type (not (null (Term.add_tvarsT T' [])) andalso has_sort_constraints c, T)) |
594 | tag (t1 $ u1) (t $ u) = tag t1 t $ tag u1 u |
596 | tag (t1 $ u1) (t $ u) = tag t1 t $ tag u1 u |
595 | tag (Abs (_, _, t1)) (Abs (x, T, t)) = Abs (x, T, tag t1 t) |
597 | tag (Abs (_, _, t1)) (Abs (x, T, t)) = Abs (x, T, tag t1 t) |
596 | tag (Free _) (t as Free _) = t |
598 | tag (Free _) (t as Free _) = t |
963 fun dynamic_value thy postproc evaluator = |
965 fun dynamic_value thy postproc evaluator = |
964 Code_Preproc.dynamic_value thy postproc (dynamic_evaluator thy evaluator); |
966 Code_Preproc.dynamic_value thy postproc (dynamic_evaluator thy evaluator); |
965 |
967 |
966 fun lift_evaluation thy evaluation' algebra eqngr naming program vs t = |
968 fun lift_evaluation thy evaluation' algebra eqngr naming program vs t = |
967 let |
969 let |
968 val (((_, program'), (((vs', ty'), t'), deps)), _) = |
970 val (((_, _), (((vs', ty'), t'), deps)), _) = |
969 ensure_value thy algebra eqngr t (NONE, (naming, program)); |
971 ensure_value thy algebra eqngr t (NONE, (naming, program)); |
970 in evaluation' ((original_sorts vs vs', (vs', ty')), t') deps end; |
972 in evaluation' ((original_sorts vs vs', (vs', ty')), t') deps end; |
971 |
973 |
972 fun lift_evaluator thy evaluator' consts algebra eqngr = |
974 fun lift_evaluator thy evaluator' consts algebra eqngr = |
973 let |
975 let |
980 |
982 |
981 fun lift_evaluator_simple thy evaluator' consts algebra eqngr = |
983 fun lift_evaluator_simple thy evaluator' consts algebra eqngr = |
982 let |
984 let |
983 fun generate_consts thy algebra eqngr = |
985 fun generate_consts thy algebra eqngr = |
984 fold_map (ensure_const thy algebra eqngr false); |
986 fold_map (ensure_const thy algebra eqngr false); |
985 val (consts', (naming, program)) = |
987 val (_, (_, program)) = |
986 invoke_generation true thy (algebra, eqngr) generate_consts consts; |
988 invoke_generation true thy (algebra, eqngr) generate_consts consts; |
987 in evaluator' program end; |
989 in evaluator' program end; |
988 |
990 |
989 fun static_conv thy consts conv = |
991 fun static_conv thy consts conv = |
990 Code_Preproc.static_conv thy consts (lift_evaluator thy conv consts); |
992 Code_Preproc.static_conv thy consts (lift_evaluator thy conv consts); |