src/Tools/Code/code_target.ML
changeset 59323 468bd3aedfa1
parent 59104 a14475f044b2
child 59324 f5f9993a168d
equal deleted inserted replaced
59322:8ccecf1415b0 59323:468bd3aedfa1
    53   val set_printings: (Code_Printer.raw_const_syntax, Code_Printer.tyco_syntax, string, unit, unit, (string * string list)) symbol_attr_decl
    53   val set_printings: (Code_Printer.raw_const_syntax, Code_Printer.tyco_syntax, string, unit, unit, (string * string list)) symbol_attr_decl
    54     -> theory -> theory
    54     -> theory -> theory
    55   val add_reserved: string -> string -> theory -> theory
    55   val add_reserved: string -> string -> theory -> theory
    56 
    56 
    57   val codegen_tool: string (*theory name*) -> string (*export_code expr*) -> unit
    57   val codegen_tool: string (*theory name*) -> string (*export_code expr*) -> unit
    58 
       
    59   val setup: theory -> theory
       
    60 end;
    58 end;
    61 
    59 
    62 structure Code_Target : CODE_TARGET =
    60 structure Code_Target : CODE_TARGET =
    63 struct
    61 struct
    64 
    62 
   490       val thy = Proof_Context.theory_of ctxt;
   488       val thy = Proof_Context.theory_of ctxt;
   491     in (Sign.intern_class thy raw_tyco, Sign.intern_type thy raw_class) end) Class_Instance;
   489     in (Sign.intern_class thy raw_tyco, Sign.intern_type thy raw_class) end) Class_Instance;
   492 
   490 
   493 in
   491 in
   494 
   492 
   495 val antiq_setup =
   493 val _ = Theory.setup
   496   Thy_Output.antiquotation @{binding code_stmts}
   494   (Thy_Output.antiquotation @{binding code_stmts}
   497     (parse_const_terms --
   495     (parse_const_terms --
   498       Scan.repeat (parse_consts || parse_types || parse_classes || parse_instances)
   496       Scan.repeat (parse_consts || parse_types || parse_classes || parse_instances)
   499       -- Scan.lift (Args.parens (Args.name -- Scan.option Parse.int)))
   497       -- Scan.lift (Args.parens (Args.name -- Scan.option Parse.int)))
   500     (fn {context = ctxt, ...} => fn ((mk_cs, mk_stmtss), (target_name, some_width)) =>
   498     (fn {context = ctxt, ...} => fn ((mk_cs, mk_stmtss), (target_name, some_width)) =>
   501         present_code ctxt (mk_cs ctxt)
   499         present_code ctxt (mk_cs ctxt)
   502           (maps (fn f => f ctxt) mk_stmtss)
   500           (maps (fn f => f ctxt) mk_stmtss)
   503           target_name some_width "Example" []);
   501           target_name some_width "Example" []));
   504 
   502 
   505 end;
   503 end;
   506 
   504 
   507 
   505 
   508 (** serializer configuration **)
   506 (** serializer configuration **)
   671   in case parse cmd_expr
   669   in case parse cmd_expr
   672    of SOME f => (writeln "Now generating code..."; f ctxt)
   670    of SOME f => (writeln "Now generating code..."; f ctxt)
   673     | NONE => error ("Bad directive " ^ quote cmd_expr)
   671     | NONE => error ("Bad directive " ^ quote cmd_expr)
   674   end;
   672   end;
   675 
   673 
   676 
       
   677 (** theory setup **)
       
   678 
       
   679 val setup = antiq_setup;
       
   680 
       
   681 end; (*struct*)
   674 end; (*struct*)