Add using literal loading

Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
Marcel Müller 2026-03-12 11:31:08 +01:00
parent 8c02dbd672
commit 05c095ccfe
7 changed files with 162 additions and 1 deletions

View file

@ -2,6 +2,8 @@ use std::collections::BTreeMap;
use crate::ast::TemplateAstExpr;
use crate::input::NomoInput;
use crate::parser::TemplateToken;
use crate::value::NomoValue;
pub struct EmitMachine {
current_index: usize,
@ -88,6 +90,11 @@ pub enum Instruction {
value_ident: NomoInput,
value_slot: VariableSlot,
},
LoadLiteralToSlot {
source: TemplateToken,
value: NomoValue,
slot: VariableSlot,
},
}
#[derive(Debug, Clone)]
@ -421,6 +428,13 @@ fn emit_expr_load(
slot: emit_slot,
});
}
TemplateAstExpr::Literal { source, value } => {
eval.push(Instruction::LoadLiteralToSlot {
source: source.clone(),
value: value.clone(),
slot: emit_slot,
});
}
TemplateAstExpr::Invalid { .. } => eval.push(Instruction::Abort),
TemplateAstExpr::StaticContent { .. } | TemplateAstExpr::Interpolation { .. } => {
unreachable!("Invalid AST here")
@ -433,7 +447,6 @@ fn emit_expr_load(
TemplateAstExpr::For { .. } => todo!(),
TemplateAstExpr::ForElse => todo!(),
TemplateAstExpr::Operation { .. } => todo!(),
TemplateAstExpr::Literal { .. } => todo!(),
TemplateAstExpr::IfConditional { .. } => todo!(),
TemplateAstExpr::ConditionalContent { .. } => todo!(),

View file

@ -179,6 +179,13 @@ pub fn execute(vm: &VMInstructions, global_context: &Context) -> Result<String,
scopes.insert_into_scope(value_ident, value);
}
Instruction::LoadLiteralToSlot {
source: _,
value,
slot,
} => {
scopes.insert_into_slot(*slot, value.clone());
}
}
ip += 1;