doc-src/IsarAdvanced/Codegen/Thy/Codegen.thy
changeset 21217 0425fc57510f
parent 21189 5435ccdb4ea1
child 21222 6dfdb69e83ef
equal deleted inserted replaced
21216:1c8580913738 21217:0425fc57510f
   718 (*<*)
   718 (*<*)
   719 lemmas [code func] = collect_duplicates.simps
   719 lemmas [code func] = collect_duplicates.simps
   720 (*>*)
   720 (*>*)
   721 
   721 
   722 text {*
   722 text {*
   723   The membership test during preprocessing is rewriting,
   723   The membership test during preprocessing is rewritten,
   724   resulting in @{const List.memberl}, which itself
   724   resulting in @{const List.memberl}, which itself
   725   performs an explicit equality check.
   725   performs an explicit equality check.
   726 *}
   726 *}
   727 
   727 
   728 code_gen collect_duplicates (SML "examples/collect_duplicates.ML")
   728 code_gen collect_duplicates (SML "examples/collect_duplicates.ML")
  1269 *}
  1269 *}
  1270 
  1270 
  1271 subsection {* Function equation systems: codegen\_funcgr.ML *}
  1271 subsection {* Function equation systems: codegen\_funcgr.ML *}
  1272 
  1272 
  1273 text {*
  1273 text {*
  1274   
  1274   Out of the executable content of a theory, a normalized
       
  1275   function equation systems may be constructed containing
       
  1276   function definitions for constants.  The system is cached
       
  1277   until its underlying executable content changes.
  1275 *}
  1278 *}
  1276 
  1279 
  1277 text %mlref {*
  1280 text %mlref {*
  1278   \begin{mldecls}
  1281   \begin{mldecls}
  1279   @{index_ML_type CodegenFuncgr.T} \\
  1282   @{index_ML_type CodegenFuncgr.T} \\
  1282   @{index_ML CodegenFuncgr.typ: "CodegenFuncgr.T -> CodegenConsts.const -> typ"} \\
  1285   @{index_ML CodegenFuncgr.typ: "CodegenFuncgr.T -> CodegenConsts.const -> typ"} \\
  1283   @{index_ML CodegenFuncgr.deps: "CodegenFuncgr.T
  1286   @{index_ML CodegenFuncgr.deps: "CodegenFuncgr.T
  1284     -> CodegenConsts.const list -> CodegenConsts.const list list"} \\
  1287     -> CodegenConsts.const list -> CodegenConsts.const list list"} \\
  1285   @{index_ML CodegenFuncgr.all: "CodegenFuncgr.T -> CodegenConsts.const list"}
  1288   @{index_ML CodegenFuncgr.all: "CodegenFuncgr.T -> CodegenConsts.const list"}
  1286   \end{mldecls}
  1289   \end{mldecls}
       
  1290 
       
  1291   \begin{description}
       
  1292 
       
  1293   \item @{ML_type CodegenFuncgr.T} represents
       
  1294     a normalized function equation system.
       
  1295 
       
  1296   \item @{ML CodegenFuncgr.make}~@{text thy}~@{text cs}
       
  1297     returns a normalized function equation system,
       
  1298     with the assertion that it contains any function
       
  1299     definition for constants @{text cs} (if exisiting).
       
  1300 
       
  1301   \item @{ML CodegenFuncgr.funcs}~@{text funcgr}~@{text c}
       
  1302     retrieves function definition for constant @{text c}.
       
  1303 
       
  1304   \item @{ML CodegenFuncgr.typ}~@{text funcgr}~@{text c}
       
  1305     retrieves function type for constant @{text c}.
       
  1306 
       
  1307   \item @{ML CodegenFuncgr.deps}~@{text funcgr}~@{text cs}
       
  1308     returns the transitive closure of dependencies for
       
  1309     constants @{text cs} as a partitioning where each partition
       
  1310     corresponds to a strongly connected component of
       
  1311     dependencies and any partition does \emph{not}
       
  1312     depend on partitions further left.
       
  1313 
       
  1314   \item @{ML CodegenFuncgr.all}~@{text funcgr}
       
  1315     returns all currently represented constants.
       
  1316 
       
  1317   \end{description}
  1287 *}
  1318 *}
  1288 
  1319 
  1289 subsection {* Further auxiliary *}
  1320 subsection {* Further auxiliary *}
  1290 
  1321 
  1291 text %mlref {*
  1322 text %mlref {*
  1297   @{index_ML_structure CodegenConsts.Consttab} \\
  1328   @{index_ML_structure CodegenConsts.Consttab} \\
  1298   @{index_ML_structure CodegenFuncgr.Constgraph} \\
  1329   @{index_ML_structure CodegenFuncgr.Constgraph} \\
  1299   @{index_ML CodegenData.typ_func: "theory -> thm -> typ"} \\
  1330   @{index_ML CodegenData.typ_func: "theory -> thm -> typ"} \\
  1300   @{index_ML CodegenData.rewrite_func: "thm list -> thm -> thm"} \\
  1331   @{index_ML CodegenData.rewrite_func: "thm list -> thm -> thm"} \\
  1301   \end{mldecls}
  1332   \end{mldecls}
       
  1333 
       
  1334   \begin{description}
       
  1335 
       
  1336   \item @{ML CodegenConsts.const_ord},~@{ML CodegenConsts.eq_const}
       
  1337      provide order and equality on constant identifiers.
       
  1338 
       
  1339   \item @{ML_struct CodegenConsts.Consttab},~@{ML_struct CodegenFuncgr.Constgraph}
       
  1340      provide advanced data structures with constant identifiers as keys.
       
  1341 
       
  1342   \item @{ML CodegenConsts.consts_of}~@{text thy}~@{text t}
       
  1343      returns all constant identifiers mentioned in a term @{text t}.
       
  1344 
       
  1345   \item @{ML CodegenConsts.read_const}~@{text thy}~@{text s}
       
  1346      reads a constant as a concrete term expression @{text s}.
       
  1347 
       
  1348   \item @{ML CodegenData.typ_func}~@{text thy}~@{text thm}
       
  1349      extracts the type of a constant in a function equation @{text thm}.
       
  1350 
       
  1351   \item @{ML CodegenData.rewrite_func}~@{text rews}~@{text thm}
       
  1352      rewrites a function equation @{text thm} with a set of rewrite
       
  1353      rules @{text rews}; only arguments and right hand side are rewritten,
       
  1354      not the head of the function equation.
       
  1355 
       
  1356   \end{description}
       
  1357 
  1302 *}
  1358 *}
  1303 
  1359 
  1304 subsection {* Implementing code generator applications *}
  1360 subsection {* Implementing code generator applications *}
  1305 
  1361 
  1306 text {*
  1362 text {*
       
  1363   Implementing code generator applications on top
       
  1364   of the framework set out so far usually not only
       
  1365   involves using those primitive interfaces
       
  1366   but also storing code-dependent data and various
       
  1367   other things.
       
  1368 
  1307   \begin{warn}
  1369   \begin{warn}
  1308     Some interfaces discussed here have not reached
  1370     Some interfaces discussed here have not reached
  1309     a final state yet.
  1371     a final state yet.
  1310     Changes likely to occur in future.
  1372     Changes likely to occur in future.
  1311   \end{warn}
  1373   \end{warn}
  1312 *}
  1374 *}
  1313 
  1375 
  1314 subsubsection {* Data depending on the theory's executable content *}
  1376 subsubsection {* Data depending on the theory's executable content *}
  1315 
  1377 
       
  1378 text {*
       
  1379   \medskip
       
  1380   \begin{tabular}{l}
       
  1381   @{text "val name: string"} \\
       
  1382   @{text "type T"} \\
       
  1383   @{text "val empty: T"} \\
       
  1384   @{text "val merge: Pretty.pp \<rightarrow> T * T \<rightarrow> T"} \\
       
  1385   @{text "val purge: theory option \<rightarrow> CodegenConsts.const list option \<rightarrow> T \<rightarrow> T"}
       
  1386   \end{tabular}
       
  1387 
       
  1388   \medskip
       
  1389 
       
  1390   \begin{tabular}{l}
       
  1391   @{text "init: theory \<rightarrow> theory"} \\
       
  1392   @{text "get: theory \<rightarrow> T"} \\
       
  1393   @{text "change: theory \<rightarrow> (T \<rightarrow> T) \<rightarrow> T"} \\
       
  1394   @{text "change_yield: theory \<rightarrow> (T \<rightarrow> 'a * T) \<rightarrow> 'a * T"}
       
  1395   \end{tabular}
       
  1396 *}
       
  1397 
       
  1398 text %mlref {*
       
  1399   \begin{mldecls}
       
  1400   @{index_ML_functor CodeDataFun}
       
  1401   \end{mldecls}
       
  1402 
       
  1403   \begin{description}
       
  1404 
       
  1405   \item @{ML_functor CodeDataFun}@{text "(spec)"} declares code
       
  1406   dependent data according to the specification provided as
       
  1407   argument structure.  The resulting structure provides data init and
       
  1408   access operations as described above.
       
  1409 
       
  1410   \end{description}
       
  1411 *}
       
  1412 
  1316 subsubsection {* Datatype hooks *}
  1413 subsubsection {* Datatype hooks *}
  1317 
  1414 
  1318 text {*
  1415 text %mlref {*
       
  1416   \begin{mldecls}
       
  1417   @{index_ML_type DatatypeHooks.hook} \\
       
  1418   @{index_ML DatatypeHooks.add: "DatatypeHooks.hook -> theory -> theory"}
       
  1419   \end{mldecls}
       
  1420 *}
       
  1421 
       
  1422 text %mlref {*
       
  1423   \begin{mldecls}
       
  1424   @{index_ML_type TypecopyPackage.info} \\
       
  1425   @{index_ML TypecopyPackage.add_typecopy: "
       
  1426     bstring * string list -> typ -> (bstring * bstring) option
       
  1427     -> theory -> (string * TypecopyPackage.info) * theory"} \\
       
  1428   @{index_ML TypecopyPackage.get_typecopies: "theory -> string list"} \\
       
  1429   @{index_ML TypecopyPackage.get_typecopy_info: "theory
       
  1430     -> string -> TypecopyPackage.info option"} \\
       
  1431   @{index_ML_type TypecopyPackage.hook} \\
       
  1432   @{index_ML TypecopyPackage.add_hook: "TypecopyPackage.hook -> theory -> theory"} \\
       
  1433   @{index_ML TypecopyPackage.get_spec: "theory -> string
       
  1434     -> (string * sort) list * (string * typ list) list"}
       
  1435   \end{mldecls}
       
  1436 *}
       
  1437 
       
  1438 text %mlref {*
       
  1439   \begin{mldecls}
       
  1440   @{index_ML_type DatatypeCodegen.hook} \\
       
  1441   @{index_ML DatatypeCodegen.add_codetypes_hook_bootstrap: "
       
  1442       DatatypeCodegen.hook -> theory -> theory"}
       
  1443   \end{mldecls}
       
  1444 *}
       
  1445 
       
  1446 (*text {*
  1319   \emph{Happy proving, happy hacking!}
  1447   \emph{Happy proving, happy hacking!}
  1320 *}
  1448 *}*)
  1321 
  1449 
  1322 end
  1450 end