concepts.dsl.dsl_functions.Function#
- class Function[source]#
Bases:
object
A function object holds a function type and an optional overridden __call__.
The function object holds an additional field called overridden_call, which isa callable function. This field is used to override the __call__ method of the function object.
By default, the __call__ function returns a FunctionApplication object, which contains the name of the function and a list of arguments. However, when overridden_call is set, the __call__ method will return the result of calling overridden_call with the arguments.
Methods
from_function
(function[, implementation, sig])Create a function object from an actual Python function.
get_overridden_call
([ftype_index])Get the overridden call function.
get_sub_function
(ftype_index)partial
(*args[, execute_fully_bound_functions])remap_arguments
(remapping)Generate a new Function object with a different argument order.
set_function_body
(function_body)Set the function body.
set_function_name
(function_name)Set the function name.
Attributes
Return True if the function is overloaded.
- __init__(name, ftype, derived_expression=None, overridden_call=None, resolved_from=None, function_body=None)[source]#
- Parameters:
name (str) – the name of the function.
ftype (FunctionType | OverloadedFunctionType) – the function type.
derived_expression (Expression | FunctionDerivedExpressionList | None) – the expression that this function is derived from.
overridden_call (Callable | FunctionOverriddenCallList | None) – the overridden call function.
resolved_from (FunctionResolvedFromRecord | None) – the record of the function that this function is resolved from. This is used for handling partial evaluation and function specialization (for overloadded functions).
function_body (Callable | Sequence[Callable] | None) – the function body.
- __new__(**kwargs)#
- classmethod from_function(function, implementation=True, sig=None)[source]#
Create a function object from an actual Python function.
- remap_arguments(remapping)[source]#
Generate a new Function object with a different argument order. Specifically, remapping is a permutation. The i-th argument to the new function will be the remapping[i]-th argument in the old function.
- set_function_body(function_body)[source]#
Set the function body.
- Parameters:
function_body (Callable)
- property all_sub_functions#
- property return_type: ObjectType | ValueType | FunctionType | SequenceType#