-
Notifications
You must be signed in to change notification settings - Fork 8
/
intrinsic_models.py
43 lines (34 loc) · 1.55 KB
/
intrinsic_models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from collections.abc import Sequence
import attrs
from puya.awst import wtypes
# used to map puyapy/_gen.pyi stubs to awst
# referenced by both scripts/generate_stubs.py and src/puya/awst_build/eb/intrinsics.py
@attrs.define
class ArgMapping:
arg_name: str
"""Name of puyapy argument to obtain value from"""
allowed_types: Sequence[wtypes.WType | type] = attrs.field(factory=tuple)
"""Valid types for this argument"""
@allowed_types.validator
def check(self, _attribute: object, value: Sequence[wtypes.WType | type]) -> None:
if wtypes.biguint_wtype in value and wtypes.uint64_wtype in value:
raise ValueError("overlap in integral types")
def is_allowed_constant(self, constant: object) -> bool:
if type(constant) in self.allowed_types:
return True
for allowed_type in self.allowed_types:
if isinstance(allowed_type, wtypes.WType) and allowed_type.is_valid_literal(constant):
return True
return False
@attrs.define
class FunctionOpMapping:
op_code: str
"""TEAL op code for this mapping"""
immediates: Sequence[str | ArgMapping] = attrs.field(factory=tuple)
"""A list of constant values or references to an puyapy argument to include in immediate"""
stack_inputs: Sequence[ArgMapping] = attrs.field(factory=tuple)
"""References to an puyapy argument"""
stack_outputs: Sequence[wtypes.WType] = attrs.field(factory=tuple)
"""Types output by TEAL op"""
is_property: bool = False
"""Is this function represented as a property"""