Skip to content

Commit b369820

Browse files
authored
Merge pull request #32 from mlabs-haskell/compiler/integrate-CLI-KindChecker
Kind Checker: CLI Integration
2 parents d7291b3 + a8e5d72 commit b369820

File tree

20 files changed

+751
-336
lines changed

20 files changed

+751
-336
lines changed

lambda-buffers-compiler/app/LambdaBuffers/Compiler/Cli/Compile.hs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ import Data.ProtoLens qualified as Pb
77
import Data.ProtoLens.TextFormat qualified as PbText
88
import Data.Text.Lazy qualified as Text
99
import Data.Text.Lazy.IO qualified as Text
10-
import LambdaBuffers.Compiler.ProtoCompat (FromProtoErr (NamingError, ProtoError), IsMessage (fromProto, toProto))
10+
import LambdaBuffers.Compiler.KindCheck (check)
11+
import LambdaBuffers.Compiler.ProtoCompat (
12+
FromProtoErr (NamingError, ProtoError),
13+
IsMessage (fromProto, toProto),
14+
)
1115
import LambdaBuffers.Compiler.ProtoCompat.Types qualified as ProtoCompat
12-
import Proto.Compiler (CompilerInput)
16+
import Proto.Compiler as ProtoLib (CompilerInput, CompilerOutput)
1317
import System.FilePath.Lens (extension)
1418

1519
data CompileOpts = CompileOpts
@@ -20,6 +24,8 @@ data CompileOpts = CompileOpts
2024

2125
makeLenses ''CompileOpts
2226

27+
-- NOTE(cstml) - let's use Katip instead of print.
28+
2329
-- | Compile LambdaBuffers modules
2430
compile :: CompileOpts -> IO ()
2531
compile opts = do
@@ -30,8 +36,8 @@ compile opts = do
3036
ProtoError pe -> print $ "Encountered a proto error " <> show pe
3137
Right compIn' -> do
3238
print @String "Successfully processed the CompilerInput"
33-
writeCompilerOutput (opts ^. output) (toProto compIn')
34-
39+
let result = check compIn'
40+
writeCompilerOutput (opts ^. output) (toProto result)
3541
return ()
3642

3743
readCompilerInput :: FilePath -> IO CompilerInput
@@ -46,11 +52,10 @@ readCompilerInput fp = do
4652
return $ PbText.readMessageOrDie content
4753
_ -> error $ "Unknown CompilerInput format " <> ext
4854

49-
-- FIXME(bladyjoker): Do this properly when you figure out what the CompilerOutput is.
50-
writeCompilerOutput :: FilePath -> CompilerInput -> IO ()
51-
writeCompilerOutput fp co = do
55+
writeCompilerOutput :: FilePath -> ProtoLib.CompilerOutput -> IO ()
56+
writeCompilerOutput fp cr = do
5257
let ext = fp ^. extension
5358
case ext of
54-
".pb" -> BS.writeFile fp (Pb.encodeMessage co)
55-
".textproto" -> Text.writeFile fp (Text.pack . show $ PbText.pprintMessage co)
59+
".pb" -> BS.writeFile fp (Pb.encodeMessage cr)
60+
".textproto" -> Text.writeFile fp (Text.pack . show $ PbText.pprintMessage cr)
5661
_ -> error $ "Unknown CompilerOutput format " <> ext

lambda-buffers-compiler/app/Main.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ import Options.Applicative (
2323
subparser,
2424
)
2525

26-
newtype Command
27-
= Compile CompileOpts
26+
newtype Command = Compile CompileOpts
2827

2928
inputPathP :: Parser FilePath
3029
inputPathP =

lambda-buffers-compiler/lambda-buffers-compiler.cabal

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ common common-language
3838
DeriveTraversable
3939
DerivingStrategies
4040
DoAndIfThenElse
41+
DuplicateRecordFields
4142
EmptyCase
4243
EmptyDataDecls
4344
EmptyDataDeriving
@@ -59,6 +60,7 @@ common common-language
5960
NamedFieldPuns
6061
NamedWildCards
6162
NumericUnderscores
63+
OverloadedLabels
6264
OverloadedStrings
6365
PartialTypeSignatures
6466
PatternGuards
@@ -103,7 +105,9 @@ library
103105
exposed-modules:
104106
LambdaBuffers.Compiler.KindCheck
105107
LambdaBuffers.Compiler.KindCheck.Context
108+
LambdaBuffers.Compiler.KindCheck.Derivation
106109
LambdaBuffers.Compiler.KindCheck.Inference
110+
LambdaBuffers.Compiler.KindCheck.Judgement
107111
LambdaBuffers.Compiler.KindCheck.Kind
108112
LambdaBuffers.Compiler.KindCheck.Type
109113
LambdaBuffers.Compiler.KindCheck.Variable
@@ -114,6 +118,7 @@ library
114118

115119
hs-source-dirs: src
116120

121+
-- note(cstml): should we name this something shorter? lb-cli?
117122
executable lambda-buffers-compiler-cli
118123
import: common-language
119124
import: common-imports
@@ -145,4 +150,10 @@ test-suite tests
145150

146151
other-modules:
147152
Test.KindCheck
153+
Test.Samples
154+
Test.Samples.Proto.CompilerInput
155+
Test.Samples.Proto.Helpers
156+
Test.Samples.Proto.Module
157+
Test.Samples.Proto.SourceInfo
158+
Test.Samples.Proto.TyDef
148159
Test.TypeClassCheck

0 commit comments

Comments
 (0)