rue_compiler/compile/binding/
pair_binding.rs

1use rue_ast::{AstNode, AstPairBinding};
2use rue_hir::{BindingSymbol, Declaration, Hir, Symbol, SymbolId, SymbolPath, Value};
3
4use crate::{Compiler, compile_pair_fields, create_binding};
5
6pub fn create_pair_binding(ctx: &mut Compiler, symbol: SymbolId, binding: &AstPairBinding) {
7    let ty = ctx.symbol_type(symbol);
8
9    let reference = Value::new(ctx.alloc_hir(Hir::Reference(symbol)), ty)
10        .with_reference(SymbolPath::new(symbol, vec![]));
11
12    let (first_value, rest_value) = compile_pair_fields(ctx, binding.syntax(), &reference);
13
14    if let Some(first) = binding.first() {
15        let first_symbol = ctx.alloc_symbol(Symbol::Binding(BindingSymbol {
16            name: None,
17            value: first_value,
18            inline: true,
19        }));
20        ctx.push_declaration(Declaration::Symbol(first_symbol));
21        ctx.reference(Declaration::Symbol(symbol));
22        create_binding(ctx, first_symbol, &first);
23        ctx.pop_declaration();
24    }
25
26    if let Some(rest) = binding.rest() {
27        let rest_symbol = ctx.alloc_symbol(Symbol::Binding(BindingSymbol {
28            name: None,
29            value: rest_value,
30            inline: true,
31        }));
32        ctx.push_declaration(Declaration::Symbol(rest_symbol));
33        ctx.reference(Declaration::Symbol(symbol));
34        create_binding(ctx, rest_symbol, &rest);
35        ctx.pop_declaration();
36    }
37}