setOnDevice
This commit is contained in:
@@ -3,7 +3,7 @@ use indoc::indoc;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn test_yield_syscall() -> anyhow::Result<()> {
|
||||
fn test_yield() -> anyhow::Result<()> {
|
||||
let compiled = compile! {
|
||||
debug
|
||||
"
|
||||
@@ -26,7 +26,7 @@ fn test_yield_syscall() -> anyhow::Result<()> {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sleep_syscall() -> anyhow::Result<()> {
|
||||
fn test_sleep() -> anyhow::Result<()> {
|
||||
let compiled = compile! {
|
||||
debug
|
||||
"
|
||||
@@ -51,3 +51,33 @@ fn test_sleep_syscall() -> anyhow::Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_set_on_device() -> anyhow::Result<()> {
|
||||
let compiled = compile! {
|
||||
debug
|
||||
r#"
|
||||
device airConditioner = "d0";
|
||||
let internalTemp = 20c;
|
||||
|
||||
let shouldToggleOn = internalTemp > 25c;
|
||||
setOnDevice(airConditioner, "On", shouldToggleOn);
|
||||
"#
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
compiled,
|
||||
indoc! {
|
||||
"
|
||||
j main
|
||||
main:
|
||||
move r8 293.15 #internalTemp
|
||||
sgt r1 r8 298.15
|
||||
move r9 r1 #shouldToggleOn
|
||||
s d0 On r9
|
||||
"
|
||||
}
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1017,6 +1017,34 @@ impl<'a, W: std::io::Write> Compiler<'a, W> {
|
||||
|
||||
Ok(None)
|
||||
}
|
||||
System::SetOnDevice(device, logic_type, variable) => {
|
||||
let (variable, var_cleanup) = self.compile_literal_or_variable(variable, scope)?;
|
||||
|
||||
let LiteralOrVariable::Variable(device) = device else {
|
||||
return Err(Error::AgrumentMismatch(
|
||||
"Arg1 expected to be a variable".into(),
|
||||
));
|
||||
};
|
||||
|
||||
let Some(device) = self.devices.get(&device) else {
|
||||
return Err(Error::InvalidDevice(device));
|
||||
};
|
||||
|
||||
let Literal::String(logic_type) = logic_type else {
|
||||
return Err(Error::AgrumentMismatch(
|
||||
"Arg2 expected to be a string".into(),
|
||||
));
|
||||
};
|
||||
|
||||
self.write_output(format!("s {} {} {}", device, logic_type, variable))?;
|
||||
|
||||
if let Some(temp_var) = var_cleanup {
|
||||
scope.free_temp(temp_var)?;
|
||||
}
|
||||
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
_ => {
|
||||
todo!()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user