prepare for coroutine

This commit is contained in:
afonya 2025-06-18 14:46:59 +02:00
parent c626af7cd4
commit 17ffb11f34
Signed by: afonya
GPG key ID: EBB9C4CAFAAFB2DC
8 changed files with 107 additions and 130 deletions

View file

@ -310,7 +310,7 @@ fn do_ast_op(ast_op: ASTPart, op_count: &mut usize, ops: &mut Vec<Operation>, va
ASTPart::Else(else_part) => {
if get_variable_by_name(variables, "__LASTIF", ops.len(), traceback).is_none() {
let err = create_error(&format!("Else used without an if statement before it"), else_part.pos, ErrorType::SemanticError, ErrorSubType::ElseWithoutIf, ctx);
print_error(&err, &ctx);
print_error(&err);
process::exit(1);
}
let reg = get_register_by_variable(registers, get_variable_by_name(variables, "__LASTIF", ops.len(), traceback).expect("__LASTIF should exist").clone());
@ -358,7 +358,7 @@ fn do_ast_op(ast_op: ASTPart, op_count: &mut usize, ops: &mut Vec<Operation>, va
ASTPart::ElseIf(elseif_part) => {
if get_variable_by_name(variables, "__LASTIF", ops.len(), traceback).is_none() {
let err = create_error(&format!("Else if used without an if statement before it"), elseif_part.pos, ErrorType::SemanticError, ErrorSubType::ElseWithoutIf, ctx);
print_error(&err, &ctx);
print_error(&err);
process::exit(1);
}
let reg = get_register_by_variable(registers, get_variable_by_name(variables, "__LASTIF", ops.len(), traceback).expect("__LASTIF should exist").clone());
@ -472,12 +472,12 @@ fn do_ast_op(ast_op: ASTPart, op_count: &mut usize, ops: &mut Vec<Operation>, va
},
ASTPart::Break(brk) => {
let err = create_error(&format!("Unexpected break outside of loop"), brk.pos, ErrorType::SemanticError, ErrorSubType::BreakContinueWithoutLoop, ctx);
print_error(&err, &ctx);
print_error(&err);
process::exit(1);
},
ASTPart::Continue(cont) => {
let err = create_error(&format!("Unexpected continue outside of loop"), cont.pos, ErrorType::SemanticError, ErrorSubType::BreakContinueWithoutLoop, ctx);
print_error(&err, &ctx);
print_error(&err);
process::exit(1);
},
ASTPart::For(for_part) => {
@ -575,7 +575,7 @@ fn do_ast_op(ast_op: ASTPart, op_count: &mut usize, ops: &mut Vec<Operation>, va
},
_ => {
let err = create_error(&format!("Unknown operator `{}`", op.operator), op.pos, ErrorType::SyntaxError, ErrorSubType::UnknownOperation, ctx);
print_error(&err, &ctx);
print_error(&err);
process::exit(1);
},
};
@ -586,7 +586,7 @@ fn do_ast_op(ast_op: ASTPart, op_count: &mut usize, ops: &mut Vec<Operation>, va
ASTPart::VarUpdate(upd) => {
if get_variable_by_name(variables, &upd.variable, ops.len(), traceback).is_none() {
let err = create_error(&format!("Variable `{}` does not exist", upd.variable), upd.pos, ErrorType::SemanticError, ErrorSubType::VariableNotFound, ctx);
print_error(&err, &ctx);
print_error(&err);
process::exit(1);
}
let value_reg = do_ast_op(*upd.value, op_count, ops, variables, next_var_id, strings, next_string_id, functions, next_function_id, registers, ctx, traceback);
@ -602,7 +602,7 @@ fn do_ast_op(ast_op: ASTPart, op_count: &mut usize, ops: &mut Vec<Operation>, va
ASTPart::Assigment(asign) => {
if get_variable_by_name(variables, &asign.variable, ops.len(), traceback).is_some() {
let err = create_error(&format!("Variable `{}` already exists", asign.variable), asign.pos, ErrorType::SemanticError, ErrorSubType::VariableAlreadyExists, ctx);
print_error(&err, &ctx);
print_error(&err);
process::exit(1);
}
let reg = do_ast_op(*asign.value, op_count, ops, variables, next_var_id, strings, next_string_id, functions, next_function_id, registers, ctx, traceback);
@ -673,7 +673,7 @@ fn do_ast_op(ast_op: ASTPart, op_count: &mut usize, ops: &mut Vec<Operation>, va
},
Err(e) => {
let err = create_error(&format!("Failed to read file `{}`: {}", impr.path, e), impr.pos, ErrorType::IOError, ErrorSubType::FileError, ctx);
print_error(&err, &ctx);
print_error(&err);
process::exit(1);
}
}
@ -727,7 +727,7 @@ fn compile_function(ast: Vec<ASTPart>, args: Option<Vec<String>>, registers: &mu
for arg in arg_list {
if get_variable_by_name(&variables, &arg, 0, &empty_tb).is_some() {
let err = create_error(&format!("Argument `{}` already exists", arg), 0, ErrorType::SemanticError, ErrorSubType::ArgumentDuplication, ctx);
print_error(&err, &ctx);
print_error(&err);
process::exit(1);
}
variables.push( Variable { name: arg, id: *next_var_id, start: 0, end: 0, no_end: true });