Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LARA
inox
Commits
0c172123
Commit
0c172123
authored
10 years ago
by
Manos Koukoutos
Browse files
Options
Downloads
Patches
Plain Diff
Return to nested IfExpr repr. for FiniteLambda
parent
d85c97c1
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/scala/leon/purescala/Constructors.scala
+12
-12
12 additions, 12 deletions
src/main/scala/leon/purescala/Constructors.scala
src/main/scala/leon/purescala/Extractors.scala
+25
-15
25 additions, 15 deletions
src/main/scala/leon/purescala/Extractors.scala
with
37 additions
and
27 deletions
src/main/scala/leon/purescala/Constructors.scala
+
12
−
12
View file @
0c172123
...
...
@@ -222,21 +222,21 @@ object Constructors {
NonemptyArray
(
els
.
zipWithIndex
.
map
{
_
.
swap
}.
toMap
,
defaultLength
)
}
/*
* Take a mapping from keys to values and a default expression and return a lambda of the form
* (x1, ..., xn) =>
* if ( key1 == (x1, ..., xn) ) value1
* else if ( key2 == (x1, ..., xn) ) value2
* ...
* else default
*/
def
finiteLambda
(
default
:
Expr
,
els
:
Seq
[(
Expr
,
Expr
)],
inputTypes
:
Seq
[
TypeTree
])
:
Lambda
=
{
val
args
=
inputTypes
map
{
tpe
=>
ValDef
(
FreshIdentifier
(
"x"
,
tpe
,
true
))
}
if
(
els
.
isEmpty
)
{
Lambda
(
args
,
default
)
}
else
{
val
theMap
=
NonemptyMap
(
els
)
val
theMapVar
=
FreshIdentifier
(
"pairs"
,
theMap
.
getType
,
true
)
val
argsAsExpr
=
tupleWrap
(
args
map
{
_
.
toVariable
})
val
body
=
Let
(
theMapVar
,
theMap
,
IfExpr
(
MapIsDefinedAt
(
Variable
(
theMapVar
),
argsAsExpr
),
MapGet
(
Variable
(
theMapVar
),
argsAsExpr
),
default
))
Lambda
(
args
,
body
)
val
argsExpr
=
tupleWrap
(
args
map
{
_
.
toVariable
})
val
body
=
els
.
foldRight
(
default
)
{
case
((
key
,
value
),
default
)
=>
IfExpr
(
Equals
(
argsExpr
,
key
),
value
,
default
)
}
Lambda
(
args
,
body
)
}
def
application
(
fn
:
Expr
,
realArgs
:
Seq
[
Expr
])
=
fn
match
{
...
...
This diff is collapsed.
Click to expand it.
src/main/scala/leon/purescala/Extractors.scala
+
25
−
15
View file @
0c172123
...
...
@@ -234,26 +234,36 @@ object Extractors {
def
unapply
[
T
<:
Typed
](
e
:
T
)
:
Option
[(
T
,
TypeTree
)]
=
Some
((
e
,
e
.
getType
))
}
/*
* Extract a default expression and key-value pairs from a lambda constructed with
* Constructors.finiteLambda
*/
object
FiniteLambda
{
def
unapply
(
lambda
:
Lambda
)
:
Option
[(
Expr
,
Seq
[(
Expr
,
Expr
)])]
=
{
val
inSize
=
lambda
.
getType
.
asInstanceOf
[
FunctionType
].
from
.
size
lambda
match
{
case
Lambda
(
args
,
Let
(
theMapVar
,
FiniteMap
(
pairs
),
IfExpr
(
MapIsDefinedAt
(
Variable
(
theMapVar1
),
targs2
),
MapGet
(
Variable
(
theMapVar2
),
targs3
),
default
)))
if
{
val
args2
=
unwrapTuple
(
targs2
,
inSize
)
val
args3
=
unwrapTuple
(
targs3
,
inSize
)
(
args
map
{
x
:
ValDef
=>
x
.
toVariable
})
==
args2
&&
args2
==
args3
&&
theMapVar
==
theMapVar1
&&
theMapVar
==
theMapVar2
val
Lambda
(
args
,
body
)
=
lambda
def
step
(
e
:
Expr
)
:
(
Option
[(
Expr
,
Expr
)],
Expr
)
=
e
match
{
case
IfExpr
(
Equals
(
argsExpr
,
key
),
value
,
default
)
if
{
val
formal
=
args
.
map
{
_
.
id
}
val
real
=
unwrapTuple
(
argsExpr
,
inSize
).
collect
{
case
Variable
(
id
)
=>
id
}
formal
==
real
}
=>
Some
(
default
,
pairs
)
case
Lambda
(
args
,
default
)
if
(
variablesOf
(
default
)
&
args
.
toSet
.
map
{
x
:
ValDef
=>
x
.
id
}).
isEmpty
=>
Some
(
default
,
Seq
())
case
_
=>
None
(
Some
((
key
,
value
)),
default
)
case
other
=>
(
None
,
other
)
}
def
rec
(
e
:
Expr
)
:
(
Expr
,
Seq
[(
Expr
,
Expr
)])
=
{
step
(
e
)
match
{
case
(
None
,
default
)
=>
(
default
,
Seq
())
case
(
Some
(
pair
),
default
)
=>
val
(
defaultRest
,
pairs
)
=
rec
(
default
)
(
defaultRest
,
pair
+:
pairs
)
}
}
Some
(
rec
(
body
))
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment