Add deep access

Signed-off-by: Marcel Müller <neikos@neikos.email>
This commit is contained in:
Marcel Müller 2026-03-15 14:31:46 +01:00
parent 4f770c1f24
commit ffd9baf90f
9 changed files with 669 additions and 5 deletions

View file

@ -119,7 +119,7 @@ pub fn execute(
} else if matches!(value, NomoValue::Undefined) {
String::new()
} else {
panic!("Unknown variable");
panic!("Could not print out value {value:?}");
};
output.push_str(&value);
@ -243,6 +243,46 @@ pub fn execute(
scopes.insert_into_slot(*slot, value);
}
Instruction::LoadFromSlotToSlot { from_slot, to_slot } => {
let value = scopes.get(from_slot);
scopes.insert_into_slot(*to_slot, value.clone());
}
Instruction::JumpIfUndefined { slot, jump } => {
let is_undefined = matches!(scopes.get(slot), NomoValue::Undefined);
if is_undefined {
let Some(new_ip) = vm.labels.get(jump) else {
return Err(EvaluationError::LabelNotFound);
};
ip = *new_ip;
continue;
}
}
Instruction::IndexSlotToSlot {
name,
from_slot,
to_slot,
fail_on_not_found,
} => {
let value = scopes.get(from_slot);
match value {
NomoValue::Object { value } => {
let value = value.get(name.as_str());
let value = if let Some(value) = value {
value.clone()
} else if *fail_on_not_found {
panic!("Could not index");
} else {
NomoValue::Undefined
};
scopes.insert_into_slot(dbg!(*to_slot), dbg!(value));
}
_ => panic!("Invalid indexing"),
}
}
}
ip += 1;