diff options
| author | hallgren <hallgren@chalmers.se> | 2012-12-14 14:00:21 +0000 |
|---|---|---|
| committer | hallgren <hallgren@chalmers.se> | 2012-12-14 14:00:21 +0000 |
| commit | d7e3c869c2ae56141260d4576b439097e8271383 (patch) | |
| tree | 0cb042a0289cb3eac2fa6e5cf87b06894d4f628b /src/compiler/GF/Compile/Compute/Value.hs | |
| parent | f7a5eb0df10f3cfef6e3d4c70c4714008c50bbe8 (diff) | |
More work on the new partial evaluator
The work done by the partial evaluator is now divied in two stages:
- A static "term traversal" stage that happens only once per term and uses
only statically known information. In particular, the values of lambda bound
variables are unknown during this stage. Some tables are transformed to
reduce the cost of pattern matching.
- A dynamic "function application" stage, where function bodies can be
evaluated repeatedly with different arguments, without the term traversal
overhead and without recomputing statically known information.
Also the treatment of predefined functions has been reworked to take advantage
of the staging and better handle partial applications.
Diffstat (limited to 'src/compiler/GF/Compile/Compute/Value.hs')
| -rw-r--r-- | src/compiler/GF/Compile/Compute/Value.hs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/compiler/GF/Compile/Compute/Value.hs b/src/compiler/GF/Compile/Compute/Value.hs index 07d79ca26..bbc751ee4 100644 --- a/src/compiler/GF/Compile/Compute/Value.hs +++ b/src/compiler/GF/Compile/Compute/Value.hs @@ -3,10 +3,11 @@ import GF.Grammar.Grammar(Label,Type,TInfo,MetaId,Patt,QIdent) import PGF.Data(BindType) import GF.Infra.Ident(Ident) import Text.Show.Functions +import Data.Ix(Ix) -- | Self-contained (not quite) representation of values data Value - = VApp QIdent [Value] -- from Q, always Predef.x, has a built-in value + = VApp Predefined [Value] -- from Q, always Predef.x, has a built-in value | VCApp QIdent [Value] -- from QC, constructors | VGen Int [Value] -- for lambda bound variables, possibly applied | VMeta MetaId Env [Value] @@ -22,7 +23,7 @@ data Value | VRecType [(Label,Value)] | VRec [(Label,Value)] | VV Type [Value] [Value] -- preserve type for conversion back to Term - | VT TInfo [(Patt,Bind Env)] + | VT Wild Value [(Patt,Bind Env)] | VC Value Value | VS Value Value | VP Value Label @@ -36,9 +37,19 @@ data Value | VError String deriving (Eq,Show) +type Wild = Bool type Binding = Bind Value data Bind a = Bind (a->Value) deriving Show instance Eq (Bind a) where x==y = False type Env = [(Ident,Value)] + +-- | Predefined functions +data Predefined = Drop | Take | Tk | Dp | EqStr | Occur | Occurs | ToUpper + | ToLower | IsUpper | Length | Plus | EqInt | LessInt + {- | Show | Read | ToStr | MapStr | EqVal -} + | Error + -- Canonical values below: + | PBool | PFalse | PTrue | Ints + deriving (Show,Eq,Ord,Ix,Bounded,Enum) |
