Add a noop if no whitespace is emitted to have something to jump to
Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
parent
59f92e31fe
commit
e0e84ede1c
6 changed files with 16 additions and 11 deletions
|
|
@ -45,6 +45,7 @@ pub enum Instruction {
|
|||
Jump {
|
||||
jump: isize,
|
||||
},
|
||||
NoOp,
|
||||
}
|
||||
|
||||
pub fn emit_machine(input: crate::ast::TemplateAst<'_>) -> Vec<Instruction> {
|
||||
|
|
@ -185,6 +186,8 @@ fn emit_ast_expr(
|
|||
eval.push(Instruction::AppendContent {
|
||||
content: ws.source().clone(),
|
||||
});
|
||||
} else {
|
||||
eval.push(Instruction::NoOp);
|
||||
}
|
||||
|
||||
for index in end_indices {
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ expression: emit
|
|||
content: " " (16..17),
|
||||
},
|
||||
Jump {
|
||||
jump: 13,
|
||||
jump: 14,
|
||||
},
|
||||
AppendContent {
|
||||
content: " " (12..13),
|
||||
|
|
@ -52,7 +52,7 @@ expression: emit
|
|||
content: " " (38..39),
|
||||
},
|
||||
Jump {
|
||||
jump: 6,
|
||||
jump: 7,
|
||||
},
|
||||
AppendContent {
|
||||
content: " " (34..35),
|
||||
|
|
@ -67,9 +67,10 @@ expression: emit
|
|||
content: " " (56..57),
|
||||
},
|
||||
Jump {
|
||||
jump: 1,
|
||||
jump: 2,
|
||||
},
|
||||
AppendContent {
|
||||
content: " " (49..50),
|
||||
},
|
||||
NoOp,
|
||||
]
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ pub fn execute(
|
|||
let instr = instructions.get(ip).unwrap();
|
||||
|
||||
match instr {
|
||||
Instruction::NoOp => (),
|
||||
Instruction::AppendContent { content } => output.push_str(content),
|
||||
Instruction::LoadFromContextToSlot { name, slot } => {
|
||||
let value = global_context
|
||||
|
|
@ -53,12 +54,11 @@ pub fn execute(
|
|||
Instruction::PushScope { inherit_parent: _ } => todo!(),
|
||||
Instruction::Abort => return Err(EvaluationError::ExplicitAbort),
|
||||
Instruction::JumpIfNotTrue { emit_slot, jump } => {
|
||||
let jump = if *jump == 0 { 1 } else { *jump };
|
||||
let dont_jump = scopes.get(emit_slot).unwrap().as_bool().unwrap();
|
||||
if dont_jump {
|
||||
// We are done
|
||||
} else {
|
||||
let (new_ip, overflow) = ip.overflowing_add_signed(jump);
|
||||
let (new_ip, overflow) = ip.overflowing_add_signed(*jump);
|
||||
|
||||
if overflow {
|
||||
return Err(EvaluationError::InstructionPointerOverflow);
|
||||
|
|
@ -69,8 +69,7 @@ pub fn execute(
|
|||
}
|
||||
}
|
||||
Instruction::Jump { jump } => {
|
||||
let jump = if *jump == 0 { 1 } else { *jump };
|
||||
let (new_ip, overflow) = ip.overflowing_add_signed(jump);
|
||||
let (new_ip, overflow) = ip.overflowing_add_signed(*jump);
|
||||
|
||||
if overflow {
|
||||
return Err(EvaluationError::InstructionPointerOverflow);
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ input_file: tests/cases/if_else_if.nomo
|
|||
content: "\n" (37..38),
|
||||
},
|
||||
Jump {
|
||||
jump: 8,
|
||||
jump: 9,
|
||||
},
|
||||
AppendContent {
|
||||
content: "\n " (13..18),
|
||||
|
|
@ -53,9 +53,10 @@ input_file: tests/cases/if_else_if.nomo
|
|||
content: "\n" (81..82),
|
||||
},
|
||||
Jump {
|
||||
jump: 1,
|
||||
jump: 2,
|
||||
},
|
||||
AppendContent {
|
||||
content: "\n " (64..69),
|
||||
},
|
||||
NoOp,
|
||||
]
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ input_file: tests/cases/trim_whitespace.nomo
|
|||
},
|
||||
},
|
||||
Jump {
|
||||
jump: 0,
|
||||
jump: 1,
|
||||
},
|
||||
NoOp,
|
||||
]
|
||||
|
|
|
|||
|
|
@ -3,4 +3,4 @@ source: tests/file_tests.rs
|
|||
expression: output
|
||||
input_file: tests/cases/if_else_if.nomo
|
||||
---
|
||||
"\n \n Hello World!\n\n "
|
||||
"\n \n Hello World!\n"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue