mirror of
https://github.com/digital-asset/daml.git
synced 2024-09-20 01:07:18 +03:00
interfaces: add an experimental toTypeRep
builtin. (#11378)
This adds an experimental `toTypeRep: forall t. t -> TypeRep` builtin. It will only work on interface payloads and crash horribly otherwise. CHANGELOG_BEGIN CHANGELOG_END
This commit is contained in:
parent
5654d5cb48
commit
f89ecc6b95
@ -5,6 +5,7 @@ module DA.Experimental.Interface(
|
||||
interfaceCreate,
|
||||
interfaceSignatory,
|
||||
interfaceObserver,
|
||||
toTypeRep,
|
||||
) where
|
||||
|
||||
import GHC.Types (primitive)
|
||||
@ -17,3 +18,6 @@ interfaceSignatory payload = primitive @"$RESOLVE_VIRTUAL_SIGNATORY" payload pay
|
||||
|
||||
interfaceObserver: t -> [Party]
|
||||
interfaceObserver payload = primitive @"$RESOLVE_VIRTUAL_OBSERVER" payload payload
|
||||
|
||||
toTypeRep: t -> TypeRep
|
||||
toTypeRep arg = primitive @"$TO_TYPE_REP" arg
|
||||
|
@ -8,6 +8,7 @@
|
||||
module InterfaceExperimental where
|
||||
|
||||
import DA.Assert ((===))
|
||||
import DA.Action (unless)
|
||||
import DA.Experimental.Interface
|
||||
import GHC.Types (primitive)
|
||||
|
||||
@ -62,13 +63,22 @@ template Asset
|
||||
do
|
||||
pure ()
|
||||
|
||||
template NotAsset
|
||||
with
|
||||
p : Party
|
||||
where
|
||||
signatory p
|
||||
|
||||
main = scenario do
|
||||
alice <- getParty "Alice"
|
||||
bob <- getParty "Bob"
|
||||
let asset = Asset alice bob 15
|
||||
let notAsset = NotAsset alice
|
||||
let token = toToken asset
|
||||
submit alice do
|
||||
interfaceCreate token
|
||||
interfaceSignatory token === [alice]
|
||||
interfaceObserver token === [bob, alice]
|
||||
unless (toTypeRep token == toTypeRep asset) $ abort "TypeReps are not equal"
|
||||
unless (toTypeRep token /= toTypeRep notAsset) $ abort "TypeReps are equal"
|
||||
pure ()
|
||||
|
@ -1667,9 +1667,17 @@ private[lf] object SBuiltin {
|
||||
machine.returnValue = SInt64(42L)
|
||||
}
|
||||
|
||||
private object SBExperimentalToTypeRep extends SBuiltinPure(1) {
|
||||
override private[speedy] def executePure(args: util.ArrayList[SValue]): STypeRep = {
|
||||
val id = getSRecord(args, 0).id
|
||||
STypeRep(Ast.TTyCon(id))
|
||||
}
|
||||
}
|
||||
|
||||
private val mapping: Map[String, SExpr] =
|
||||
List(
|
||||
"ANSWER" -> SBExperimentalAnswer,
|
||||
"TO_TYPE_REP" -> SBExperimentalToTypeRep,
|
||||
"RESOLVE_VIRTUAL_CREATE" -> new SBResolveVirtual(CreateDefRef),
|
||||
"RESOLVE_VIRTUAL_SIGNATORY" -> new SBResolveVirtual(SignatoriesDefRef),
|
||||
"RESOLVE_VIRTUAL_OBSERVER" -> new SBResolveVirtual(ObserversDefRef),
|
||||
|
Loading…
Reference in New Issue
Block a user