VariableManager lifetime errors
This commit is contained in:
@@ -1518,14 +1518,14 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
|
||||
fn syscall(&mut self) -> Result<SysCall<'a>, Error<'a>> {
|
||||
fn check_length<'a, 't: 'a>(
|
||||
parser: &'t Parser,
|
||||
fn check_length<'a>(
|
||||
span: Span,
|
||||
arguments: &[Spanned<Expression<'a>>],
|
||||
length: usize,
|
||||
) -> Result<(), Error<'a>> {
|
||||
if arguments.len() != length {
|
||||
return Err(Error::InvalidSyntax(
|
||||
parser.current_span(),
|
||||
span,
|
||||
format!("Expected {} arguments", length),
|
||||
));
|
||||
}
|
||||
@@ -1586,17 +1586,17 @@ impl<'a> Parser<'a> {
|
||||
match invocation.name.node.as_ref() {
|
||||
// System SysCalls
|
||||
"yield" => {
|
||||
check_length(self, &invocation.arguments, 0)?;
|
||||
check_length(self.current_span(), &invocation.arguments, 0)?;
|
||||
Ok(SysCall::System(sys_call::System::Yield))
|
||||
}
|
||||
"sleep" => {
|
||||
check_length(self, &invocation.arguments, 1)?;
|
||||
check_length(self.current_span(), &invocation.arguments, 1)?;
|
||||
let mut arg = invocation.arguments.into_iter();
|
||||
let expr = arg.next().ok_or(Error::UnexpectedEOF)?;
|
||||
Ok(SysCall::System(System::Sleep(boxed!(expr))))
|
||||
}
|
||||
"hash" => {
|
||||
check_length(self, &invocation.arguments, 1)?;
|
||||
check_length(self.current_span(), &invocation.arguments, 1)?;
|
||||
let mut args = invocation.arguments.into_iter();
|
||||
let lit_str = literal_or_variable!(args.next());
|
||||
|
||||
@@ -1617,7 +1617,7 @@ impl<'a> Parser<'a> {
|
||||
})))
|
||||
}
|
||||
"load" | "l" => {
|
||||
check_length(self, &invocation.arguments, 2)?;
|
||||
check_length(self.current_span(), &invocation.arguments, 2)?;
|
||||
let mut args = invocation.arguments.into_iter();
|
||||
|
||||
let tmp = args.next();
|
||||
@@ -1662,7 +1662,7 @@ impl<'a> Parser<'a> {
|
||||
)))
|
||||
}
|
||||
"loadBatched" | "lb" => {
|
||||
check_length(self, &invocation.arguments, 3)?;
|
||||
check_length(self.current_span(), &invocation.arguments, 3)?;
|
||||
let mut args = invocation.arguments.into_iter();
|
||||
let tmp = args.next();
|
||||
let device_hash = literal_or_variable!(tmp);
|
||||
@@ -1680,7 +1680,7 @@ impl<'a> Parser<'a> {
|
||||
)))
|
||||
}
|
||||
"loadBatchedNamed" | "lbn" => {
|
||||
check_length(self, &invocation.arguments, 4)?;
|
||||
check_length(self.current_span(), &invocation.arguments, 4)?;
|
||||
let mut args = invocation.arguments.into_iter();
|
||||
let tmp = args.next();
|
||||
let dev_hash = literal_or_variable!(tmp);
|
||||
@@ -1699,7 +1699,7 @@ impl<'a> Parser<'a> {
|
||||
)))
|
||||
}
|
||||
"set" | "s" => {
|
||||
check_length(self, &invocation.arguments, 3)?;
|
||||
check_length(self.current_span(), &invocation.arguments, 3)?;
|
||||
let mut args = invocation.arguments.into_iter();
|
||||
let tmp = args.next();
|
||||
let device = literal_or_variable!(tmp);
|
||||
@@ -1720,7 +1720,7 @@ impl<'a> Parser<'a> {
|
||||
)))
|
||||
}
|
||||
"setBatched" | "sb" => {
|
||||
check_length(self, &invocation.arguments, 3)?;
|
||||
check_length(self.current_span(), &invocation.arguments, 3)?;
|
||||
let mut args = invocation.arguments.into_iter();
|
||||
let tmp = args.next();
|
||||
let device_hash = literal_or_variable!(tmp);
|
||||
@@ -1739,7 +1739,7 @@ impl<'a> Parser<'a> {
|
||||
)))
|
||||
}
|
||||
"setBatchedNamed" | "sbn" => {
|
||||
check_length(self, &invocation.arguments, 4)?;
|
||||
check_length(self.current_span(), &invocation.arguments, 4)?;
|
||||
let mut args = invocation.arguments.into_iter();
|
||||
let tmp = args.next();
|
||||
let device_hash = literal_or_variable!(tmp);
|
||||
@@ -1762,28 +1762,28 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
// Math SysCalls
|
||||
"acos" => {
|
||||
check_length(self, &invocation.arguments, 1)?;
|
||||
check_length(self.current_span(), &invocation.arguments, 1)?;
|
||||
let mut args = invocation.arguments.into_iter();
|
||||
let tmp = args.next().ok_or(Error::UnexpectedEOF)?;
|
||||
|
||||
Ok(SysCall::Math(Math::Acos(boxed!(tmp))))
|
||||
}
|
||||
"asin" => {
|
||||
check_length(self, &invocation.arguments, 1)?;
|
||||
check_length(self.current_span(), &invocation.arguments, 1)?;
|
||||
let mut args = invocation.arguments.into_iter();
|
||||
let tmp = args.next().ok_or(Error::UnexpectedEOF)?;
|
||||
|
||||
Ok(SysCall::Math(Math::Asin(boxed!(tmp))))
|
||||
}
|
||||
"atan" => {
|
||||
check_length(self, &invocation.arguments, 1)?;
|
||||
check_length(self.current_span(), &invocation.arguments, 1)?;
|
||||
let mut args = invocation.arguments.into_iter();
|
||||
let expr = args.next().ok_or(Error::UnexpectedEOF)?;
|
||||
|
||||
Ok(SysCall::Math(Math::Atan(boxed!(expr))))
|
||||
}
|
||||
"atan2" => {
|
||||
check_length(self, &invocation.arguments, 2)?;
|
||||
check_length(self.current_span(), &invocation.arguments, 2)?;
|
||||
let mut args = invocation.arguments.into_iter();
|
||||
let arg1 = args.next().ok_or(Error::UnexpectedEOF)?;
|
||||
let arg2 = args.next().ok_or(Error::UnexpectedEOF)?;
|
||||
@@ -1791,42 +1791,42 @@ impl<'a> Parser<'a> {
|
||||
Ok(SysCall::Math(Math::Atan2(boxed!(arg1), boxed!(arg2))))
|
||||
}
|
||||
"abs" => {
|
||||
check_length(self, &invocation.arguments, 1)?;
|
||||
check_length(self.current_span(), &invocation.arguments, 1)?;
|
||||
let mut args = invocation.arguments.into_iter();
|
||||
let expr = args.next().ok_or(Error::UnexpectedEOF)?;
|
||||
|
||||
Ok(SysCall::Math(Math::Abs(boxed!(expr))))
|
||||
}
|
||||
"ceil" => {
|
||||
check_length(self, &invocation.arguments, 1)?;
|
||||
check_length(self.current_span(), &invocation.arguments, 1)?;
|
||||
let mut args = invocation.arguments.into_iter();
|
||||
let arg = args.next().ok_or(Error::UnexpectedEOF)?;
|
||||
|
||||
Ok(SysCall::Math(Math::Ceil(boxed!(arg))))
|
||||
}
|
||||
"cos" => {
|
||||
check_length(self, &invocation.arguments, 1)?;
|
||||
check_length(self.current_span(), &invocation.arguments, 1)?;
|
||||
let mut args = invocation.arguments.into_iter();
|
||||
let arg = args.next().ok_or(Error::UnexpectedEOF)?;
|
||||
|
||||
Ok(SysCall::Math(Math::Cos(boxed!(arg))))
|
||||
}
|
||||
"floor" => {
|
||||
check_length(self, &invocation.arguments, 1)?;
|
||||
check_length(self.current_span(), &invocation.arguments, 1)?;
|
||||
let mut args = invocation.arguments.into_iter();
|
||||
let arg = args.next().ok_or(Error::UnexpectedEOF)?;
|
||||
|
||||
Ok(SysCall::Math(Math::Floor(boxed!(arg))))
|
||||
}
|
||||
"log" => {
|
||||
check_length(self, &invocation.arguments, 1)?;
|
||||
check_length(self.current_span(), &invocation.arguments, 1)?;
|
||||
let mut args = invocation.arguments.into_iter();
|
||||
let arg = args.next().ok_or(Error::UnexpectedEOF)?;
|
||||
|
||||
Ok(SysCall::Math(Math::Log(boxed!(arg))))
|
||||
}
|
||||
"max" => {
|
||||
check_length(self, &invocation.arguments, 2)?;
|
||||
check_length(self.current_span(), &invocation.arguments, 2)?;
|
||||
let mut args = invocation.arguments.into_iter();
|
||||
let arg1 = args.next().ok_or(Error::UnexpectedEOF)?;
|
||||
let arg2 = args.next().ok_or(Error::UnexpectedEOF)?;
|
||||
@@ -1834,7 +1834,7 @@ impl<'a> Parser<'a> {
|
||||
Ok(SysCall::Math(Math::Max(boxed!(arg1), boxed!(arg2))))
|
||||
}
|
||||
"min" => {
|
||||
check_length(self, &invocation.arguments, 2)?;
|
||||
check_length(self.current_span(), &invocation.arguments, 2)?;
|
||||
let mut args = invocation.arguments.into_iter();
|
||||
let arg1 = args.next().ok_or(Error::UnexpectedEOF)?;
|
||||
let arg2 = args.next().ok_or(Error::UnexpectedEOF)?;
|
||||
@@ -1842,32 +1842,32 @@ impl<'a> Parser<'a> {
|
||||
Ok(SysCall::Math(Math::Min(boxed!(arg1), boxed!(arg2))))
|
||||
}
|
||||
"rand" => {
|
||||
check_length(self, &invocation.arguments, 0)?;
|
||||
check_length(self.current_span(), &invocation.arguments, 0)?;
|
||||
Ok(SysCall::Math(Math::Rand))
|
||||
}
|
||||
"sin" => {
|
||||
check_length(self, &invocation.arguments, 1)?;
|
||||
check_length(self.current_span(), &invocation.arguments, 1)?;
|
||||
let mut args = invocation.arguments.into_iter();
|
||||
let arg = args.next().ok_or(Error::UnexpectedEOF)?;
|
||||
|
||||
Ok(SysCall::Math(Math::Sin(boxed!(arg))))
|
||||
}
|
||||
"sqrt" => {
|
||||
check_length(self, &invocation.arguments, 1)?;
|
||||
check_length(self.current_span(), &invocation.arguments, 1)?;
|
||||
let mut args = invocation.arguments.into_iter();
|
||||
let arg = args.next().ok_or(Error::UnexpectedEOF)?;
|
||||
|
||||
Ok(SysCall::Math(Math::Sqrt(boxed!(arg))))
|
||||
}
|
||||
"tan" => {
|
||||
check_length(self, &invocation.arguments, 1)?;
|
||||
check_length(self.current_span(), &invocation.arguments, 1)?;
|
||||
let mut args = invocation.arguments.into_iter();
|
||||
let arg = args.next().ok_or(Error::UnexpectedEOF)?;
|
||||
|
||||
Ok(SysCall::Math(Math::Tan(boxed!(arg))))
|
||||
}
|
||||
"trunc" => {
|
||||
check_length(self, &invocation.arguments, 1)?;
|
||||
check_length(self.current_span(), &invocation.arguments, 1)?;
|
||||
let mut args = invocation.arguments.into_iter();
|
||||
let arg = args.next().ok_or(Error::UnexpectedEOF)?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user