51 |
52 |
52 datatype truth = Holds; |
53 datatype truth = Holds; |
53 |
54 |
54 val _ = Theory.setup |
55 val _ = Theory.setup |
55 (Code_Target.extend_target (target, (Code_ML.target_SML, I)) |
56 (Code_Target.extend_target (target, (Code_ML.target_SML, I)) |
56 #> Code_Target.set_printings (Code_Symbol.Type_Constructor (@{type_name prop}, |
57 #> Code_Target.set_printings (Type_Constructor (@{type_name prop}, |
57 [(target, SOME (0, (K o K o K) (Code_Printer.str s_truth)))])) |
58 [(target, SOME (0, (K o K o K) (Code_Printer.str s_truth)))])) |
58 #> Code_Target.set_printings (Code_Symbol.Constant (@{const_name Code_Generator.holds}, |
59 #> Code_Target.set_printings (Constant (@{const_name Code_Generator.holds}, |
59 [(target, SOME (Code_Printer.plain_const_syntax s_Holds))])) |
60 [(target, SOME (Code_Printer.plain_const_syntax s_Holds))])) |
60 #> Code_Target.add_reserved target this |
61 #> Code_Target.add_reserved target this |
61 #> fold (Code_Target.add_reserved target) ["oo", "ooo", "oooo", "upto", "downto", "orf", "andf"]); |
62 #> fold (Code_Target.add_reserved target) ["oo", "ooo", "oooo", "upto", "downto", "orf", "andf"]); |
62 (*avoid further pervasive infix names*) |
63 (*avoid further pervasive infix names*) |
63 |
64 |
90 fun obtain_evaluator thy some_target program consts expr = |
91 fun obtain_evaluator thy some_target program consts expr = |
91 Code_Target.evaluator thy (the_default target some_target) program consts expr |
92 Code_Target.evaluator thy (the_default target some_target) program consts expr |
92 |> apfst (fn ml_modules => space_implode "\n\n" (map snd ml_modules)); |
93 |> apfst (fn ml_modules => space_implode "\n\n" (map snd ml_modules)); |
93 |
94 |
94 fun obtain_evaluator' thy some_target program = |
95 fun obtain_evaluator' thy some_target program = |
95 obtain_evaluator thy some_target program o map Code_Symbol.Constant; |
96 obtain_evaluator thy some_target program o map Constant; |
96 |
97 |
97 fun evaluation cookie thy evaluator vs_t args = |
98 fun evaluation cookie thy evaluator vs_t args = |
98 let |
99 let |
99 val ctxt = Proof_Context.init_global thy; |
100 val ctxt = Proof_Context.init_global thy; |
100 val (program_code, value_name) = evaluator vs_t; |
101 val (program_code, value_name) = evaluator vs_t; |
196 let |
197 let |
197 val ctxt = Proof_Context.init_global thy; |
198 val ctxt = Proof_Context.init_global thy; |
198 val program = Code_Thingol.consts_program thy false consts; |
199 val program = Code_Thingol.consts_program thy false consts; |
199 val (ml_modules, target_names) = |
200 val (ml_modules, target_names) = |
200 Code_Target.produce_code_for thy |
201 Code_Target.produce_code_for thy |
201 target NONE module_name [] program (map Code_Symbol.Constant consts @ map Code_Symbol.Type_Constructor tycos); |
202 target NONE module_name [] program (map Constant consts @ map Type_Constructor tycos); |
202 val ml_code = space_implode "\n\n" (map snd ml_modules); |
203 val ml_code = space_implode "\n\n" (map snd ml_modules); |
203 val (consts', tycos') = chop (length consts) target_names; |
204 val (consts', tycos') = chop (length consts) target_names; |
204 val consts_map = map2 (fn const => |
205 val consts_map = map2 (fn const => |
205 fn NONE => |
206 fn NONE => |
206 error ("Constant " ^ (quote o Code.string_of_const thy) const ^ |
207 error ("Constant " ^ (quote o Code.string_of_const thy) const ^ |
290 Code_Printer.concat [pr' Code_Printer.BR ty, tyco'] |
291 Code_Printer.concat [pr' Code_Printer.BR ty, tyco'] |
291 | pr pr' _ tys = |
292 | pr pr' _ tys = |
292 Code_Printer.concat [Code_Printer.enum "," "(" ")" (map (pr' Code_Printer.BR) tys), tyco'] |
293 Code_Printer.concat [Code_Printer.enum "," "(" ")" (map (pr' Code_Printer.BR) tys), tyco'] |
293 in |
294 in |
294 thy |
295 thy |
295 |> Code_Target.set_printings (Code_Symbol.Type_Constructor (tyco, [(target, SOME (k, pr))])) |
296 |> Code_Target.set_printings (Type_Constructor (tyco, [(target, SOME (k, pr))])) |
296 end; |
297 end; |
297 |
298 |
298 fun add_eval_constr (const, const') thy = |
299 fun add_eval_constr (const, const') thy = |
299 let |
300 let |
300 val k = Code.args_number thy const; |
301 val k = Code.args_number thy const; |
301 fun pr pr' fxy ts = Code_Printer.brackify fxy |
302 fun pr pr' fxy ts = Code_Printer.brackify fxy |
302 (const' :: the_list (Code_Printer.tuplify pr' Code_Printer.BR (map fst ts))); |
303 (const' :: the_list (Code_Printer.tuplify pr' Code_Printer.BR (map fst ts))); |
303 in |
304 in |
304 thy |
305 thy |
305 |> Code_Target.set_printings (Code_Symbol.Constant (const, |
306 |> Code_Target.set_printings (Constant (const, |
306 [(target, SOME (Code_Printer.simple_const_syntax (k, pr)))])) |
307 [(target, SOME (Code_Printer.simple_const_syntax (k, pr)))])) |
307 end; |
308 end; |
308 |
309 |
309 fun add_eval_const (const, const') = Code_Target.set_printings (Code_Symbol.Constant |
310 fun add_eval_const (const, const') = Code_Target.set_printings (Constant |
310 (const, [(target, SOME (Code_Printer.simple_const_syntax (0, (K o K o K) const')))])); |
311 (const, [(target, SOME (Code_Printer.simple_const_syntax (0, (K o K o K) const')))])); |
311 |
312 |
312 fun process_reflection (code, (tyco_map, (constr_map, const_map))) module_name NONE thy = |
313 fun process_reflection (code, (tyco_map, (constr_map, const_map))) module_name NONE thy = |
313 thy |
314 thy |
314 |> Code_Target.add_reserved target module_name |
315 |> Code_Target.add_reserved target module_name |
435 fun add_definiendum (ml_name, (b, T)) thy = |
436 fun add_definiendum (ml_name, (b, T)) thy = |
436 thy |
437 thy |
437 |> Code_Target.add_reserved target ml_name |
438 |> Code_Target.add_reserved target ml_name |
438 |> Specification.axiomatization [(b, SOME T, NoSyn)] [] |
439 |> Specification.axiomatization [(b, SOME T, NoSyn)] [] |
439 |-> (fn ([Const (const, _)], _) => |
440 |-> (fn ([Const (const, _)], _) => |
440 Code_Target.set_printings (Code_Symbol.Constant (const, |
441 Code_Target.set_printings (Constant (const, |
441 [(target, SOME (Code_Printer.simple_const_syntax (0, (K o K o K o Code_Printer.str) ml_name)))])) |
442 [(target, SOME (Code_Printer.simple_const_syntax (0, (K o K o K o Code_Printer.str) ml_name)))])) |
442 #> tap (fn thy => Code_Target.produce_code thy [const] target NONE structure_generated [])); |
443 #> tap (fn thy => Code_Target.produce_code thy [const] target NONE structure_generated [])); |
443 |
444 |
444 fun process_file filepath (definienda, thy) = |
445 fun process_file filepath (definienda, thy) = |
445 let |
446 let |