vile / scheme / implicit_statement.v
26 lines · 23 sloc · 993 bytes · 76646891b77a3d5c6af4a1e42b122cd61dc1654b
Raw
1module scheme
2
3import reader
4
5// Unspellable by a source identifier: Code.name preserves this generated
6// reader abbreviation, while user-written leading NULs are encoded separately.
7const implicit_statement_name = '\x00vile:statement'
8
9fn (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