"""Provides Python objects for builtin language keywords."""fromcollections.abcimportGeneratorfromtypingimportAny,Protocol,TypeVarfromguppylang_internals.errorimportGuppyComptimeErrorT=TypeVar("T")_MODIFIER_COMPTIME_ERROR=("The `{modifier}` modifier is not supported in comptime functions")class_Comptime:"""Dummy class to support `@comptime` annotations and `comptime(...)` expressions"""def__call__(self,v:T)->T:returnvdef__rmatmul__(self,other:Any)->Any:# This method is to make the Python interpreter happy with @comptime at runtimereturnother#: Function to tag compile-time evaluated Python expressions in a Guppy context.#:#: This function acts like the identity when execute in a Python context.comptime=_Comptime()#: Alias for `comptime` expressionspy=comptimeclass_Owned:"""Dummy class to support `@owned` annotations."""def__rmatmul__(self,other:Any)->Any:returnotherowned=_Owned()
[docs]classCopy(Protocol):"""Bound to mark generic type parameters as being implicitly copyable."""
[docs]classDrop(Protocol):"""Bound to mark generic type parameters as being implicitly droppable."""
[docs]defcontrol(*args:Any,**kwargs:Any)->Generator[None]:"""Dummy function to support `with control(...):` blocks in Guppy code."""raiseGuppyComptimeError(_MODIFIER_COMPTIME_ERROR.format(modifier="control"))
[docs]defdagger(*args:Any,**kwargs:Any)->Generator[None]:"""Dummy function to support `with dagger(...):` blocks in Guppy code."""raiseGuppyComptimeError(_MODIFIER_COMPTIME_ERROR.format(modifier="dagger"))
[docs]defpower(*args:Any,**kwargs:Any)->Generator[None]:"""Dummy function to support `with power(...):` blocks in Guppy code."""raiseGuppyComptimeError(_MODIFIER_COMPTIME_ERROR.format(modifier="power"))