-- SPDX-FileCopyrightText: 2020 Tocqueville Group
--
-- SPDX-License-Identifier: LicenseRef-MIT-TQ

{-# OPTIONS_GHC -Wno-redundant-constraints #-}

-- | Printing lorentz contracts.
module Lorentz.Print
  ( printLorentzValue
  , printLorentzContract
  ) where

import Lorentz.Constraints
import Lorentz.Run
import Michelson.Printer (printTypedContract, printTypedValue)
import Michelson.Typed (toVal)

-- | Pretty-print a Haskell value as Michelson one.
printLorentzValue
  :: forall v.
    (NicePrintedValue v)
  => Bool -> v -> LText
printLorentzValue :: Bool -> v -> LText
printLorentzValue forceSingleLine :: Bool
forceSingleLine =
  ((KnownValue v,
  (SingI (ToT v), FailOnOperationFound (ContainsOp (ToT v))))
 :- PrintedValScope (ToT v))
-> (PrintedValScope (ToT v) => v -> LText) -> v -> LText
forall (c :: Constraint) e r. HasDict c e => e -> (c => r) -> r
withDict ((KnownValue v,
 (SingI (ToT v), FailOnOperationFound (ContainsOp (ToT v))))
:- PrintedValScope (ToT v)
forall a. NicePrintedValue a :- PrintedValScope (ToT a)
nicePrintedValueEvi @v) ((PrintedValScope (ToT v) => v -> LText) -> v -> LText)
-> (PrintedValScope (ToT v) => v -> LText) -> v -> LText
forall a b. (a -> b) -> a -> b
$
    Bool -> Value (ToT v) -> LText
forall (t :: T).
ProperPrintedValBetterErrors t =>
Bool -> Value t -> LText
printTypedValue Bool
forceSingleLine (Value (ToT v) -> LText) -> (v -> Value (ToT v)) -> v -> LText
forall b c a. (b -> c) -> (a -> b) -> a -> c
. v -> Value (ToT v)
forall a. IsoValue a => a -> Value (ToT a)
toVal

-- | Pretty-print a Lorentz contract into Michelson code.
printLorentzContract
  :: forall cp st.
     (NiceParameterFull cp, NiceStorage st)
  => Bool -> Contract cp st -> LText
printLorentzContract :: Bool -> Contract cp st -> LText
printLorentzContract forceSingleLine :: Bool
forceSingleLine =
  Bool -> Contract (ToT cp) (ToT st) -> LText
forall (p :: T) (s :: T). Bool -> Contract p s -> LText
printTypedContract Bool
forceSingleLine (Contract (ToT cp) (ToT st) -> LText)
-> (Contract cp st -> Contract (ToT cp) (ToT st))
-> Contract cp st
-> LText
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Contract cp st -> Contract (ToT cp) (ToT st)
forall cp st.
(NiceParameterFull cp, NiceStorage st) =>
Contract cp st -> Contract (ToT cp) (ToT st)
compileLorentzContract