lovm2_core/gen/hir/
include.rs

1//! Loads a module by name into the VM
2
3use super::*;
4
5/// Loads a module by name into the VM
6#[derive(Clone)]
7pub struct Include {
8    name: Expr,
9    namespaced: bool,
10}
11
12impl Include {
13    pub fn import<T>(name: T) -> Self
14    where
15        T: Into<Expr>,
16    {
17        Self {
18            name: name.into(),
19            namespaced: true,
20        }
21    }
22
23    pub fn import_global<T>(name: T) -> Self
24    where
25        T: Into<Expr>,
26    {
27        Self {
28            name: name.into(),
29            namespaced: false,
30        }
31    }
32}
33
34impl HirLowering for Include {
35    fn lower<'hir, 'lir>(&'hir self, runtime: &mut HirLoweringRuntime<'lir>)
36    where
37        'hir: 'lir,
38    {
39        self.name.lower(runtime);
40
41        let elem = LirElement::Import {
42            namespaced: self.namespaced,
43        };
44        runtime.emit(elem);
45    }
46}