Skip to content

Commit

Permalink
Add conversion primops and PIR shims
Browse files Browse the repository at this point in the history
  • Loading branch information
kozross committed Sep 13, 2024
1 parent bf22f24 commit 8cfe7d8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Language/PureScript/Environment.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1059,5 +1059,6 @@ builtinCxt =
, PLC.I_mkNilData #@ tyUnit -:> tyBuiltinList tyBuiltinData
, PLC.I_mkNilPairData #@ tyUnit -:> tyBuiltinList (tyBuiltinPair tyBuiltinData tyBuiltinData)
-- TODO: the Bls12 crypto primfuns
-- NOTE: IntegerToByteString & ByteStringToInteger don't appear to be in the version of PlutusCore we have?
, PLC.I_integerToByteString #@ tyBoolean -:> tyInt -:> tyInt -:> tyByteString
, PLC.I_byteStringToInteger #@ tyBoolean -:> tyByteString -:> tyInt
]
18 changes: 18 additions & 0 deletions src/Language/Purus/Pipeline/CompileToPIR/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ builtinSubstitutions =
, (PLC.EqualsData, pirEqualsData)
, (PLC.IfThenElse, pirIfThenElse)
, (PLC.NullList, pirNullList)
, (PLC.IntegerToByteString, pirI2BS)
, (PLC.ByteStringToInteger, pirBS2I)
]

tyInt, tyBool, tyByteString, tyData, tyString :: Ty
Expand Down Expand Up @@ -238,3 +240,19 @@ pirNullList =
freshLam' listAppliedTy $ \_ arg -> do
let nullListFun = PIR.Builtin () PLC.NullList
pirBoolToBoolean (pirTyInst tv nullListFun # arg)

-- Bool -> Int -> Int -> ByteString
pirI2BS :: PlutusContext PIRTerm
pirI2BS =
freshLam tyBool $ \_ b -> do
b' <- pirBooleanToBool b
let fun = PIR.Builtin () PLC.IntegerToByteString
pure $ fun # b'

-- Bool -> ByteString -> Int
pirBS2I :: PlutusContext PIRTerm
pirBS2I =
freshLam tyBool $ \_ b -> do
b' <- pirBooleanToBool b
let fun = PIR.Builtin () PLC.ByteStringToInteger
pure $ fun # b'

0 comments on commit 8cfe7d8

Please sign in to comment.