@@ -15,10 +15,10 @@ import LambdaBuffers.ProtoCompat qualified as PC
15
15
import Prettyprinter (Doc , Pretty (pretty ), align , backslash , dquotes , group , hardline , hsep , line , parens , vsep , (<+>) )
16
16
import Proto.Codegen_Fields qualified as P
17
17
18
- throwInternalError :: MonadPrint m => String -> m a
19
- throwInternalError msg = throwError $ defMessage & P. msg .~ " [LambdaBuffers.Codegen.Plutarch] " <> Text. pack msg
18
+ type PlutarchLamValMonad m = LV. MonadPrint m HsSyntax. QValName ()
20
19
21
- type MonadPrint m = LV. MonadPrint m HsSyntax. QValName
20
+ throwInternalError :: PlutarchLamValMonad m => String -> m a
21
+ throwInternalError msg = throwError $ defMessage & P. msg .~ " [LambdaBuffers.Codegen.Plutarch] " <> Text. pack msg
22
22
23
23
withInfo :: PC. InfoLessC b => PC. InfoLess b -> b
24
24
withInfo x = PC. withInfoLess x id
@@ -66,7 +66,7 @@ translates to Plutarch
66
66
plam (\x -> <expression over x>)
67
67
```
68
68
-}
69
- printLamE :: MonadPrint m => (LV. ValueE -> LV. ValueE ) -> m (Doc ann )
69
+ printLamE :: PlutarchLamValMonad m => (LV. ValueE -> LV. ValueE ) -> m (Doc ann )
70
70
printLamE lamVal = do
71
71
arg <- LV. freshArg
72
72
bodyDoc <- printValueE (lamVal arg)
@@ -86,7 +86,7 @@ translates to Plutarch
86
86
(#) (funVal) (argVal)
87
87
```
88
88
-}
89
- printAppE :: MonadPrint m => LV. ValueE -> LV. ValueE -> m (Doc ann )
89
+ printAppE :: PlutarchLamValMonad m => LV. ValueE -> LV. ValueE -> m (Doc ann )
90
90
printAppE funVal argVal = do
91
91
funDoc <- printValueE funVal
92
92
argDoc <- printValueE argVal
@@ -111,7 +111,7 @@ pcon (Foo'Bar (x) (y))
111
111
112
112
TODO(bladyjoker): Add import for the `Foo'Bar` constructor value reference.
113
113
-}
114
- printCtorE :: MonadPrint m => LV. QCtor -> [LV. ValueE ] -> m (Doc ann )
114
+ printCtorE :: PlutarchLamValMonad m => LV. QCtor -> [LV. ValueE ] -> m (Doc ann )
115
115
printCtorE _qctor@ ((_, tyN), (ctorN, _)) prodVals = do
116
116
prodDocs <- for prodVals (fmap parens . printValueE)
117
117
let ctorNDoc = HsSyntax. printCtorName (withInfo tyN) (withInfo ctorN)
@@ -147,7 +147,7 @@ pmatch foo (\x -> case x of
147
147
)
148
148
```
149
149
-}
150
- printCaseE :: MonadPrint m => LV. QSum -> LV. ValueE -> ((LV. Ctor , [LV. ValueE ]) -> LV. ValueE ) -> m (Doc ann )
150
+ printCaseE :: PlutarchLamValMonad m => LV. QSum -> LV. ValueE -> ((LV. Ctor , [LV. ValueE ]) -> LV. ValueE ) -> m (Doc ann )
151
151
printCaseE _qsum@ (qtyN, sumTy) caseVal ctorCont = do
152
152
caseValDoc <- printValueE caseVal
153
153
ctorCaseDocs <-
@@ -163,7 +163,7 @@ printCaseE _qsum@(qtyN, sumTy) caseVal ctorCont = do
163
163
let casesDoc = " ca" <> align (" se" <+> pmatchContArgDoc <+> " of" <> line <> ctorCaseDocs)
164
164
return $ pmatchDoc <+> caseValDoc <+> parens (backslash <> pmatchContArgDoc <+> " ->" <+> casesDoc)
165
165
166
- printCtorCase :: MonadPrint m => PC. QTyName -> ((LV. Ctor , [LV. ValueE ]) -> LV. ValueE ) -> LV. Ctor -> m (Doc ann )
166
+ printCtorCase :: PlutarchLamValMonad m => PC. QTyName -> ((LV. Ctor , [LV. ValueE ]) -> LV. ValueE ) -> LV. Ctor -> m (Doc ann )
167
167
printCtorCase (_, tyn) ctorCont ctor@ (ctorN, fields) = do
168
168
args <- for fields (const LV. freshArg)
169
169
argDocs <- for args printValueE
@@ -192,7 +192,7 @@ pcon (Foo (x) (y))
192
192
193
193
TODO(bladyjoker): Add Product constructor import.
194
194
-}
195
- printProductE :: MonadPrint m => LV. QProduct -> [LV. ValueE ] -> m (Doc ann )
195
+ printProductE :: PlutarchLamValMonad m => LV. QProduct -> [LV. ValueE ] -> m (Doc ann )
196
196
printProductE ((_, tyN), _) vals = do
197
197
fieldDocs <- for vals (fmap parens . printValueE)
198
198
let ctorDoc = HsSyntax. printMkCtor (withInfo tyN)
@@ -217,7 +217,7 @@ translates to Plutarch
217
217
pmatch foo (\(Foo x y) -> <expression on x and y>)
218
218
```
219
219
-}
220
- printLetE :: MonadPrint m => LV. QProduct -> LV. ValueE -> ([LV. ValueE ] -> LV. ValueE ) -> m (Doc ann )
220
+ printLetE :: PlutarchLamValMonad m => LV. QProduct -> LV. ValueE -> ([LV. ValueE ] -> LV. ValueE ) -> m (Doc ann )
221
221
printLetE ((_, tyN), fields) prodVal letCont = do
222
222
prodValDoc <- printValueE prodVal
223
223
args <- for fields (const LV. freshArg)
@@ -240,7 +240,7 @@ translates to Plutarch
240
240
pcon (PCons x (PCons y PNil))
241
241
```
242
242
-}
243
- printListE :: MonadPrint m => [LV. ValueE ] -> m (Doc ann )
243
+ printListE :: PlutarchLamValMonad m => [LV. ValueE ] -> m (Doc ann )
244
244
printListE [] = do
245
245
pconDoc <- HsSyntax. printHsQValName <$> LV. importValue pconRef
246
246
pnilDoc <- HsSyntax. printHsQValName <$> LV. importValue pnilRef
@@ -291,13 +291,13 @@ case xs of
291
291
h4:t4 -> d xs -- OTHER
292
292
```
293
293
-}
294
- printCaseListE :: MonadPrint m => LV. ValueE -> [(Int , [LV. ValueE ] -> LV. ValueE )] -> (LV. ValueE -> LV. ValueE ) -> m (Doc ann )
294
+ printCaseListE :: PlutarchLamValMonad m => LV. ValueE -> [(Int , [LV. ValueE ] -> LV. ValueE )] -> (LV. ValueE -> LV. ValueE ) -> m (Doc ann )
295
295
printCaseListE xs cases otherCase = do
296
296
let maxLength = maximum $ fst <$> cases
297
297
otherCaseDoc <- printValueE (otherCase xs)
298
298
printCaseListE' xs cases otherCaseDoc 0 maxLength []
299
299
300
- printCaseListE' :: MonadPrint m => LV. ValueE -> [(Int , [LV. ValueE ] -> LV. ValueE )] -> Doc ann -> Int -> Int -> [LV. ValueE ] -> m (Doc ann )
300
+ printCaseListE' :: PlutarchLamValMonad m => LV. ValueE -> [(Int , [LV. ValueE ] -> LV. ValueE )] -> Doc ann -> Int -> Int -> [LV. ValueE ] -> m (Doc ann )
301
301
printCaseListE' _xs _cases otherCaseDoc currentLength maxLength _args | currentLength > maxLength = return otherCaseDoc
302
302
printCaseListE' xs cases otherCaseDoc currentLength maxLength args = do
303
303
pnilRefDoc <- HsSyntax. printHsQValName <$> LV. importValue pnilRef
@@ -345,7 +345,7 @@ pconstant 1
345
345
pconstant (-1)
346
346
```
347
347
-}
348
- printIntE :: MonadPrint m => Int -> m (Doc ann )
348
+ printIntE :: PlutarchLamValMonad m => Int -> m (Doc ann )
349
349
printIntE i = do
350
350
pconstantRefDoc <- HsSyntax. printHsQValName <$> LV. importValue pconstantRef
351
351
return $ pconstantRefDoc <+> if i < 0 then parens (pretty i) else pretty i
@@ -362,7 +362,7 @@ translates to Plutarch
362
362
pif ((#==) (x) (pconstant 0)) <A> (pif ((#==) (x) (pconstant 123)) <B> <C>)
363
363
```
364
364
-}
365
- printCaseIntE :: MonadPrint m => LV. ValueE -> [(LV. ValueE , LV. ValueE )] -> (LV. ValueE -> LV. ValueE ) -> m (Doc ann )
365
+ printCaseIntE :: PlutarchLamValMonad m => LV. ValueE -> [(LV. ValueE , LV. ValueE )] -> (LV. ValueE -> LV. ValueE ) -> m (Doc ann )
366
366
printCaseIntE caseIntVal [] otherCase = printValueE (otherCase caseIntVal) -- TODO(bladyjoker): Why is this a function and not just a ValueE?
367
367
printCaseIntE caseIntVal ((iVal, bodyVal) : cases) otherCase = do
368
368
pifRefDoc <- HsSyntax. printHsQValName <$> LV. importValue pifRef
@@ -385,7 +385,7 @@ translates to Plutarch
385
385
pconstant "Dražen Popović"
386
386
```
387
387
-}
388
- printTextE :: MonadPrint m => Text. Text -> m (Doc ann )
388
+ printTextE :: PlutarchLamValMonad m => Text. Text -> m (Doc ann )
389
389
printTextE t = do
390
390
pconstantRefDoc <- HsSyntax. printHsQValName <$> LV. importValue pconstantRef
391
391
return $ pconstantRefDoc <+> dquotes (pretty t)
@@ -402,7 +402,7 @@ translates to Plutarch
402
402
pif ((#==) (x) (pconstant "a")) <A> (pif ((#==) (x) (pconstant "b")) <B> <C>)
403
403
```
404
404
-}
405
- printCaseTextE :: MonadPrint m => LV. ValueE -> [(LV. ValueE , LV. ValueE )] -> (LV. ValueE -> LV. ValueE ) -> m (Doc ann )
405
+ printCaseTextE :: PlutarchLamValMonad m => LV. ValueE -> [(LV. ValueE , LV. ValueE )] -> (LV. ValueE -> LV. ValueE ) -> m (Doc ann )
406
406
printCaseTextE caseTxtVal [] otherCase = printValueE (otherCase caseTxtVal) -- TODO(bladyjoker): Why is this a function and not just a ValueE?
407
407
printCaseTextE caseTxtVal ((txtVal, bodyVal) : cases) otherCase = do
408
408
pifRefDoc <- HsSyntax. printHsQValName <$> LV. importValue pifRef
@@ -413,12 +413,12 @@ printCaseTextE caseTxtVal ((txtVal, bodyVal) : cases) otherCase = do
413
413
elseDoc <- printCaseIntE caseTxtVal cases otherCase
414
414
return $ pifRefDoc <+> parens (peqRefDoc <+> parens caseTxtValDoc <+> parens txtValDoc) <+> parens bodyValDoc <+> parens elseDoc
415
415
416
- printRefE :: MonadPrint m => LV. Ref -> m (Doc ann )
416
+ printRefE :: PlutarchLamValMonad m => LV. Ref -> m (Doc ann )
417
417
printRefE ref = do
418
418
qvn <- LV. resolveRef ref
419
419
HsSyntax. printHsQValName <$> LV. importValue qvn
420
420
421
- printValueE :: MonadPrint m => LV. ValueE -> m (Doc ann )
421
+ printValueE :: PlutarchLamValMonad m => LV. ValueE -> m (Doc ann )
422
422
printValueE (LV. VarE v) = return $ pretty v
423
423
printValueE (LV. RefE ref) = printRefE ref
424
424
printValueE (LV. LamE lamVal) = printLamE lamVal
0 commit comments