summaryrefslogtreecommitdiff
path: root/devel/compiler/Match.hs
diff options
context:
space:
mode:
authoraarne <aarne@cs.chalmers.se>2007-03-27 20:54:49 +0000
committeraarne <aarne@cs.chalmers.se>2007-03-27 20:54:49 +0000
commitfd518ed2a3fe50238e0e9e7947e33cc9d5de9bce (patch)
tree384d4e0a74cd0019dbf20394f2eeb9b83b24b1cc /devel/compiler/Match.hs
parent7c30d211c3eda504668c0eab51e99d6e52db2127 (diff)
primitive pattern matching
Diffstat (limited to 'devel/compiler/Match.hs')
-rw-r--r--devel/compiler/Match.hs21
1 files changed, 21 insertions, 0 deletions
diff --git a/devel/compiler/Match.hs b/devel/compiler/Match.hs
new file mode 100644
index 000000000..a9ac839ef
--- /dev/null
+++ b/devel/compiler/Match.hs
@@ -0,0 +1,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
+