Define an "interrupt" trap code.
This is a trap code for interrupting the running code, to allow timeouts and safepoints to be implemented. It is resumable.
This commit is contained in:
@@ -38,6 +38,10 @@ pub enum TrapCode {
|
|||||||
/// Failed float-to-int conversion.
|
/// Failed float-to-int conversion.
|
||||||
BadConversionToInteger,
|
BadConversionToInteger,
|
||||||
|
|
||||||
|
/// Execution has potentially run too long and may be interrupted.
|
||||||
|
/// This trap is resumable.
|
||||||
|
Interrupt,
|
||||||
|
|
||||||
/// A user-defined trap code.
|
/// A user-defined trap code.
|
||||||
User(u16),
|
User(u16),
|
||||||
}
|
}
|
||||||
@@ -54,6 +58,7 @@ impl Display for TrapCode {
|
|||||||
IntegerOverflow => "int_ovf",
|
IntegerOverflow => "int_ovf",
|
||||||
IntegerDivisionByZero => "int_divz",
|
IntegerDivisionByZero => "int_divz",
|
||||||
BadConversionToInteger => "bad_toint",
|
BadConversionToInteger => "bad_toint",
|
||||||
|
Interrupt => "interrupt",
|
||||||
User(x) => return write!(f, "user{}", x),
|
User(x) => return write!(f, "user{}", x),
|
||||||
};
|
};
|
||||||
f.write_str(identifier)
|
f.write_str(identifier)
|
||||||
@@ -74,6 +79,7 @@ impl FromStr for TrapCode {
|
|||||||
"int_ovf" => Ok(IntegerOverflow),
|
"int_ovf" => Ok(IntegerOverflow),
|
||||||
"int_divz" => Ok(IntegerDivisionByZero),
|
"int_divz" => Ok(IntegerDivisionByZero),
|
||||||
"bad_toint" => Ok(BadConversionToInteger),
|
"bad_toint" => Ok(BadConversionToInteger),
|
||||||
|
"interrupt" => Ok(Interrupt),
|
||||||
_ if s.starts_with("user") => s[4..].parse().map(User).map_err(|_| ()),
|
_ if s.starts_with("user") => s[4..].parse().map(User).map_err(|_| ()),
|
||||||
_ => Err(()),
|
_ => Err(()),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user