Skip to content

Commit

Permalink
Move decl.read_only to generative check phase
Browse files Browse the repository at this point in the history
  • Loading branch information
VonTum committed Feb 12, 2024
1 parent 8a8527d commit 2b98e88
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 25 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ The main goals of the language are roughly listed below:
- [ ] Incremental Compilation
- [ ] Multi-Threaded Compilation

### Type and Bound Checking
### Safety
- [x] Basic Type Checking (bools, ints, arrays, etc)
- [ ] Types for Interfaces
- [ ] Integer and Array Bounds Checking
- [ ] Conflicting assignments (such as calling the same module twice in a single cycle, multiple assignments to a single variable)

### Latency Counting
- [x] Basic latency assignment algorithm
Expand Down
8 changes: 4 additions & 4 deletions multiply_add.sus
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ module blur2 :


module Tree_Multiply : int[4] values -> int total {
int a = values[0] * values[1];
int b = values[2] * values[3];
total = a * b;
reg int a = values[0] * values[1];
reg int b = values[2] * values[3];
reg total = a * b;
}


Expand All @@ -272,7 +272,7 @@ module Accumulator : int term, bool done -> int total {

int new_tot = tot + term;
if done {
total = new_tot;
reg total = new_tot;
tot = 0; // Must restore initial conditions
} else {
tot = new_tot;
Expand Down
1 change: 0 additions & 1 deletion src/dev_aid/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ fn get_semantic_token_type_from_ide_token(tok : &IDEToken) -> u32 {
IDETokenType::Comment => 0,
IDETokenType::Keyword => 1,
IDETokenType::Operator => 2,
IDETokenType::TimelineStage => 8,// EVENT seems to get a good colour
IDETokenType::Identifier(IDEIdentifierType::Value(IdentifierType::Input)) => 4,
IDETokenType::Identifier(IDEIdentifierType::Value(IdentifierType::Output)) => 4,
IDETokenType::Identifier(IDEIdentifierType::Value(IdentifierType::State)) => 3,
Expand Down
8 changes: 1 addition & 7 deletions src/dev_aid/syntax_highlighting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub enum IDETokenType {
Comment,
Keyword,
Operator,
TimelineStage,
Identifier(IDEIdentifierType),
Number,
Invalid,
Expand Down Expand Up @@ -68,7 +67,6 @@ fn pretty_print(file_text : &str, tokens : &TokenizeResult, ide_infos : &[IDETok
IDETokenType::Comment => Style::new().green().dim(),
IDETokenType::Keyword => Style::new().blue(),
IDETokenType::Operator => Style::new().white().bright(),
IDETokenType::TimelineStage => Style::new().red().bold(),
IDETokenType::Identifier(IDEIdentifierType::Unknown) => Style::new().red().underlined(),
IDETokenType::Identifier(IDEIdentifierType::Value(IdentifierType::Local)) => Style::new().blue().bright(),
IDETokenType::Identifier(IDEIdentifierType::Value(IdentifierType::State)) => Style::new().blue().bright().underlined(),
Expand Down Expand Up @@ -168,11 +166,7 @@ pub fn create_token_ide_info<'a>(parsed: &FileData, linker : &Linker) -> Vec<IDE
} else if is_bracket(tok_typ) != IsBracket::NotABracket {
IDETokenType::InvalidBracket // Brackets are initially invalid. They should be overwritten by the token_hierarchy step. The ones that don't get overwritten are invalid
} else if is_symbol(tok_typ) {
if tok_typ == kw("#") {
IDETokenType::TimelineStage
} else {
IDETokenType::Operator
}
IDETokenType::Operator
} else if tok_typ == TOKEN_IDENTIFIER {
IDETokenType::Identifier(IDEIdentifierType::Unknown)
} else if tok_typ == TOKEN_NUMBER {
Expand Down
12 changes: 6 additions & 6 deletions src/flattening/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,13 +430,8 @@ impl<'prev, 'inst, 'l, 'runtime> FlatteningContext<'prev, 'inst, 'l, 'runtime> {
match expr {
Expression::Named(local_idx) => {
let root = self.resolve_identifier(local_idx).expect_local("assignments")?;
let decl = self.instructions[root].extract_wire_declaration();

if decl.read_only {
self.errors.error_with_info(span, "Cannot Assign to Read-Only value", vec![decl.make_declared_here(self.errors.file)]);
return None
}
Some(ConnectionWrite{root, path : Vec::new(), span, is_declared_in_this_module : self.is_declared_in_this_module,})
Some(ConnectionWrite{root, path : Vec::new(), span, is_declared_in_this_module : self.is_declared_in_this_module})
}
Expression::Array(arr_box) => {
let (arr, idx_expr, _bracket_span) = arr_box.deref();
Expand Down Expand Up @@ -746,6 +741,11 @@ impl<'prev, 'inst, 'l, 'runtime> FlatteningContext<'prev, 'inst, 'l, 'runtime> {
}
Instruction::Write(conn) => {
let decl = self.instructions[conn.to.root].extract_wire_declaration();

if decl.read_only {
self.errors.error_with_info(conn.to.span, "Cannot Assign to Read-Only value", vec![decl.make_declared_here(self.errors.file)]);
}

let from_wire = self.instructions[conn.from].extract_wire();
match conn.write_type {
WriteType::Connection{num_regs : _, regs_span : _} => {
Expand Down
4 changes: 0 additions & 4 deletions src/instantiation/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,6 @@ impl<'fl, 'l> InstantiationContext<'fl, 'l> {
Instruction::Declaration(wire_decl) => {
let typ = self.concretize_type(&wire_decl.typ, wire_decl.typ_expr.get_span())?;
if wire_decl.identifier_type.is_generative() {
/*Do nothing (in fact re-initializes the wire to 'empty'), just corresponds to wire declaration*/
/*if wire_decl.read_only { // Don't know why this check is *here*
todo!("Modules can't be computed at compile time yet");
}*/
let initial_value = typ.get_initial_val(self.linker);
assert!(initial_value.is_of_type(&typ));
SubModuleOrWire::CompileTimeValue(initial_value)
Expand Down
4 changes: 2 additions & 2 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ impl<'file> ASTParserContext<'file> {
let (for_block, for_block_span) = self.eat_block(token_stream, kw("{"), "Block of for loop")?;
let code = self.parse_code_block(for_block, for_block_span);

Some((Statement::For{var, range, code}, Span(for_token.tok_idx, for_block_span.1)))
Some((Statement::For{var, range, code}, Span::new_extend_before(for_token.tok_idx, for_block_span)))
}

fn parse_code_block(&mut self, block_tokens : &[TokenTreeNode], span : Span) -> CodeBlock {
Expand Down Expand Up @@ -678,7 +678,7 @@ impl<'file> ASTParserContext<'file> {

let code = self.parse_code_block(block_tokens, block_span);

let span = Span(declaration_start_idx, token_stream.last_idx);
let span = Span::new_across_tokens(declaration_start_idx, token_stream.last_idx);

let link_info = LinkInfo{
file : self.errors.file,
Expand Down

0 comments on commit 2b98e88

Please sign in to comment.