Skip to content

Commit

Permalink
Removed PreLinker
Browse files Browse the repository at this point in the history
  • Loading branch information
VonTum committed Jan 10, 2024
1 parent 52ccf80 commit 5cc7f65
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 55 deletions.
5 changes: 2 additions & 3 deletions src/dev_aid/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use lsp_server::{Response, Message, Connection};

use lsp_types::notification::Notification;

use crate::{parser::perform_full_semantic_parse, dev_aid::syntax_highlighting::create_token_ide_info, ast::{IdentifierType, Span}, errors::{ErrorCollector, CompileError, ErrorLevel}, linker::{PreLinker, FileUUIDMarker, Linker, FileUUID, FileData, Links}, arena_alloc::ArenaVector};
use crate::{parser::perform_full_semantic_parse, dev_aid::syntax_highlighting::create_token_ide_info, ast::{IdentifierType, Span}, errors::{ErrorCollector, CompileError, ErrorLevel}, linker::{FileUUIDMarker, Linker, FileUUID, FileData, Links}, arena_alloc::ArenaVector};

use super::syntax_highlighting::{IDETokenType, IDEIdentifierType, IDEToken};

Expand Down Expand Up @@ -299,8 +299,7 @@ fn main_loop(
params: serde_json::Value,
) -> Result<(), Box<dyn Error + Sync + Send>> {

let prelinker = PreLinker::new();
let mut file_cache = LoadedFileCache::new(prelinker.link(), ArenaVector::new());
let mut file_cache = LoadedFileCache::new(Linker::new(), ArenaVector::new());

let _params: InitializeParams = serde_json::from_value(params).unwrap();
println!("starting LSP main loop");
Expand Down
10 changes: 4 additions & 6 deletions src/dev_aid/syntax_highlighting.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

use std::{ops::Range, path::PathBuf};

use crate::{ast::*, tokenizer::*, parser::*, linker::{PreLinker, FileData, Links, NamedUUID, Named, Linkable, Linker, FileUUIDMarker, FileUUID}, arena_alloc::ArenaVector, flattening::{Instantiation, WireSource}};
use crate::{ast::*, tokenizer::*, parser::*, linker::{FileData, Links, NamedUUID, Named, Linkable, Linker, FileUUIDMarker, FileUUID}, arena_alloc::ArenaVector, flattening::{Instantiation, WireSource}};

use ariadne::FileCache;
use console::Style;
Expand Down Expand Up @@ -226,10 +226,10 @@ fn generate_character_offsets(file_text : &str, tokens : &[Token]) -> Vec<Range<
}

pub fn compile_all(file_paths : Vec<PathBuf>) -> (Linker, ArenaVector<PathBuf, FileUUIDMarker>) {
let mut prelinker : PreLinker = PreLinker::new();
let mut linker = Linker::new();
let mut paths_arena = ArenaVector::new();
for file_path in file_paths {
let uuid = prelinker.reserve_file();
let uuid = linker.reserve_file();
let file_text = match std::fs::read_to_string(&file_path) {
Ok(file_text) => file_text,
Err(reason) => {
Expand All @@ -242,12 +242,10 @@ pub fn compile_all(file_paths : Vec<PathBuf>) -> (Linker, ArenaVector<PathBuf, F

println!("{:?}", full_parse.ast);

prelinker.add_reserved_file(uuid, full_parse);
linker.add_reserved_file(uuid, full_parse);
paths_arena.insert(uuid, file_path);
}

let mut linker = prelinker.link();

linker.recompile_all();

(linker, paths_arena)
Expand Down
2 changes: 1 addition & 1 deletion src/flattening.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ impl<'inst, 'l, 'm> FlatteningContext<'inst, 'l, 'm> {
if_stmt.else_end = else_end;
}
Statement::For{var : decl_id, range, code} => {
let loop_var_decl = self.flatten_declaration::<false>(*decl_id, false);
let loop_var_decl = self.flatten_declaration::<false>(*decl_id, true);

let start = self.flatten_expr(&range.from);
let end = self.flatten_expr(&range.to);
Expand Down
40 changes: 3 additions & 37 deletions src/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,43 +253,6 @@ impl IndexMut<NamedUUID> for Links {
}
}

// This is a class that efficiently collects all files when initially starting, and links them together once all are present.
// Converts to a proper Linker using self.link()
pub struct PreLinker {
links : Links,
files : ArenaAllocator<FileData, FileUUIDMarker>
}

impl PreLinker {
pub fn new() -> PreLinker {
PreLinker { links: Links::new(), files: ArenaAllocator::new() }
}
pub fn reserve_file(&mut self) -> FileUUID {
self.files.reserve()
}
pub fn add_reserved_file(&mut self, file : FileUUID, parse_result : FullParseResult) {
let mut associated_values = Vec::new();
for md in parse_result.ast.modules {
let module_name = md.link_info.name.clone();
let new_module_uuid = self.links.globals.alloc(Named::Module(md));
associated_values.push(new_module_uuid);
self.links.add_name(module_name, new_module_uuid);
}
self.files.alloc_reservation(file, FileData{file_text : parse_result.file_text, tokens: parse_result.tokens, token_hierarchy: parse_result.token_hierarchy, parsing_errors : parse_result.ast.errors, associated_values});
}

// This should be called once all modules have been added. Adds errors for globals it couldn't match
pub fn link(mut self) -> Linker {
for (_file_uuid, file) in &self.files {
for val_in_file in &file.associated_values {
let link_info = self.links.globals[*val_in_file].get_link_info_mut().unwrap();
Links::resolve_dependencies(&self.links.global_namespace, &file, link_info);
}
}
Linker{links: self.links, files : self.files}
}
}

fn add_error(info_a: &LinkInfo, info_b: &LinkInfo, errors: &ErrorCollector) {
let this_object_name = &info_a.name;
errors.error_with_info(info_a.name_span, format!("Conflicting Declaration for the name '{this_object_name}'"), vec![
Expand All @@ -298,6 +261,9 @@ fn add_error(info_a: &LinkInfo, info_b: &LinkInfo, errors: &ErrorCollector) {
}

impl Linker {
pub fn new() -> Linker {
Linker{files : ArenaAllocator::new(), links : Links::new()}
}
fn get_linking_errors(&self, file_uuid : FileUUID, errors : &ErrorCollector) {
let file = &self.files[file_uuid];

Expand Down
8 changes: 0 additions & 8 deletions src/typing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,6 @@ impl Type {
Type::Array(sub) => sub.deref().0.to_string(linker) + "[]",
}
}
pub fn get_root(&self) -> Option<NamedUUID> {
match self {
Type::Error => None,
Type::Unknown => None,
Type::Named(name) => Some(*name),
Type::Array(sub) => sub.0.get_root(),
}
}
pub fn for_each_generative_input<F : FnMut(FlatID)>(&self, f : &mut F) {
match self {
Type::Error => {}
Expand Down

0 comments on commit 5cc7f65

Please sign in to comment.