Skip to content

Commit

Permalink
Update tokenizer and parser for updated Errors
Browse files Browse the repository at this point in the history
  • Loading branch information
VonTum committed Jan 9, 2024
1 parent 349b400 commit c64e01f
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 67 deletions.
13 changes: 7 additions & 6 deletions multiply_add.sus
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,12 @@ module generative : int i -> int o, int o2 {
o2 = a[a[0]];
}

module add_stuff_to_indices : int[10] values -> int[10] added_values {
for int i in 0..10 {
added_values[i] = values[i] + i;
}
}


//timeline (bs -> /, true) | (bs -> v, false)
module first_bit_idx_6 : bool[6] bits -> int first, bool all_zeros {
Expand Down Expand Up @@ -354,12 +360,6 @@ module first_bit_idx_6 : bool[6] bits -> int first, bool all_zeros {

}

module add_stuff_to_indices : int[10] values -> int[10] added_values {
for int i in 0..10 {
added_values[i] = values[i] + i;
}
}

module first_bit_idx_24 : bool[24] bits -> int first {
int[4] offsets;
bool[4] was_nonzeros;
Expand All @@ -369,6 +369,7 @@ module first_bit_idx_24 : bool[24] bits -> int first {
for int j in 0..6 {
these_bits[j] = bits[i * 6 + j];
}

int offset, bool was_nonzero = first_bit_idx_6(these_bits);
offsets[i] = offset;
was_nonzeros[i] = was_nonzero;
Expand Down
5 changes: 3 additions & 2 deletions src/ast.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


use crate::{tokenizer::{TokenTypeIdx, get_token_type_name}, linker::{NamedUUID, FileUUID}, flattening::FlattenedModule, arena_alloc::{UUIDMarker, UUID, FlatAlloc}, instantiation::InstantiationList, value::Value};
use crate::{tokenizer::{TokenTypeIdx, get_token_type_name}, linker::{NamedUUID, FileUUID}, flattening::FlattenedModule, arena_alloc::{UUIDMarker, UUID, FlatAlloc}, instantiation::InstantiationList, value::Value, errors::ErrorCollector};
use core::ops::Range;
use std::fmt::Display;

Expand Down Expand Up @@ -185,5 +185,6 @@ pub struct GlobalReference(pub Span, pub Option<NamedUUID>); // token index, and

#[derive(Debug)]
pub struct ASTRoot {
pub modules : Vec<Module>
pub modules : Vec<Module>,
pub errors : ErrorCollector
}
10 changes: 5 additions & 5 deletions src/dev_aid/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ impl LoadedFileCache {
let found_opt = self.find_uri(&uri);
let found_opt_was_none = found_opt.is_none();
let file_uuid : FileUUID = found_opt.unwrap_or_else(|| self.linker.reserve_file());
let (full_parse, parsing_errors) = perform_full_semantic_parse(new_file_text, file_uuid);
let full_parse = perform_full_semantic_parse(new_file_text, file_uuid);

if found_opt_was_none {
self.linker.add_reserved_file(file_uuid, full_parse, parsing_errors);
self.linker.add_reserved_file(file_uuid, full_parse);
self.uris.insert(file_uuid, uri.clone());
} else {
self.linker.relink(file_uuid, full_parse, parsing_errors);
self.linker.relink(file_uuid, full_parse);
}
self.linker.recompile_all();
}
Expand All @@ -44,8 +44,8 @@ impl LoadedFileCache {
} else {
let file_uuid = self.linker.reserve_file();
let file_text = std::fs::read_to_string(uri.to_file_path().unwrap()).unwrap();
let (full_parse, parsing_errors) = perform_full_semantic_parse(file_text, file_uuid);
self.linker.add_reserved_file(file_uuid, full_parse, parsing_errors);
let full_parse = perform_full_semantic_parse(file_text, file_uuid);
self.linker.add_reserved_file(file_uuid, full_parse);
self.uris.insert(file_uuid, uri.clone());
self.linker.recompile_all();
file_uuid
Expand Down
4 changes: 2 additions & 2 deletions src/dev_aid/syntax_highlighting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,11 @@ pub fn compile_all(file_paths : Vec<PathBuf>) -> (Linker, ArenaVector<PathBuf, F
}
};

let (full_parse, errors) = perform_full_semantic_parse(file_text, uuid);
let full_parse = perform_full_semantic_parse(file_text, uuid);

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

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

Expand Down
12 changes: 6 additions & 6 deletions src/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,15 @@ impl PreLinker {
pub fn reserve_file(&mut self) -> FileUUID {
self.files.reserve()
}
pub fn add_reserved_file(&mut self, file : FileUUID, parse_result : FullParseResult, parsing_errors : ErrorCollector) {
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, associated_values});
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
Expand Down Expand Up @@ -432,15 +432,15 @@ impl Linker {
self.files.reserve()
}

pub fn add_reserved_file(&mut self, file : FileUUID, parse_result : FullParseResult, parsing_errors : ErrorCollector) {
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, associated_values});
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});

for (_uuid, val_in_file) in &mut self.links.globals {
if let Some(link_info) = val_in_file.get_link_info_mut() {
Expand All @@ -452,10 +452,10 @@ impl Linker {
}
}

pub fn relink(&mut self, file : FileUUID, parse_result : FullParseResult, parsing_errors : ErrorCollector) {
pub fn relink(&mut self, file : FileUUID, parse_result : FullParseResult) {
self.remove_file_datas(&[file]);
self.files.revert_to_reservation(file);
self.add_reserved_file(file, parse_result, parsing_errors);
self.add_reserved_file(file, parse_result);
}

pub fn get_module(&self, uuid : NamedUUID) -> &Module {
Expand Down
Loading

0 comments on commit c64e01f

Please sign in to comment.