summaryrefslogtreecommitdiff
path: root/Compiler.hs
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2019-11-20 22:51:12 +0100
committerTom Smeding <tom.smeding@gmail.com>2019-11-20 23:06:45 +0100
commitbee62a7f1ac399fa1641711ecbbca46b66adcfc4 (patch)
treee5ae692e7d921bfc914b872522d30a7d12d6f2ac /Compiler.hs
parentd541e0f84ae8f82f70e2393207d359975841facf (diff)
Move compiler macro's to separate module (from Compiler)
Diffstat (limited to 'Compiler.hs')
-rw-r--r--Compiler.hs47
1 files changed, 1 insertions, 46 deletions
diff --git a/Compiler.hs b/Compiler.hs
index 37f3d0d..f973afa 100644
--- a/Compiler.hs
+++ b/Compiler.hs
@@ -24,50 +24,6 @@ data TaggedValue
| TVEllipsis
deriving Show
-preprocess :: Value -> Value
-preprocess (VList [VName "define", VName name, VList args, body])
- | Just names <- mapM fromVName args = preprocess (VList [VName "define", VName name, VLambda names body])
- | otherwise = error "Invalid 'define' shorthand syntax: Invalid argument list"
-preprocess (VList [VName "define", VName name, value]) = VDefine name (preprocess value)
-preprocess (VList (VName "define" : _)) = error "Invalid 'define' syntax"
-
-preprocess (VList [VName "lambda", VList args, body])
- | Just names <- mapM fromVName args = preprocess (VLambda names body)
- | otherwise = error "Invalid 'lambda' syntax: Invalid argument list"
-preprocess (VList (VName "lambda" : _)) = error "Invalid 'lambda' syntax"
-
-preprocess (VList [VName "lambdarec", VName recname, VList args, body])
- | Just names <- mapM fromVName args = preprocess (VLambdaRec recname names body)
- | otherwise = error "Invalid 'lambdarec' syntax: Invalid argument list"
-preprocess (VList (VName "lambdarec" : _)) = error "Invalid 'lambdarec' syntax"
-
--- preprocess (VList [VName "let", VList args, body]) =
--- case sequence [case p of { [n, v] -> Just (n, v); _ -> Nothing } | VList p <- args] of
--- Just pairs ->
--- preprocess (VList (VList [VName "lambda", VList (map fst pairs), body] : map snd pairs))
--- Nothing ->
--- error "Invalid 'let' syntax: Invalid variable list (not all pairs)"
-preprocess (VList [VName "let", VList args, body]) =
- case sequence [case p of { [VName n, v] -> Just (n, v); _ -> Nothing } | VList p <- args] of
- Just pairs ->
- preprocess (VLet pairs body)
- Nothing ->
- error "Invalid 'let' syntax: Invalid variable list (not all pairs)"
-preprocess (VList (VName "let" : _)) = error "Invalid 'let' syntax: Invalid argument list"
-
-preprocess (VList values) = VList (map preprocess values)
-
-preprocess (VDefine name body) = VDefine name (preprocess body)
-preprocess (VLambda args body) = VLambda args (preprocess body)
-preprocess (VLambdaRec recname args body) = VLambdaRec recname args (preprocess body)
-preprocess (VLet args body) = VLet [(name, preprocess value) | (name, value) <- args] (preprocess body)
-preprocess v@(VNum _) = v
-preprocess v@(VString _) = v
-preprocess v@(VName _) = v
-preprocess v@(VQuoted _) = v
-preprocess v@(VBuiltin _) = v
-preprocess v@VEllipsis = v
-
analyseValue :: Value -> TaggedValue
analyseValue = go (Map.empty, 0)
where
@@ -213,8 +169,7 @@ compileProgram (Program values) = runCM $ do
bstart <- newBlockSwitch
forM_ values $ \value -> do
bnext <- newBlock
- let value' = preprocess value
- tvalue = analyseValue value'
+ let tvalue = analyseValue value
ref <- genTValue tvalue bnext
switchBlock bnext
addIns (RNone, IDiscard ref)