~ubuntu-branches/ubuntu/raring/agda/raring-proposed

« back to all changes in this revision

Viewing changes to src/full/Agda/Compiler/MAlonzo/Primitives.hs

  • Committer: Bazaar Package Importer
  • Author(s): Iain Lane
  • Date: 2010-01-05 23:43:20 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100105234320-6ksc0sdsfhtweknu
Tags: 2.2.6-1
* New upstream release 2.2.6, for headlines please see:
  http://wiki.portal.chalmers.se/agda/pmwiki.php?n=Main.Version-2-2-6
* debian/control
  + Bump standards-version to 3.8.3, no changes
  + Fix Vcs-Git to point to correct URL
  + Update build-depends for new upstream release
  + Undo arch/indep split per current pkg-haskell practice
  + Add Homepage field
* debian/copyright: Fix encoding to UTF-8 (thanks Lintian) 
* debian/README.source: Remove, no repacking so not necessary any more 
* debian/50agda.el:
  + Only load file if it exists, prevents a non-intrusive emacs warning
    where 50agda.el is left on system when package is removed. 
    (Closes: #559197). 
  + Do not load file on XEmacs — agda-mode is not compatible with XEmacs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
module Agda.Compiler.MAlonzo.Primitives where
2
2
 
 
3
import Control.Monad.Reader
3
4
import Control.Monad.State
4
5
import Data.Char
5
6
import Data.List as L
6
7
import Data.Map as M
7
8
import Language.Haskell.Syntax
8
9
 
 
10
import {-# SOURCE #-} Agda.Compiler.MAlonzo.Compiler (term)
9
11
import Agda.Compiler.MAlonzo.Misc
10
12
import Agda.Compiler.MAlonzo.Pretty
 
13
import Agda.Syntax.Common
11
14
import Agda.Syntax.Internal
12
15
import Agda.TypeChecking.Monad
13
16
import Agda.TypeChecking.Monad.Builtin
14
17
import Agda.TypeChecking.Reduce
 
18
import Agda.TypeChecking.Substitute
15
19
import Agda.TypeChecking.Pretty
16
20
import Agda.Utils.Monad
17
21
 
60
64
    forList toH toA = decls ["NIL", "CONS"]
61
65
       toH (concat
62
66
           ["let { f <<0>>        = [];"
63
 
           ,"      f (<<1>> x xs) = x : f (unsafeCoerce xs)"
 
67
           ,"      f (<<1>> x xs) = x : f (Unsafe.Coerce.unsafeCoerce xs)"
64
68
           ,"} in f"])
65
69
       toA (concat
66
70
           ["let { f []     = <<0>>;"
67
 
           ,"      f (c:cs) = <<1>> c (unsafeCoerce (f cs));"
 
71
           ,"      f (c:cs) = <<1>> c (Unsafe.Coerce.unsafeCoerce (f cs));"
68
72
           ,"} in f"])
69
73
    natToFrom hty to from = let
70
74
        totxt   = repl ["<<0>>", "<<1>>", hty] (concat
71
75
                       ["let { f <<0>>     = 0 :: <<2>>;"
72
 
                       ,"      f (<<1>> x) = 1 + f (unsafeCoerce x);"
 
76
                       ,"      f (<<1>> x) = 1 + f (Unsafe.Coerce.unsafeCoerce x);"
73
77
                       ,"} in f"])
74
78
        fromtxt = repl ["<<0>>", "<<1>>", hty] (concat
75
79
                       ["let { f x | x <= (0 :: <<2>>) = <<0>>"
76
 
                       ,"     | True = <<1>> (unsafeCoerce (f (x - 1)))"
 
80
                       ,"     | True = <<1>> (Unsafe.Coerce.unsafeCoerce (f (x - 1)))"
77
81
                       ,"} in f"])
78
82
      in decls ["ZERO", "SUC"] to totxt from fromtxt
79
83
    decls cs n1 b1 n2 b2 =
106
110
 
107
111
-- Definition bodies for primitive functions
108
112
primBody :: String -> TCM HsExp
109
 
primBody s = (hsVarUQ . HsIdent <$>) $ maybe unimplemented id $ L.lookup s $
 
113
primBody s = maybe unimplemented (either (hsVarUQ . HsIdent) id <$>) $
 
114
             L.lookup s $
110
115
  [
111
116
  -- Integer functions
112
117
    "primIntegerPlus"    |-> binAsis "(+)" "Integer"
172
177
  , "primStringAppend"   |-> binAsis "(++)" "String"
173
178
  , "primStringEquality" |-> rel "(==)" "String"
174
179
  , "primShowString"     |-> return "(show :: String -> String)"
 
180
 
 
181
  -- Trust me
 
182
  , ("primTrustMe"       , Right <$> do
 
183
       refl <- primRefl
 
184
       flip runReaderT 0 $
 
185
         term $ lam "A" (lam "x" (lam "y" (refl `apply` [var 2, var 1]))))
175
186
  ]
176
187
  where
177
 
  (|->) = (,)
 
188
  x |-> s = (x, Left <$> s)
178
189
  bin blt op ty from to = do
179
190
    from' <- bltQual' blt from
180
191
    to'   <- bltQual' blt to
192
203
  pred p = do toHB <- bltQual' "BOOL" mazHBoolToBool
193
204
              return $ repl [p, toHB] $ "(\\ x -> <<1>> (<<0>> x))"
194
205
  opty t = t ++ "->" ++ t ++ "->" ++ t
195
 
  unimplemented = return$ prettyPrint$ rtmError$ "not yet implemented: "++ s
 
206
  unimplemented = typeError $ NotImplemented s
 
207
 
 
208
  lam x t = Lam Hidden (Abs x t)
 
209
  var x   = Arg Hidden (Var x [])
196
210
 
197
211
----------------------
198
212