curry.toolchain.flat2icurry package
The translation from FlatCurry to ICurry.
This is a port of the Curry package icurry 3.1.0 by Michael Hanus. It
reads the FlatCurry of a module and the FlatCurry interfaces of its imports,
and it produces the ICurry term that icurry writes to a .icy file. The
passes run in this order:
The rewrite step of the routes (
rewrite_prog()), when the caller asks for it: the binding optimization (bindingopt; the Boolean equalities whose value is required to be True become equational constraints, as the preprocessing of PAKCS makes them) and the set0 lift (setlift;set0 eover the captured variables ofebecomessetk L xs). The routes from Curry to ICurry do not ask for it here: they apply it to the FlatCurry file itself before the translation (rewrite_file()), as PAKCS applies its preprocessing, so the file on disk is the rewritten program and theicurryprogram sees it too. The flag serves a caller that must not touch the file, such as the option--rewriteof the command line. The oracle tests do not ask for it. The command line ofrewriteapplies the step to files by hand.Newtype elimination (
elimnewtype).Case completion against the data declarations of the module and its imports (
casecompletion).Lifting of nested cases, lets, and free declarations into new functions (
caselifting).The name-to-index maps and the ICurry generation (
compiler).
showterm() prints the result as the PAKCS showTerm does, so the
text is byte-identical to the output of icurry under PAKCS.
write_flatcurry() writes a FlatCurry program as the front end does.
One defect of icurry 3.1.0 is kept behind the flag icurry_compat,
which is on by default: a type annotation at the root of a rule hides a
case, a let, or a free declaration from the block builder. See
compiler.to_iblock(). The oracle tests keep the flag on, so the
output stays byte-identical to the files icurry wrote. The build route
(curry.toolchain._frontend) turns it off, so the programs it compiles
run.
- exception curry.toolchain.flat2icurry.Flat2ICurryError[source]
Bases:
CompileErrorAn error in the translation from FlatCurry to ICurry.
- class curry.toolchain.flat2icurry.InterfaceFinder(searchdirs, subdirs, progs=())[source]
Bases:
objectLooks up the interface of a module by name.
- Parameters:
searchdirs – The directories to search, as a Curry path.
subdirs – The names of the subdirectories of
.currythat hold the front end output, e.g.,['pakcs-3.4.1'].progs – Programs already in hand, used before any file is read.
- curry.toolchain.flat2icurry.load_flatcurry(filename)
Reads a FlatCurry program (or interface) from a file.
- curry.toolchain.flat2icurry.load_interface(filename)[source]
Reads a FlatCurry file. Files are cached by name, size, and time.
- curry.toolchain.flat2icurry.module_root(fcyfile, modname)[source]
The directory from which the module
modnamewas compiled, given its FlatCurry file. The file of moduleA.Blies at<root>/.curry/<subdir>/A/B.fcyor at<root>/A/.curry/<subdir>/B.fcy.
- curry.toolchain.flat2icurry.optimize_bindings(prog, equivalence=True)[source]
Applies the binding optimization to a FlatCurry program. Returns the transformed program when an equality was replaced, else
progitself: transbooleq writes a file only then, so a rule whose equalities all stay is rebuilt (its$reduced) only in a program that is transformed.
- curry.toolchain.flat2icurry.optimize_file(fcyfile, equivalence=True)[source]
Applies the binding optimization to the FlatCurry file
fcyfilein place. The file is written again, in the format of the front end, when the pass replaced an equality; else it is left as it is, with its time. Returns the number of equalities replaced.
- curry.toolchain.flat2icurry.optimize_set0(prog)[source]
Applies the set0 lift to a FlatCurry program. Returns the transformed program when a call was lifted, else
progitself.
- curry.toolchain.flat2icurry.product_path(filename)[source]
Splits the path of a front-end product into
(root, subdir, tail). The file lies at<root>/.curry/<subdir>/<tail>/M.ext;tailis empty for a module at the top level andA/Bfor a module underA.B. Returns None when no.currydirectory encloses the file.
- curry.toolchain.flat2icurry.read_flatcurry(text)
Reads a FlatCurry program (or interface) from .fcy text.
- curry.toolchain.flat2icurry.rewrite_file(fcyfile, equivalence=True)[source]
Applies the rewrite step to the FlatCurry file
fcyfilein place, as the routes do after the front end wrote it. The file is written again, in the format of the front end, when a pass changed the program; else it is left as it is, with its time. Returns the pair of counts ofrewrite_prog().
- curry.toolchain.flat2icurry.rewrite_prog(prog, equivalence=True)[source]
Applies the rewrite step of the routes to a FlatCurry program in memory: the binding optimization, then the set0 lift. Returns the program and the pair of counts (equalities replaced, set0 calls lifted); the program is
progitself when both counts are zero. The result of the binding optimization counts only when it replaced an equality, asbindingopt.optimize_bindings()has it (a rule it rebuilt without a replacement, its$reduced, is not handed on), so the lift runs over the program the former route translated. Withoutequivalencethe binding optimization replaces===and/==alone (seebindingopt.transform_prog()).
- curry.toolchain.flat2icurry.show_flatcurry(prog)
The text of a FlatCurry program (or interface) as the front end writes it: the
showof Haskell, on one line, without a newline at the end.
- curry.toolchain.flat2icurry.showhaskell(term)[source]
Prints a term as the
showof Haskell does with the derivedShowinstances: the format of the FlatCurry files of the Curry front end. A constructor with arguments is in parentheses when it is an argument; a negative number is in parentheses when it is an argument; the elements of a list and of a tuple are not. There is no newline.
- curry.toolchain.flat2icurry.showterm(term)[source]
Prints a term as the PAKCS
showTermdoes. There is no newline.
- curry.toolchain.flat2icurry.translate(prog, interfaces, icurry_compat=True, rewrite=False)[source]
Translates a FlatCurry program to ICurry.
- Parameters:
prog – The FlatCurry program.
interfaces – The FlatCurry interfaces of the imports of
prog, in import order.icurry_compat – Whether to keep the output of
icurry3.1.0 for a type annotation at the root of a rule. Seecompiler.to_iblock().rewrite – Whether to apply the rewrite step of the routes first, the binding optimization and the set0 lift. See
rewrite_prog().
- Returns:
The ICurry program, an
IProgterm.
- curry.toolchain.flat2icurry.translate_file(fcyfile, finder, icurry_compat=True, rewrite=False)[source]
Translates the FlatCurry file
fcyfile.finderis anInterfaceFinderthat supplies the interfaces of the imports.
- curry.toolchain.flat2icurry.write_flatcurry(prog, filename)
Writes a FlatCurry program to a file in the format of the front end. The text goes to a file beside the target first, which then takes the place of the target, so a reader never sees a partial file.
- curry.toolchain.flat2icurry.write_icurry(iprog, filename)[source]
Writes an ICurry program to a .icy file.
Submodules
- curry.toolchain.flat2icurry.bindingopt module
- curry.toolchain.flat2icurry.casecompletion module
- curry.toolchain.flat2icurry.caselifting module
- curry.toolchain.flat2icurry.compiler module
- curry.toolchain.flat2icurry.elimnewtype module
- curry.toolchain.flat2icurry.errors module
- curry.toolchain.flat2icurry.flatcurry module
BranchCaseCaseTypeCharcCombCombTypeConsConsPartCallExprExternalFixityFloatcForallTypeFreeFuncFuncPartCallFuncTypeIntcKArrowKindLPatternLetLitLiteralNewConsOpOrPatternPatternDeclProgRuleRuleDeclTConsTVarTypeTypeDeclTypeExprTypeNewTypeSynTypedVarVisibilityall_vars()data_decls_of()decode()load()prelude()read()show()write()
- curry.toolchain.flat2icurry.icurrytypes module
- curry.toolchain.flat2icurry.interfaces module
- curry.toolchain.flat2icurry.rewrite module
- curry.toolchain.flat2icurry.setlift module
- curry.toolchain.flat2icurry.terms module