| 1 | module scheme |
| 2 | |
| 3 | import reader |
| 4 | |
| 5 | // Unspellable by a source identifier: Code.name preserves this generated |
| 6 | // reader abbreviation, while user-written leading NULs are encoded separately. |
| 7 | const implicit_statement_name = '\x00vile:statement' |
| 8 | |
| 9 | fn (mut b Builder) implicit_statement(nodes []reader.NodeId, tail bool, origin reader.NodeId) ! { |
| 10 | if nodes.len != 2 { return failure('invalid implicit call statement') } |
| 11 | // Pattern substitution can replace a bare template variable with any |
| 12 | // expression. Such an expression evaluates once without a second call. |
| 13 | if b.code.node(nodes[1])!.kind != .symbol { |
| 14 | b.expression(nodes[1], tail) |
| 15 | return |
| 16 | } |
| 17 | name := b.code.name(nodes[1])! |
| 18 | binding := b.resolve_binding(name) |
| 19 | // Existing bare control keywords already compile their own exits. |
| 20 | if binding.kind == .keyword && binding.name in ['return', 'break', 'continue'] { |
| 21 | b.expression(nodes[1], tail) |
| 22 | return |
| 23 | } |
| 24 | b.load_resolved(name, binding, nodes[1])! |
| 25 | b.emit(.implicit_call, int(tail), 0, origin) |
| 26 | } |
| 27 | |