Skip to content
← Back

src/syntax/trees/expressions/function.ghul

1
namespace Syntax.Trees.Expressions is
2
use Source
3
4
class FUNCTION: Expression, ScopeCarrier is
5
scope: Semantic.Scope? public
6
7
arguments: LIST
8
type_expression: TypeExpressions.TypeExpression
9
is_recursive: bool
10
11
// True when the lambda's body contains an `await` expression
12
// (not inside a nested lambda). Set by declare-symbols.
13
// Read by compile-lambdas to decide whether an implicit-INFER
14
// return type becomes a plain placeholder or settles to
15
// `Tasks.TASK[T]`.
16
contains_let_await: bool public
17
18
// True when `contains_let_await` is set AND the body has no
19
// value-returning `return X;` statements — meaning the
20
// lambda's inferred return type should be the non-generic
21
// `Tasks.TASK` (rather than `Tasks.TASK[T]` for some T).
22
// End-of-body fallthrough and bare `return;` in such a body
23
// produce a TaskCompletionSource.SetResult() with no value.
24
is_void_async: bool public
25
26
// The name a nested named function statement wrote. Null on
27
// every anonymous literal. The literal is otherwise unchanged:
28
// the name reaches the enclosing scope through the statement's
29
// own variable, and this carries it to declare-members, which
30
// needs it to recognise the body's references to the function
31
// itself.
32
nested_name: Identifiers.Identifier? public
33
34
mark_recursive() is
35
is_recursive = true
36
si
37
38
set_nested_name(name: Identifiers.Identifier) is
39
nested_name = name
40
si
41
42
body: Bodies.Body
43
44
// True when the walk found the body produced only null and
45
// nothing had yet said what the return is optional of. A call
46
// argument's formal arrives on the re-walk the call site drives
47
// once the callee is resolved, so until one does the literal
48
// reports itself as taking its type from the context.
49
returned_only_null_without_slot: bool public
50
51
awaits_context_type: bool => returned_only_null_without_slot
52
53
// Constraint pushed in by the parent context (LHS of an
54
// assignment, declared variable type, etc.). Read by the
55
// compile_expressions function-literal visitor as a fallback
56
// for argument-type inference when the existing
57
// _partial_argument_function_type implication channel hasn't
58
// been set.
59
60
init(
61
location: LOCATION,
62
arguments: LIST,
63
type_expression: TypeExpressions.TypeExpression,
64
body: Bodies.Body,
65
is_recursive: bool
66
)
67
is
68
super.init(location)
69
70
self.arguments = arguments
71
self.type_expression = type_expression
72
self.is_recursive = is_recursive
73
74
self.body = body
75
si
76
77
set_expected_type(expected_type: Semantic.Types.Type?, error_message: string?) is
78
compile_expressions_state.set_expected_type(expected_type, error_message)
79
si
80
81
accept(visitor: Visitor) is
82
visitor.visit(self)
83
si
84
85
walk(visitor: Visitor) is
86
if !visitor.pre(self) then
87
type_expression.walk(visitor)
88
arguments.walk(visitor)
89
body.walk(visitor)
90
fi
91
92
accept(visitor)
93
si
94
si
95
si