summaryrefslogtreecommitdiffstats
path: root/third_party/rust/jsparagus-emitter/src/expression_emitter.rs
blob: 45f0e10664e854f245a89abad301fe344c3a0494 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use crate::ast_emitter::AstEmitter;
use crate::emitter::EmitError;

pub struct ExpressionEmitter<F>
where
    F: Fn(&mut AstEmitter) -> Result<(), EmitError>,
{
    pub expr: F,
}

impl<F> ExpressionEmitter<F>
where
    F: Fn(&mut AstEmitter) -> Result<(), EmitError>,
{
    pub fn emit(self, emitter: &mut AstEmitter) -> Result<(), EmitError> {
        //              [stack]

        (self.expr)(emitter)?;
        //              [stack] VAL

        if emitter.options.no_script_rval {
            emitter.emit.pop();
        //          [stack]
        } else {
            emitter.emit.set_rval();
            //          [stack]
        }

        Ok(())
    }
}