Yhc Core is a way of dumping and using the internal representation of Yhc in an external project.

Yhc Core is a way of dumping and using the internal representation of Yhc in an external project.

−

== Haddock Documentation ==

+

== Haddock documentation ==

* http://www.cs.york.ac.uk/fp/yhc/snapshot/docs/Yhc-Core.html

* http://www.cs.york.ac.uk/fp/yhc/snapshot/docs/Yhc-Core.html

Line 31:

Line 31:

== Generating Core ==

== Generating Core ==

−

Yhc Core files are stored as .ycr files in a binary format. They can be generated by passing the <code>-core</code> flag to the compiler:

+

Yhc Core files are stored as .ycr files in a binary format. They can be generated by passing the <code>--core</code> flag to the compiler:

−

yhc -corep Main.hs

+

yhc --core Main.hs

−

If Core files are required for the standard libraries they can be built using <code>scons core=1</code>. To view the Core output, <code>yhc Main -showcore</code>, with the output going to the screen in a pretty printed format. To view an existing Core file, <code>yhc -viewcore File.ycr</code>.

+

If you want all definitions from all libraries included in then:

+

+

yhc --linkcore Main.hs

+

+

To view the Core output, <code>yhc Main --showcore</code>, with the output going to the screen in a pretty printed format. To view an existing Core file, <code>yhc --viewcore File.ycr</code>.

== The Core output ==

== The Core output ==

Line 80:

Line 84:

import Yhc.Core

import Yhc.Core

−

showFile x :: FilePath -> String

+

showFile :: FilePath -> IO ()

−

showFile x = liftM show (loadCore x)

+

showFile x = loadCore x >>= print

</haskell>

</haskell>

Line 97:

Line 101:

Here the linker ignores the import statements and the module name, of course you can do linking driven by the import statements easily.

Here the linker ignores the import statements and the module name, of course you can do linking driven by the import statements easily.

+

+

Note: The <code>--linkcore</code> option in Yhc does automatic linking

=== SHOUT AT EVERYONE ===

=== SHOUT AT EVERYONE ===

Line 106:

Line 112:

shout :: Core -> Core

shout :: Core -> Core

−

shout core = mapUnderCore f core

+

shout core = transformCore f core

where

where

f (CoreChr x) = CoreChr (toUpper x)

f (CoreChr x) = CoreChr (toUpper x)

Line 124:

Line 130:

count42 :: Core -> [(String,Int)]

count42 :: Core -> [(String,Int)]

count42 core = [(name, n) | func@(Func name _ _) <- coreFuncs core,

count42 core = [(name, n) | func@(Func name _ _) <- coreFuncs core,

−

let n = length $ filter is42 $ allCore func, n /= 0]

+

let n = length $ filter is42 $ universeCore func, n /= 0]

is42 :: CoreExpr -> Bool

is42 :: CoreExpr -> Bool

Line 135:

Line 141:

There are many invariants that hold in a Yhc Core program, and some that usually hold but aren't actually true. This secion lists both types.

There are many invariants that hold in a Yhc Core program, and some that usually hold but aren't actually true. This secion lists both types.