summaryrefslogtreecommitdiff
path: root/devel/compiler/Match.hs
blob: a9ac839efecdd0336970cf0a7ef2eb4e1fbeb911 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module Match where

import AbsSrc
import AbsTgt

import Env
import STM

match :: [Case] -> Exp -> STM Env Exp
match cs v = checks $ map (tryMatch v) cs

---- return substitution  
tryMatch :: Exp -> Case -> STM Env Exp
tryMatch e (Cas p v) = if fit (e, p) then return v else raise "no fit" where
  fit (exp,patt) = case (exp,patt) of
    (ECst c es, PCon d ps) ->
      c == d  &&
      length es == length ps &&
      all fit (zip es ps)
    (_,PVar _) -> True ---- not is exp contains variables