refactor(compiler): remove simple expression count helpers
This commit is contained in:
@@ -5,14 +5,6 @@ mod tagged;
|
||||
mod template_literal;
|
||||
|
||||
impl Compiler {
|
||||
pub(crate) fn count_template_domain(&self, expr: &Expression, ctx: &mut CompileCtx) {
|
||||
match expr {
|
||||
Expression::TemplateLiteral(_) => self.count_template_literal(expr, ctx),
|
||||
Expression::TaggedTemplateExpression(_) => self.count_tagged_template_expression(expr, ctx),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn emit_template_domain(&self, expr: &Expression, ctx: &mut CompileCtx) -> Result<u8, String> {
|
||||
match expr {
|
||||
Expression::TemplateLiteral(tl) => self.emit_template_literal_expression(tl, ctx),
|
||||
|
||||
@@ -3,48 +3,7 @@ use oxide_bytecode::{
|
||||
module::Constant,
|
||||
opcode::{self, OpCode},
|
||||
};
|
||||
use oxide_parser::Expression;
|
||||
|
||||
impl Compiler {
|
||||
pub(crate) fn count_tagged_template_expression(&self, expr: &Expression, ctx: &mut CompileCtx) {
|
||||
let Expression::TaggedTemplateExpression(tt) = expr else {
|
||||
return;
|
||||
};
|
||||
self.count_expression(&tt.tag, ctx);
|
||||
let quasi_count = tt.quasi.quasis.len();
|
||||
|
||||
for _ in 0..quasi_count {
|
||||
ctx.count_load_const();
|
||||
ctx.count_load_const();
|
||||
ctx.count_instr();
|
||||
}
|
||||
ctx.alloc_reg();
|
||||
ctx.count_instr();
|
||||
|
||||
for _ in 0..quasi_count {
|
||||
ctx.count_load_const();
|
||||
ctx.count_load_const();
|
||||
ctx.count_instr();
|
||||
}
|
||||
ctx.alloc_reg();
|
||||
ctx.count_instr();
|
||||
|
||||
for expr in &tt.quasi.expressions {
|
||||
self.count_expression(expr, ctx);
|
||||
}
|
||||
|
||||
ctx.alloc_reg();
|
||||
ctx.alloc_reg();
|
||||
for _ in &tt.quasi.expressions {
|
||||
ctx.alloc_reg();
|
||||
ctx.count_instr();
|
||||
}
|
||||
ctx.count_words(2);
|
||||
ctx.count_load_const();
|
||||
ctx.count_call_instr_with_arg_ext();
|
||||
ctx.count_load_var();
|
||||
}
|
||||
|
||||
pub(crate) fn emit_tagged_template_expression(
|
||||
&self, tt: &oxide_parser::TaggedTemplateExpression, ctx: &mut CompileCtx,
|
||||
) -> Result<u8, String> {
|
||||
|
||||
@@ -3,20 +3,7 @@ use oxide_bytecode::{
|
||||
module::Constant,
|
||||
opcode::{self, OpCode},
|
||||
};
|
||||
use oxide_parser::Expression;
|
||||
|
||||
impl Compiler {
|
||||
pub(crate) fn count_template_literal(&self, expr: &Expression, ctx: &mut CompileCtx) {
|
||||
let Expression::TemplateLiteral(tl) = expr else {
|
||||
return;
|
||||
};
|
||||
for expr in &tl.expressions {
|
||||
self.count_expression(expr, ctx);
|
||||
}
|
||||
let segment_count = tl.quasis.len() + tl.expressions.len();
|
||||
ctx.count_template_str(segment_count);
|
||||
}
|
||||
|
||||
pub(crate) fn emit_template_literal_expression(
|
||||
&self, tl: &oxide_parser::TemplateLiteral, ctx: &mut CompileCtx,
|
||||
) -> Result<u8, String> {
|
||||
|
||||
Reference in New Issue
Block a user