5151 ('c_function_name' , str ),
5252 ('error_kind' , int ),
5353 ('steals' , StealsDescription ),
54+ ('is_borrowed' , bool ),
5455 ('ordering' , Optional [List [int ]]),
5556 ('extra_int_constants' , List [Tuple [int , RType ]]),
5657 ('priority' , int )])
6162 ('type' , RType ),
6263 ('src' , str )]) # name of the target to load
6364
64- # Primitive binary ops (key is operator such as '+')
65- binary_ops = {} # type: Dict[str, List[OpDescription]]
66-
6765# Primitive ops for built-in functions (key is function name such as 'builtins.len')
6866func_ops = {} # type: Dict[str, List[OpDescription]]
6967
@@ -116,31 +114,6 @@ def call_emit(func: str) -> EmitCallback:
116114 return simple_emit ('{dest} = %s({comma_args});' % func )
117115
118116
119- def binary_op (op : str ,
120- arg_types : List [RType ],
121- result_type : RType ,
122- error_kind : int ,
123- emit : EmitCallback ,
124- format_str : Optional [str ] = None ,
125- steals : StealsDescription = False ,
126- is_borrowed : bool = False ,
127- priority : int = 1 ) -> None :
128- """Define a PrimitiveOp for a binary operation.
129-
130- Arguments are similar to func_op(), but exactly two argument types
131- are expected.
132-
133- This will be automatically generated by matching against the AST.
134- """
135- assert len (arg_types ) == 2
136- ops = binary_ops .setdefault (op , [])
137- if format_str is None :
138- format_str = '{dest} = {args[0]} %s {args[1]}' % op
139- desc = OpDescription (op , arg_types , result_type , False , error_kind , format_str , emit ,
140- steals , is_borrowed , priority )
141- ops .append (desc )
142-
143-
144117def func_op (name : str ,
145118 arg_types : List [RType ],
146119 result_type : RType ,
@@ -281,6 +254,7 @@ def c_method_op(name: str,
281254 ordering : Optional [List [int ]] = None ,
282255 extra_int_constants : List [Tuple [int , RType ]] = [],
283256 steals : StealsDescription = False ,
257+ is_borrowed : bool = False ,
284258 priority : int = 1 ) -> CFunctionDescription :
285259 """Define a c function call op that replaces a method call.
286260
@@ -303,12 +277,13 @@ def c_method_op(name: str,
303277 accepted by the python syntax(before reordering)
304278 extra_int_constants: optional extra integer constants as the last arguments to a C call
305279 steals: description of arguments that this steals (ref count wise)
280+ is_borrowed: if True, returned value is borrowed (no need to decrease refcount)
306281 priority: if multiple ops match, the one with the highest priority is picked
307282 """
308283 ops = c_method_call_ops .setdefault (name , [])
309284 desc = CFunctionDescription (name , arg_types , return_type , var_arg_type , truncated_type ,
310- c_function_name , error_kind , steals , ordering , extra_int_constants ,
311- priority )
285+ c_function_name , error_kind , steals , is_borrowed , ordering ,
286+ extra_int_constants , priority )
312287 ops .append (desc )
313288 return desc
314289
@@ -323,6 +298,7 @@ def c_function_op(name: str,
323298 ordering : Optional [List [int ]] = None ,
324299 extra_int_constants : List [Tuple [int , RType ]] = [],
325300 steals : StealsDescription = False ,
301+ is_borrowed : bool = False ,
326302 priority : int = 1 ) -> CFunctionDescription :
327303 """Define a c function call op that replaces a function call.
328304
@@ -336,8 +312,8 @@ def c_function_op(name: str,
336312 """
337313 ops = c_function_ops .setdefault (name , [])
338314 desc = CFunctionDescription (name , arg_types , return_type , var_arg_type , truncated_type ,
339- c_function_name , error_kind , steals , ordering , extra_int_constants ,
340- priority )
315+ c_function_name , error_kind , steals , is_borrowed , ordering ,
316+ extra_int_constants , priority )
341317 ops .append (desc )
342318 return desc
343319
@@ -352,6 +328,7 @@ def c_binary_op(name: str,
352328 ordering : Optional [List [int ]] = None ,
353329 extra_int_constants : List [Tuple [int , RType ]] = [],
354330 steals : StealsDescription = False ,
331+ is_borrowed : bool = False ,
355332 priority : int = 1 ) -> CFunctionDescription :
356333 """Define a c function call op for a binary operation.
357334
@@ -362,8 +339,8 @@ def c_binary_op(name: str,
362339 """
363340 ops = c_binary_ops .setdefault (name , [])
364341 desc = CFunctionDescription (name , arg_types , return_type , var_arg_type , truncated_type ,
365- c_function_name , error_kind , steals , ordering , extra_int_constants ,
366- priority )
342+ c_function_name , error_kind , steals , is_borrowed , ordering ,
343+ extra_int_constants , priority )
367344 ops .append (desc )
368345 return desc
369346
@@ -376,13 +353,14 @@ def c_custom_op(arg_types: List[RType],
376353 truncated_type : Optional [RType ] = None ,
377354 ordering : Optional [List [int ]] = None ,
378355 extra_int_constants : List [Tuple [int , RType ]] = [],
379- steals : StealsDescription = False ) -> CFunctionDescription :
356+ steals : StealsDescription = False ,
357+ is_borrowed : bool = False ) -> CFunctionDescription :
380358 """Create a one-off CallC op that can't be automatically generated from the AST.
381359
382360 Most arguments are similar to c_method_op().
383361 """
384362 return CFunctionDescription ('<custom>' , arg_types , return_type , var_arg_type , truncated_type ,
385- c_function_name , error_kind , steals , ordering ,
363+ c_function_name , error_kind , steals , is_borrowed , ordering ,
386364 extra_int_constants , 0 )
387365
388366
@@ -395,6 +373,7 @@ def c_unary_op(name: str,
395373 ordering : Optional [List [int ]] = None ,
396374 extra_int_constants : List [Tuple [int , RType ]] = [],
397375 steals : StealsDescription = False ,
376+ is_borrowed : bool = False ,
398377 priority : int = 1 ) -> CFunctionDescription :
399378 """Define a c function call op for an unary operation.
400379
@@ -405,8 +384,8 @@ def c_unary_op(name: str,
405384 """
406385 ops = c_unary_ops .setdefault (name , [])
407386 desc = CFunctionDescription (name , [arg_type ], return_type , None , truncated_type ,
408- c_function_name , error_kind , steals , ordering , extra_int_constants ,
409- priority )
387+ c_function_name , error_kind , steals , is_borrowed , ordering ,
388+ extra_int_constants , priority )
410389 ops .append (desc )
411390 return desc
412391
0 commit comments