diff options
Diffstat (limited to 'oryxc/src')
| -rw-r--r-- | oryxc/src/sema/typecheck.rs | 50 | ||||
| -rw-r--r-- | oryxc/src/unistr.rs | 12 |
2 files changed, 34 insertions, 28 deletions
diff --git a/oryxc/src/sema/typecheck.rs b/oryxc/src/sema/typecheck.rs index 5cb37c7..cb963b3 100644 --- a/oryxc/src/sema/typecheck.rs +++ b/oryxc/src/sema/typecheck.rs @@ -18,7 +18,7 @@ pub fn typecheck_multi_def_bind( ) -> Result<(), OryxError> { let ast = fdata.ast.get().unwrap(); let tokens = fdata.tokens.get().unwrap(); - let scope = &fdata.scopes.get().unwrap()[scope_id.into()]; + let scope = &fdata.scopes.get().unwrap()[scope_id.into()]; let SubNodes(decls, exprs) = ast.nodes.sub()[node as usize]; let (decls, exprs) = (decls as usize, exprs as usize); @@ -26,31 +26,33 @@ pub fn typecheck_multi_def_bind( let nexprs = ast.extra[exprs] as usize; /* Mark our identifiers as ‘resolving’ */ - let mut circularp = false; + let mut circularp = false; for i in 0..nidents { let itok = ast.extra[decls + 1 + i * 2] as usize; let view = tokens.view()[itok]; /* Pointer fuckery to bypass the borrow checker */ let s = UniStr(unsafe { &*(&fdata.buffer[view.0..view.1] as *const str) }); - let id = c_state.ident_intr.intern(s); - let mut sym = scope.symtab.get_mut(&id).unwrap(); - match sym.state { - ResolutionState::Unresolved => sym.state = ResolutionState::Resolving, - ResolutionState::Resolving | ResolutionState::Poisoned => { - sym.state = ResolutionState::Poisoned; - circularp = true; - }, - _ => unreachable!(), - } + let id = c_state.ident_intr.intern(s); + let mut sym = scope.symtab.get_mut(&id).unwrap(); + match sym.state { + ResolutionState::Unresolved => { + sym.state = ResolutionState::Resolving + }, + ResolutionState::Resolving | ResolutionState::Poisoned => { + sym.state = ResolutionState::Poisoned; + circularp = true; + }, + _ => unreachable!(), + } } - if circularp { - return Err(OryxError::new( - tokens.view()[ast.nodes.tok()[node as usize] as usize], - format!("circular dependency of multiple symbol definition"), - )); - } + if circularp { + return Err(OryxError::new( + tokens.view()[ast.nodes.tok()[node as usize] as usize], + format!("circular dependency of multiple symbol definition"), + )); + } let mut types = Vec::with_capacity(nexprs); for i in 0..nexprs { @@ -86,8 +88,8 @@ pub fn typecheck_multi_def_bind( let alleged_type = if tnode == u32::MAX { /* Inferred type */ - TypeId::INVALID - } else { + TypeId::INVALID + } else { /* In ‘def a, b int = x, y;’, the type node for A and B are the * same, so we need to make sure we only typecheck once. */ let id = match ast.types[tnode as usize].get() { @@ -120,10 +122,10 @@ pub fn typecheck_multi_def_bind( /* Pointer fuckery to bypass the borrow checker */ let s = UniStr(unsafe { &*(&fdata.buffer[view.0..view.1] as *const str) }); - let id = c_state.ident_intr.intern(s); - let mut sym = scope.symtab.get_mut(&id).unwrap(); - sym.state = ResolutionState::Resolved; - sym.vtype = vtype; + let id = c_state.ident_intr.intern(s); + let mut sym = scope.symtab.get_mut(&id).unwrap(); + sym.state = ResolutionState::Resolved; + sym.vtype = vtype; } return Ok(()); diff --git a/oryxc/src/unistr.rs b/oryxc/src/unistr.rs index 9a204cf..60d2864 100644 --- a/oryxc/src/unistr.rs +++ b/oryxc/src/unistr.rs @@ -1,4 +1,8 @@ -use std::fmt::{self, Display, Formatter}; +use std::fmt::{ + self, + Display, + Formatter, +}; use std::hash::{ Hash, Hasher, @@ -15,9 +19,9 @@ use unicode_normalization::{ pub struct UniStr<'a>(pub &'a str); impl Display for UniStr<'_> { - fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), fmt::Error> { - return self.0.fmt(f); - } + fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), fmt::Error> { + return self.0.fmt(f); + } } impl Hash for UniStr<'_> { |