added native functions, enviroment

This commit is contained in:
afonya2 2025-06-04 19:38:59 +02:00
parent 9a915cd274
commit 32c2a20697
Signed by: afonya
GPG key ID: EBB9C4CAFAAFB2DC
4 changed files with 195 additions and 25 deletions

View file

@ -183,7 +183,17 @@ fn do_ast_op(ast_op: ASTPart, op_count: &mut usize, ops: &mut Vec<Operation>, va
},
ASTPart::VarRead(var_read) => {
if get_variable_by_name(variables, &var_read.variable, ops.len()).is_none() {
panic!("Variable {} does not exist", var_read.variable);
let reg = allocate_register(registers);
if reg.unbind_before {
ops.push(Operation { opcode: 8, arg1: Some(reg.register), arg2: None, arg3: None });
}
let str_id = *next_string_id;
strings.insert(str_id, var_read.variable.clone());
*next_string_id += 1;
ops.push(Operation { opcode: 1, arg1: Some(reg.register), arg2: Some(str_id as i64), arg3: None });
ops.push(Operation { opcode: 30, arg1: Some(0), arg2: Some(reg.register as i64), arg3: Some(reg.register) });
set_register(registers, RegisterState { id: reg.register, used: true, variable: 0, last_used: *op_count });
return reg.register;
}
let reg = get_register_by_variable(registers, get_variable_by_name(variables, &var_read.variable, ops.len()).expect("Variable should exist"));
if reg.id == 0 {