Skip to content

Commit

Permalink
Merge pull request #2 from Rigidity/dependency-graph
Browse files Browse the repository at this point in the history
Rework dependency graph
  • Loading branch information
Rigidity authored Apr 19, 2024
2 parents e8e6625 + 720bb23 commit b5e97a6
Show file tree
Hide file tree
Showing 21 changed files with 947 additions and 477 deletions.
10 changes: 8 additions & 2 deletions crates/rue-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,27 @@ fn main() {
let output = compile(&mut allocator, ast, errors.is_empty());

if !output.diagnostics().is_empty() {
let mut has_error = false;

for error in output.diagnostics() {
let LineCol { line, col } = line_col(&source, error.span().start);
let line = line + 1;
let col = col + 1;

match error.kind() {
DiagnosticKind::Error(kind) => {
has_error = true;
eprintln!("Error: {} at {line}:{col}", kind)
}
DiagnosticKind::Warning(kind) => {
eprintln!("Warning: {} at {line}:{col}", kind)
}
}
}
return;

if has_error {
return;
}
}

let bytes = node_to_bytes(&allocator, output.node_ptr()).unwrap();
Expand All @@ -57,7 +63,7 @@ fn main() {
NodePtr::NIL,
0,
) {
Ok(output) => println!(
Ok(output) => eprintln!(
"Serialized output: {}",
hex::encode(node_to_bytes(&allocator, output.1).unwrap())
),
Expand Down
33 changes: 4 additions & 29 deletions crates/rue-compiler/src/database.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use std::collections::HashMap;

use id_arena::{Arena, Id};
use rue_parser::SyntaxToken;

use crate::{hir::Hir, lir::Lir, scope::Scope, symbol::Symbol, ty::Type};

Expand All @@ -27,33 +24,19 @@ pub struct Database {
types: Arena<Type>,
hir: Arena<Hir>,
lir: Arena<Lir>,
symbol_tokens: HashMap<SymbolId, SyntaxToken>,
type_tokens: HashMap<TypeId, SyntaxToken>,
}

impl Database {
pub(crate) fn alloc_scope(&mut self, scope: Scope) -> ScopeId {
ScopeId(self.scopes.alloc(scope))
}

pub(crate) fn alloc_symbol(&mut self, symbol: Symbol, token: Option<SyntaxToken>) -> SymbolId {
let id = SymbolId(self.symbols.alloc(symbol));

if let Some(token) = token {
self.symbol_tokens.insert(id, token);
}

id
pub(crate) fn alloc_symbol(&mut self, symbol: Symbol) -> SymbolId {
SymbolId(self.symbols.alloc(symbol))
}

pub(crate) fn alloc_type(&mut self, ty: Type, token: Option<SyntaxToken>) -> TypeId {
let id = TypeId(self.types.alloc(ty));

if let Some(token) = token {
self.type_tokens.insert(id, token);
}

id
pub(crate) fn alloc_type(&mut self, ty: Type) -> TypeId {
TypeId(self.types.alloc(ty))
}

pub(crate) fn alloc_hir(&mut self, hir: Hir) -> HirId {
Expand All @@ -72,10 +55,6 @@ impl Database {
&self.symbols[id.0]
}

pub fn symbol_token(&self, id: SymbolId) -> Option<SyntaxToken> {
self.symbol_tokens.get(&id).cloned()
}

pub fn ty_raw(&self, id: TypeId) -> &Type {
&self.types[id.0]
}
Expand All @@ -87,10 +66,6 @@ impl Database {
self.ty_raw(id)
}

pub fn type_token(&self, id: TypeId) -> Option<SyntaxToken> {
self.type_tokens.get(&id).cloned()
}

pub(crate) fn ty_mut(&mut self, id: TypeId) -> &mut Type {
&mut self.types[id.0]
}
Expand Down
Loading

0 comments on commit b5e97a6

Please sign in to comment.