Commit 774b5db3 authored by Michael Hanus 's avatar Michael Hanus

Code refactoring

parent 104a1965
......@@ -55,6 +55,13 @@ In the following, we describe various uses of the `icurry` tool.
> icurry -v Prog
As a default, the ICurry compiler lifts all nested case/let expressions,
i.e., it transforms them into auxiliary top-level operations.
This is also necessary for the simple interpreter contained in this
package (see below).
If an implementation of ICurry can deal with nested case/let expressions,
one can use the option `--nolifting` to supress this lifting.
2. One can also use a simple (i.e., not efficient) interpreter
to execute ICurry programs and visualize their behavior.
In this case, one has to provide the name of a 0-ary function `mymain`
......
......@@ -157,14 +157,12 @@ trFunc opts (Func qn@(mn,fn) ar vis _ rule) =
where
optsf = opts { optFun = qn }
demandOf (External _) = [] -- TODO
demandOf (Rule args rhs) = case rhs of
Case _ ce _ -> case ce of
Var v -> maybe (funError optsf "case variable not in left-hand side")
(\i -> [i])
(elemIndex v args)
_ -> []
_ -> []
-- Computes (approximates) the arguments demanded by a rule.
demandOf :: Rule -> [Int]
demandOf (External _) = [] -- TODO
demandOf (Rule args rhs) = case rhs of
Case _ (Var v) _ -> maybe [] (: []) (elemIndex v args)
_ -> []
trRule :: ICOptions -> Rule -> IFuncBody
trRule _ (External s) = IExternal s
......
......@@ -30,7 +30,7 @@ testI p =
banner :: String
banner = unlines [bannerLine,bannerText,bannerLine]
where
bannerText = "ICurry Compiler (Version of 09/02/20)"
bannerText = "ICurry Compiler (Version of 13/02/20)"
bannerLine = take (length bannerText) (repeat '=')
main :: IO ()
......@@ -74,7 +74,7 @@ processOptions argv = do
(putStr (unlines opterrors) >> printUsage >> exitWith 1)
when (optHelp opts) (printUsage >> exitWith 0)
when (not (null (optMain opts)) && not (optLift opts)) $ error
"Incompatible options: nested case/let must be lifted for the interpreter"
"Incompatible options: interpreter requires case/let lifting!"
return (opts, map stripCurrySuffix args)
where
printUsage = putStrLn (banner ++ "\n" ++ usageText)
......@@ -106,7 +106,7 @@ options =
"command to view PDF files (default: 'evince')"
, Option "i" ["interactive"]
(NoArg (\opts -> opts { optInteractive = True }))
"interactive execution (ask after each result or step)"
"interactive execution (ask after each step/result)"
, Option "" ["nolifting"]
(NoArg (\opts -> opts { optLift = False }))
"do not lift nested case/let expressions"
......
......@@ -41,9 +41,12 @@ data IProg = IProg String [String] [IDataType] [IFunction]
data IDataType = IDataType IQName [(IQName,IArity)]
deriving (Show, Read)
--- An ICurry function declaration consisting of the function's name, arity,
--- the positions of always demandeded arguments (0 = first argument),
--- and a body.
--- An ICurry function declaration consisting of the function's name,
--- arity, visibility, the positions of always demandeded arguments
--- (where 0 denotes the first argument), and a body.
--- Note that the demanded arguments are definitely required to
--- evaluate the function. In some situations (e.g., complex nested case
--- statements), more arguments might be demanded.
data IFunction = IFunction IQName IArity IVisibility [Int] IFuncBody
deriving (Show, Read)
......@@ -71,12 +74,13 @@ data IBlock = IBlock [IVarDecl] [IAssign] IStatement
--- In the subsequent assignments, graph nodes will be assigned to
--- these variables. Instead of explicitly handling free variables,
--- one could also use local variables and assign a node representing
--- a value generator operation. Since different implementations
--- might you different strategies to deal with free variables,
--- ICurry supports both options.
--- a value generator operation for this free variable.
--- Since different implementations might use different strategies
--- to deal with free variables, ICurry supports both options.
---
--- NOTE: The ICurry variable with index 0 always points to the root
--- of the left-hand side when an ICurry function is invoked.
--- NOTE: The ICurry code assumes that the ICurry variable with index 0
--- always points to the root of the left-hand side when an ICurry function
--- is invoked. This invariant must be ensured by the ICurry application!
data IVarDecl = IVarDecl IVarIndex
| IFreeDecl IVarIndex
deriving (Show, Read)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment