Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
curry-packages
icurry
Commits
774b5db3
Commit
774b5db3
authored
Feb 13, 2020
by
Michael Hanus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code refactoring
parent
104a1965
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
19 deletions
+28
-19
README.md
README.md
+7
-0
src/ICurry/Compiler.curry
src/ICurry/Compiler.curry
+6
-8
src/ICurry/Main.curry
src/ICurry/Main.curry
+3
-3
src/ICurry/Types.curry
src/ICurry/Types.curry
+12
-8
No files found.
README.md
View file @
774b5db3
...
...
@@ -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`
...
...
src/ICurry/Compiler.curry
View file @
774b5db3
...
...
@@ -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
...
...
src/ICurry/Main.curry
View file @
774b5db3
...
...
@@ -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"
...
...
src/ICurry/Types.curry
View file @
774b5db3
...
...
@@ -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 variabl
es
,
--- ICurry supports both options.
--- a value generator operation
for this free variable.
---
Since
different
implementations might use different strategi
es
---
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)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment