diff options
author | Tom Smeding <tom@tomsmeding.com> | 2025-02-28 16:57:34 +0100 |
---|---|---|
committer | Tom Smeding <tom@tomsmeding.com> | 2025-02-28 16:59:40 +0100 |
commit | 25f175f90febf6fb148608ed20a266669450c5bc (patch) | |
tree | 3196c89933358c95b2c19a34d1df121196c1af07 | |
parent | 1083b6016c427d7eb519f9238384b1ebe5395061 (diff) |
Compile: some cleanup
-rw-r--r-- | src/Compile.hs | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/Compile.hs b/src/Compile.hs index 92eb6d5..48a03b5 100644 --- a/src/Compile.hs +++ b/src/Compile.hs @@ -1,9 +1,8 @@ -{-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE TypeApplications #-} -module Compile where +module Compile (compile) where import Control.Monad.Trans.State.Strict import Data.Bifunctor (first, second) @@ -68,16 +67,16 @@ data Stmt | SAsg String CExpr -- ^ variable name, right-hand side | SBlock [Stmt] | SIf CExpr [Stmt] [Stmt] - | SVerbatim String + | SVerbatim String -- ^ no implicit ';', just printed as-is deriving (Show) data CExpr - = CELit String - | CEStruct String [(String, CExpr)] - | CEProj CExpr String - | CECall String [CExpr] - | CEBinop CExpr String CExpr - | CEIf CExpr CExpr CExpr + = CELit String -- ^ inserted as-is, assumed no parentheses needed + | CEStruct String [(String, CExpr)] -- ^ struct construction literal: `(name){.field=expr}` + | CEProj CExpr String -- ^ field projection: expr.field + | CECall String [CExpr] -- ^ function(arg1, ..., argn) + | CEBinop CExpr String CExpr -- ^ expr + expr + | CEIf CExpr CExpr CExpr -- ^ expr ? expr : expr deriving (Show) printStructDecl :: StructDecl -> ShowS @@ -533,7 +532,7 @@ compile' env = \case STI64 -> return $ CELit $ "(int64_t)" ++ show x STF32 -> return $ CELit $ show x ++ "f" STF64 -> return $ CELit $ show x - STBool -> return $ CELit $ if x then "true" else "false" + STBool -> return $ CELit $ if x then "1" else "0" -- EIdx0 _ e -> error "TODO" -- EIdx0 ext (compile' e) |