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

« back to all changes in this revision

Viewing changes to src/full/Agda/TypeChecking/Monad/Signature.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:
9
9
import qualified Data.Map as Map
10
10
import Data.List
11
11
import Data.Function
12
 
import qualified System.IO.UTF8 as UTF8
 
12
import qualified Agda.Utils.IO.Locale as LocIO
13
13
 
14
14
import Agda.Syntax.Abstract.Name
15
15
import Agda.Syntax.Common
204
204
                  oldDef { conPars = np - size ts, conData = copyName d }
205
205
                Datatype{ dataPars = np, dataCons = cs } ->
206
206
                  oldDef { dataPars = np - size ts, dataClause = Just cl, dataCons = map copyName cs }
207
 
                Record{ recPars = np, recTel = tel } ->
208
 
                  oldDef { recPars = np - size ts, recClause = Just cl, recTel = apply tel ts }
 
207
                Record{ recPars = np, recConType = t, recTel = tel } ->
 
208
                  oldDef { recPars = np - size ts, recClause = Just cl
 
209
                         , recConType = apply t ts, recTel = apply tel ts
 
210
                         }
209
211
                _ ->
210
212
                  Function { funClauses        = [cl]
211
213
                           , funDelayed        = NotDelayed
266
268
    Constructor{ conInd = i }     -> return i
267
269
    _                             -> __IMPOSSIBLE__
268
270
 
 
271
-- | Does the given constructor come from a single-constructor type?
 
272
--
 
273
-- Precondition: The name has to refer to a constructor.
 
274
singleConstructorType :: QName -> TCM Bool
 
275
singleConstructorType q = do
 
276
  d <- theDef <$> getConstInfo q
 
277
  case d of
 
278
    Record {}                   -> return True
 
279
    Constructor { conData = d } -> do
 
280
      di <- theDef <$> getConstInfo d
 
281
      return $ case di of
 
282
        Record {}                  -> True
 
283
        Datatype { dataCons = cs } -> length cs == 1
 
284
        _                          -> __IMPOSSIBLE__
 
285
    _ -> __IMPOSSIBLE__
 
286
 
269
287
-- | Lookup the definition of a name. The result is a closed thing, all free
270
288
--   variables have been abstracted over.
271
289
getConstInfo :: MonadTCM tcm => QName -> tcm Definition
272
 
getConstInfo q = liftTCM $ do
273
 
  ab    <- treatAbstractly q
274
 
  defs  <- sigDefinitions <$> getSignature
275
 
  idefs <- sigDefinitions <$> getImportedSignature
276
 
  let smash = (++) `on` maybe [] (:[])
277
 
  case smash (Map.lookup q defs) (Map.lookup q idefs) of
278
 
      []  -> fail $ show (getRange q) ++ ": no such name " ++ show q
 
290
getConstInfo q = liftTCM $ join $ pureTCM $ \st env ->
 
291
  let defs  = sigDefinitions $ stSignature st
 
292
      idefs = sigDefinitions $ stImports st
 
293
      ab    = treatAbstractly' q env
 
294
      smash = (++) `on` maybe [] (:[])
 
295
  in case smash (Map.lookup q defs) (Map.lookup q idefs) of
 
296
      []  -> fail $ "Unbound name: " ++ show q
279
297
      [d] -> mkAbs ab d
280
 
      ds  -> fail $ show (getRange q) ++ ": ambiguous name " ++ show q
 
298
      ds  -> fail $ "Ambiguous name: " ++ show q
281
299
  where
282
300
    mkAbs True d =
283
301
      case makeAbstract d of
346
364
--   number of parameters if we're currently inside the section and 0 otherwise.
347
365
getSecFreeVars :: MonadTCM tcm => ModuleName -> tcm Nat
348
366
getSecFreeVars m = do
349
 
  sig <- sigSections <$> getSignature
 
367
  sig  <- sigSections <$> getSignature
 
368
  isig <- sigSections <$> getImportedSignature
350
369
  top <- currentModule
351
370
  case top `isSubModuleOf` m || top == m of
352
 
    True  -> return $ maybe 0 secFreeVars $ Map.lookup m sig
 
371
    True  -> return $ maybe 0 secFreeVars $ Map.lookup m (Map.union sig isig)
353
372
    False -> return 0
354
373
 
355
374
-- | Compute the number of free variables of a module. This is the sum of
376
395
  verboseS "tc.sig.inst" 30 $ do
377
396
    ctx <- getContext
378
397
    m   <- currentModule
379
 
    liftIO $ UTF8.putStrLn $ "instDef in " ++ show m ++ ": " ++ show (defName d) ++ " " ++
 
398
    liftIO $ LocIO.putStrLn $ "instDef in " ++ show m ++ ": " ++ show (defName d) ++ " " ++
380
399
                        unwords (map show . take (size vs) . reverse . map (fst . unArg) $ ctx)
381
400
  return $ d `apply` vs
382
401