From bee62a7f1ac399fa1641711ecbbca46b66adcfc4 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Wed, 20 Nov 2019 22:51:12 +0100 Subject: Move compiler macro's to separate module (from Compiler) --- Compiler.hs | 47 +---------------------------------------------- 1 file changed, 1 insertion(+), 46 deletions(-) (limited to 'Compiler.hs') 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) -- cgit v1.2.3-54-g00ecf