Skip to content

Commit 6a32790

Browse files
committed
Remove Halt error
1 parent ac45369 commit 6a32790

4 files changed

Lines changed: 11 additions & 13 deletions

File tree

src/error.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ pub type ErrorS = Spanned<Error>;
1616
pub enum Error {
1717
#[error("AttributeError: {0}")]
1818
AttributeError(AttributeError),
19-
#[error("")]
20-
Halt,
2119
#[error("IOError: {0}")]
2220
IoError(IoError),
2321
#[error("NameError: {0}")]
@@ -34,7 +32,6 @@ impl AsDiagnostic for Error {
3432
fn as_diagnostic(&self, span: &Span) -> Diagnostic<()> {
3533
match self {
3634
Error::AttributeError(e) => e.as_diagnostic(span),
37-
Error::Halt => unreachable!(),
3835
Error::IoError(e) => e.as_diagnostic(span),
3936
Error::NameError(e) => e.as_diagnostic(span),
4037
Error::OverflowError(e) => e.as_diagnostic(span),

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![allow(incomplete_features)]
1+
#![allow(dangerous_implicit_autorefs, incomplete_features)]
22
#![feature(explicit_tail_calls)]
33

44
pub mod cmd;

src/vm/mod.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,7 @@ impl<'a> VM<'a> {
123123
self.source.push('\n');
124124

125125
let function = Compiler::compile(source, offset, &mut self.gc)?;
126-
match self.run_function(function) {
127-
Ok(()) | Err((Error::Halt, _)) => Ok(()),
128-
Err(e) => Err(vec![e]),
129-
}
126+
self.run_function(function).map_err(|e| vec![e])
130127
}
131128

132129
fn run_function(&mut self, function: *mut ObjectFunction) -> Result<()> {
@@ -272,15 +269,15 @@ impl<'a> VM<'a> {
272269

273270
fn op_get_upvalue(&mut self, ip: &mut *const u8) -> Result<()> {
274271
let upvalue_idx = Self::read_u8(ip) as usize;
275-
let object = *unsafe { (&(*self.frame.closure).upvalues).get_unchecked(upvalue_idx) };
272+
let object = *unsafe { (*self.frame.closure).upvalues.get_unchecked(upvalue_idx) };
276273
let value = unsafe { *(*object).location };
277274
self.push(value);
278275
become self.dispatch(ip)
279276
}
280277

281278
fn op_set_upvalue(&mut self, ip: &mut *const u8) -> Result<()> {
282279
let upvalue_idx = Self::read_u8(ip) as usize;
283-
let object = *unsafe { (&(*self.frame.closure).upvalues).get_unchecked(upvalue_idx) };
280+
let object = *unsafe { (*self.frame.closure).upvalues.get_unchecked(upvalue_idx) };
284281
let value = unsafe { (*object).location };
285282
unsafe { *value = *self.peek(0) };
286283
become self.dispatch(ip)
@@ -566,7 +563,7 @@ impl<'a> VM<'a> {
566563
let location = unsafe { self.frame.stack.add(upvalue_idx) };
567564
self.capture_upvalue(location)
568565
} else {
569-
*unsafe { (&(*self.frame.closure).upvalues).get_unchecked(upvalue_idx) }
566+
*unsafe { (*self.frame.closure).upvalues.get_unchecked(upvalue_idx) }
570567
};
571568
upvalues.push(upvalue);
572569
}
@@ -595,7 +592,7 @@ impl<'a> VM<'a> {
595592
self.push(value);
596593
become self.dispatch(ip)
597594
}
598-
None => Err((Error::Halt, 0..0)),
595+
None => Ok(()),
599596
}
600597
}
601598

@@ -811,7 +808,7 @@ impl<'a> VM<'a> {
811808
fn read_value(&self, ip: &mut *const u8) -> Value {
812809
let constant_idx = Self::read_u8(ip) as usize;
813810
let function = unsafe { (*self.frame.closure).function };
814-
*unsafe { (&(*function).chunk.constants).get_unchecked(constant_idx) }
811+
*unsafe { (*function).chunk.constants.get_unchecked(constant_idx) }
815812
}
816813

817814
/// Pushes a [`Value`] to the stack.

src/vm/vecmap.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ impl<K: Eq + Hash, V, S: BuildHasher + Default> VecMap<K, V, S> {
7171
Self::Map(map) => map.len(),
7272
}
7373
}
74+
75+
pub fn is_empty(&self) -> bool {
76+
self.len() == 0
77+
}
7478
}
7579

7680
pub enum VecMapIter<'a, K, V> {

0 commit comments

Comments
 (0)