MCPcopy
hub / github.com/hylang/hy / compile_function_lambda

Function compile_function_lambda

hy/core/result_macros.py:1592–1615  ·  view source on GitHub ↗
(compiler, expr, root, is_async, tp, params, body)

Source from the content-addressed store, hash-verified

1590 maybe_annotated(lambda_list),
1591 many(FORM)])
1592def compile_function_lambda(compiler, expr, root, is_async, tp, params, body):
1593 params, returns = params
1594 posonly, args, rest, kwonly, kwargs = params
1595 has_annotations = returns is not None or any(
1596 isinstance(param, tuple) and param[1] is not None
1597 for param in (posonly or []) + args + kwonly + [rest, kwargs]
1598 )
1599 args, ret = compile_lambda_list(compiler, params)
1600 with compiler.local_state(), compiler.scope.create(ScopeFn, args, is_async) as scope:
1601 body = compiler._compile_branch(body)
1602
1603 # Compile to lambda if we can
1604 if not (has_annotations or tp or body.stmts or is_async):
1605 return ret + asty.Lambda(expr, args=args, body=body.force_expr)
1606
1607 # Otherwise create a standard function
1608 node = asty.AsyncFunctionDef if is_async else asty.FunctionDef
1609 name = compiler.get_anon_var()
1610 ret += compile_function_node(
1611 compiler, expr, node, [], tp, name, args, returns, body, scope
1612 )
1613
1614 # return its name as the final expr
1615 return ret + Result(expr=ret.temp_variables[0])
1616
1617
1618@pattern_macro("defn", [

Callers

nothing calls this directly

Calls 7

ResultClass · 0.90
compile_lambda_listFunction · 0.85
compile_function_nodeFunction · 0.85
local_stateMethod · 0.80
createMethod · 0.80
_compile_branchMethod · 0.80
get_anon_varMethod · 0.80

Tested by

no test coverage detected