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
1ec8524a
Commit
1ec8524a
authored
15 years ago
by
Philippe Suter
Browse files
Options
Downloads
Patches
Plain Diff
No commit message
No commit message
parent
a39bf16f
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/purescala/Analysis.scala
+1
-10
1 addition, 10 deletions
src/purescala/Analysis.scala
src/purescala/TypeTrees.scala
+34
-1
34 additions, 1 deletion
src/purescala/TypeTrees.scala
with
35 additions
and
11 deletions
src/purescala/Analysis.scala
+
1
−
10
View file @
1ec8524a
...
@@ -93,19 +93,10 @@ class Analysis(val program: Program) {
...
@@ -93,19 +93,10 @@ class Analysis(val program: Program) {
}
}
}
}
def
flatten
(
expr
:
Expr
)
:
(
Expr
,
List
[(
Variable
,
Expr
)])
=
{
// Recursively flattens the expression. The head in the end
// should be the top-level original expression.
def
fl
(
expr
:
Expr
,
lets
:
List
[(
Variable
,
Expr
)])
:
List
[(
Variable
,
Expr
)]
=
expr
match
{
case
_
=>
throw
new
Exception
(
"ah ha !"
)
}
(
expr
,
Nil
)
}
def
replaceInExpr
(
substs
:
Map
[
Expr
,
Expr
],
expr
:
Expr
)
:
Expr
=
{
def
replaceInExpr
(
substs
:
Map
[
Expr
,
Expr
],
expr
:
Expr
)
:
Expr
=
{
def
rec
(
ex
:
Expr
)
:
Expr
=
ex
match
{
def
rec
(
ex
:
Expr
)
:
Expr
=
ex
match
{
case
_
if
(
substs
.
get
(
ex
).
isDefined
)
=>
substs
(
ex
)
case
_
if
(
substs
.
get
(
ex
).
isDefined
)
=>
substs
(
ex
)
case
Let
(
i
,
e
,
b
)
=>
Let
(
i
,
rec
(
e
),
rec
(
b
))
case
FunctionInvocation
(
fd
,
args
)
=>
FunctionInvocation
(
fd
,
args
.
map
(
rec
(
_
)))
case
FunctionInvocation
(
fd
,
args
)
=>
FunctionInvocation
(
fd
,
args
.
map
(
rec
(
_
)))
case
IfExpr
(
t1
,
t2
,
t3
)
=>
IfExpr
(
rec
(
t1
),
rec
(
t2
),
rec
(
t3
))
case
IfExpr
(
t1
,
t2
,
t3
)
=>
IfExpr
(
rec
(
t1
),
rec
(
t2
),
rec
(
t3
))
case
MatchExpr
(
_
,
_
)
=>
ex
case
MatchExpr
(
_
,
_
)
=>
ex
...
...
This diff is collapsed.
Click to expand it.
src/purescala/TypeTrees.scala
+
34
−
1
View file @
1ec8524a
...
@@ -69,6 +69,40 @@ object TypeTrees {
...
@@ -69,6 +69,40 @@ object TypeTrees {
case
_
=>
scala
.
Predef
.
error
(
"Asking for lub of unrelated types: "
+
t1
+
" and "
+
t2
)
case
_
=>
scala
.
Predef
.
error
(
"Asking for lub of unrelated types: "
+
t1
+
" and "
+
t2
)
}
}
// returns the number of distinct values that inhabit a type
sealed
abstract
class
TypeSize
case
class
FiniteSize
(
size
:
Int
)
extends
TypeSize
case
object
InfiniteSize
extends
TypeSize
def
domainSize
(
typeTree
:
TypeTree
)
:
TypeSize
=
typeTree
match
{
case
NoType
=>
FiniteSize
(
0
)
case
AnyType
=>
InfiniteSize
case
BooleanType
=>
FiniteSize
(
2
)
case
Int32Type
=>
InfiniteSize
case
ListType
(
_
)
=>
InfiniteSize
case
TupleType
(
bases
)
=>
{
val
baseSizes
=
bases
.
map
(
domainSize
(
_
))
baseSizes
.
find
(
_
==
InfiniteSize
)
match
{
case
Some
(
_
)
=>
InfiniteSize
case
None
=>
FiniteSize
(
baseSizes
.
map
(
_
.
asInstanceOf
[
FiniteSize
].
size
).
reduceLeft
(
_
*
_
))
}
}
case
SetType
(
base
)
=>
domainSize
(
base
)
match
{
case
InfiniteSize
=>
InfiniteSize
case
FiniteSize
(
n
)
=>
FiniteSize
(
scala
.
math
.
pow
(
2
,
n
).
toInt
)
}
case
MapType
(
from
,
to
)
=>
(
domainSize
(
from
),
domainSize
(
to
))
match
{
case
(
InfiniteSize
,
_
)
=>
InfiniteSize
case
(
_
,
InfiniteSize
)
=>
InfiniteSize
case
(
FiniteSize
(
n
),
FiniteSize
(
m
))
=>
FiniteSize
(
scala
.
math
.
pow
(
m
+
1
,
n
).
toInt
)
}
case
OptionType
(
base
)
=>
domainSize
(
base
)
match
{
case
InfiniteSize
=>
InfiniteSize
case
FiniteSize
(
n
)
=>
FiniteSize
(
n
+
1
)
}
case
c
:
ClassType
=>
InfiniteSize
}
case
object
NoType
extends
TypeTree
case
object
NoType
extends
TypeTree
case
object
AnyType
extends
TypeTree
case
object
AnyType
extends
TypeTree
...
@@ -77,7 +111,6 @@ object TypeTrees {
...
@@ -77,7 +111,6 @@ object TypeTrees {
case
class
ListType
(
base
:
TypeTree
)
extends
TypeTree
case
class
ListType
(
base
:
TypeTree
)
extends
TypeTree
case
class
TupleType
(
bases
:
Seq
[
TypeTree
])
extends
TypeTree
{
lazy
val
dimension
:
Int
=
bases
.
length
}
case
class
TupleType
(
bases
:
Seq
[
TypeTree
])
extends
TypeTree
{
lazy
val
dimension
:
Int
=
bases
.
length
}
case
class
FunctionType
(
arg
:
TypeTree
,
res
:
TypeTree
)
extends
TypeTree
case
class
SetType
(
base
:
TypeTree
)
extends
TypeTree
case
class
SetType
(
base
:
TypeTree
)
extends
TypeTree
// case class MultisetType(base: TypeTree) extends TypeTree
// case class MultisetType(base: TypeTree) extends TypeTree
case
class
MapType
(
from
:
TypeTree
,
to
:
TypeTree
)
extends
TypeTree
case
class
MapType
(
from
:
TypeTree
,
to
:
TypeTree
)
extends
TypeTree
...
...
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