NL i/UdZddlmZddlmZmZddlmZmZddl m Z dZ de d<Gd d eZ Gd d eZiZd e d<iZd e d<iZd e d<iZd e d<iZde d< d ddZ d d!dZ d" d#dZ d$dd d%dZ d& d'dZ d( d)dZd*dZddlZddlZddlZddlZddl Zddl!Zddl"Zddl#Zddl$Zy)+a;Utilities for defining primitive ops. Most of the ops can be automatically generated by matching against AST nodes and types. For example, a func_op is automatically generated when a specific function is called with the specific positional argument count and argument types. Example op definition: list_len_op = func_op(name='builtins.len', arg_types=[list_rprimitive], result_type=short_int_rprimitive, error_kind=ERR_NEVER, emit=emit_len) This op is automatically generated for calls to len() with a single list argument. The result type is short_int_rprimitive, and this never raises an exception (ERR_NEVER). The function emit_len is used to generate C for this op. The op can also be manually generated using "list_len_op". Ops that are only generated automatically don't need to be assigned to a module attribute. Ops defined with custom_op are only explicitly generated in mypyc.irbuild and won't be generated automatically. They are always assigned to a module attribute, as otherwise they won't be accessible. The actual ops are defined in other submodules of this package, grouped by category. Most operations have fallback implementations that apply to all possible arguments and types. For example, there are generic implementations of arbitrary function and method calls, and binary operators. These generic implementations are typically slower than specialized ones, but we tend to rely on them for infrequently used ops. It's impractical to have optimized implementations of all ops. ) annotations)Final NamedTuple)PrimitiveDescriptionStealsDescription)RType r ERR_NEG_INTceZdZUded<ded<ded<ded<ded <ded <d ed <d ed<ded<ded<ded<d ed<ded<y)CFunctionDescriptionstrname list[RType] arg_typesr return_type RType | None var_arg_typetruncated_typec_function_nameint error_kindrstealsbool is_borrowedlist[int] | Noneorderingzlist[tuple[int, RType]]extra_int_constantspriorityis_pureN__name__ __module__ __qualname____annotations___/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/mypyc/primitives/registry.pyr r 2sL I  O 00M Mr&r c,eZdZUded<ded<ded<y)LoadAddressDescriptionr rrtypesrcNr r%r&r'r)r)Cs I K Hr&r)z%dict[str, list[PrimitiveDescription]]method_call_ops function_ops binary_ops unary_opszdict[str, tuple[RType, str]] builtin_namesNFc |g}tj|g} t|||||||| | ||| |  }| j||S)a.Define a c function call op that replaces a method call. This will be automatically generated by matching against the AST. Args: name: short name of the method (for example, 'append') arg_types: argument types; the receiver is always the first argument return_type: type of the return value. Use void_rtype to represent void. c_function_name: name of the C function to call error_kind: how errors are represented in the result (one of ERR_*) var_arg_type: type of all variable arguments truncated_type: type to truncated to(See Truncate for info) if it's defined both return_type and it should be non-referenced integer types or bool type ordering: optional ordering of the arguments, if defined, reorders the arguments accordingly. should never be used together with var_arg_type. all the other arguments(such as arg_types) are in the order accepted by the python syntax(before reordering) extra_int_constants: optional extra integer constants as the last arguments to a C call steals: description of arguments that this steals (ref count wise) is_borrowed: if True, returned value is borrowed (no need to decrease refcount) priority: if multiple ops match, the one with the highest priority is picked is_pure: if True, declare that the C function has no side effects, takes immutable arguments, and never raises an exception r)r, setdefaultrappend)rrrrrrrrrrrrropsdescs r' method_opr7XsgR"   $ $T2 .C   DJJt Kr&c |g}tj|g} t|||||||| | ||| d } | j| | S)a-Define a C function call op that replaces a function call. This will be automatically generated by matching against the AST. Most arguments are similar to method_op(). Args: name: full name of the function arg_types: positional argument types for which this applies F rrrrrrrrrr)r-r3rr4)rrrrrrrrrrrrr5r6s r' function_opr:sf0"   ! !$ +C  !%'/ DJJt Kr&c ||J||J| g} tj|g} t|xs|||||||| | || | d }| j||S)zDefine a c function call op for a binary operation. This will be automatically generated by matching against the AST. Most arguments are similar to method_op(), but exactly two argument types are expected. F rrrrrrrrrrrrr)r.r3rr4)rrrrrprimitive_namerrrrrrrr5r6s r' binary_opr>s,  &.*DD D+0JK K"    b )C   #t!%'/ DJJt Kr&r2c :|g}td|||||||| ||d|  S)zCreate a one-off CallC op that can't be automatically generated from the AST. Most arguments are similar to method_op(). zrr2)r ) rrrrrrrrrrrs r' custom_opr@sD$"    r&c :|g}t|||||||| | ||d|  S)zDefine a primitive op that can't be automatically generated based on the AST. Most arguments are similar to method_op(). rr<)r) rrrrrrrrrrrrs r'custom_primitive_oprBsD$"   !%'/ r&c |g}tj|g} t||g|d||||| ||| |  } | j| | S)zDefine a primitive op for an unary operation. This will be automatically generated by matching against the AST. Most arguments are similar to method_op(), but exactly one argument type is expected. Nr9)r/r3rr4)rarg_typerrrrrrrrrrr5r6s r'unary_oprE=sh*"    tR (C   %'/ DJJt Kr&cV|tvs Jd|z||ft|<t|||S)Nzalready defined: %s)r0r))rr*r+s r'load_address_oprGhs8 } $B&;d&BB $+M$ !$c 22r&)NNNNFFF)rr rrrrrr rrrrrrrrrlist[tuple[int, RType]] | Nonerrrrrrrrreturnr)NNNNFFrH)rr rrrrrr rrrrrrrrrrIrrrrrrrJr) NNNNNNFFrH)rr rrrrrrr str | Noner=rKrrrrrrrrIrrrrrrrJr)NNNNFF)rrrrrr rrrrrrrrrrIrrrrrrrJr )NNNNNFFF)rr rrrrrrrrKrrrrrrrrIrrrrrrrJr)NNNFFrHF)rr rDrrrrr rrrrrrrrIrrrrrrrrrJr)rr r*rr+r rJr))%__doc__ __future__rtypingrr mypyc.ir.opsrrmypyc.ir.rtypesrr r$r r)r,r-r.r/r0r7r:r>r@rBrErGmypyc.primitives.bytes_opsmypycmypyc.primitives.dict_opsmypyc.primitives.float_opsmypyc.primitives.int_opsmypyc.primitives.list_opsmypyc.primitives.misc_opsmypyc.primitives.str_opsmypyc.primitives.tuple_opsmypyc.primitives.weakref_opsr%r&r'r[s]#J#$@! U : " Z :<6;79 3857 1646 05.0 +0"&#'!%:> %< <<< <  <  <!<<8< <<<<<J"&#'!%:> %+ +++ +  +  +!++8+ ++++f#'!%!%#'!%:> %+ +++ +  +  ++!++8+ ++++f"&#'!%:> %""""" "  " ! ""8" """"T#'!%#'!%:> %" """ "  "  "!""8" """"V$(!%:> %( ((( (  ( ! ((8( (((((V3" ! !#r&