This commit is contained in:
2026-01-26 12:22:44 +01:00
parent 1b32a91b0d
commit 66933433d1
14 changed files with 1030 additions and 884 deletions

View File

@@ -94,8 +94,8 @@ fn tokenize(input: &str) -> Vec<Token> {
fn compile(tokens: &[Token], dict: &Dictionary) -> Result<Vec<Op>, String> {
let mut ops = Vec::new();
let mut i = 0;
let mut pipe_parity = false;
let mut list_depth: usize = 0;
let mut pipe_parity = false;
while i < tokens.len() {
match &tokens[i] {
@@ -119,15 +119,6 @@ fn compile(tokens: &[Token], dict: &Dictionary) -> Result<Vec<Op>, String> {
dict.lock().unwrap().insert(name, body);
} else if word == ";" {
return Err("unexpected ;".into());
} else if word == "|" {
if pipe_parity {
ops.push(Op::LocalCycleEnd);
list_depth = list_depth.saturating_sub(1);
} else {
ops.push(Op::ListStart);
list_depth += 1;
}
pipe_parity = !pipe_parity;
} else if word == "if" {
let (then_ops, else_ops, consumed, then_span, else_span) = compile_if(&tokens[i + 1..], dict)?;
i += consumed;
@@ -140,6 +131,13 @@ fn compile(tokens: &[Token], dict: &Dictionary) -> Result<Vec<Op>, String> {
ops.push(Op::Branch(else_ops.len()));
ops.extend(else_ops);
}
} else if word == "|" {
if pipe_parity {
ops.push(Op::InternalCycleEnd);
} else {
ops.push(Op::ListStart);
}
pipe_parity = !pipe_parity;
} else if is_list_start(word) {
ops.push(Op::ListStart);
list_depth += 1;