Skip to content

Commit

Permalink
Use newer parser and licence update
Browse files Browse the repository at this point in the history
  • Loading branch information
VonTum committed Apr 20, 2024
1 parent cd7eec7 commit 8490a4d
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "sus_compiler"
version = "0.0.1"
authors = ["VonTum <[email protected]>"]
edition = "2021"
license = "GPL-3.0-or-later"
repository = "https://github.com/pc2/sus-compiler"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
30 changes: 27 additions & 3 deletions multiply_add.sus
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ module b: HandShake hs -> {
}
}


module example_md :
int[4] factors,
int add_to ->
Expand Down Expand Up @@ -368,6 +367,7 @@ module first_bit_idx_6 : bool[6] bits -> int first, bool all_zeros {

}


module multiply_add_with_latencies : int a'0, int b'0, int c'0 -> int r'0 {
int tmp'1 = multiply(a, b)
reg r = tmp + c
Expand Down Expand Up @@ -479,7 +479,7 @@ module bad_cycle : int a -> int r {

r = new_test
}

module test {}
module module_taking_time :
int i'0 -> int o'5 {
o = i
Expand All @@ -499,7 +499,6 @@ module module_taking_a_lot_of_time : int data_in'0 -> int data_out'200 {
}



/*extern*/ module offset_latency : int i'0 -> int o'-5 {

}
Expand Down Expand Up @@ -542,3 +541,28 @@ module multiple_outputs_only : -> int o, int o2 {
reg o = loop
reg reg o2 = loop
}


// Test submodule comment
module submodule : int a, int b -> int r {
r = a * b
}

// module doing nothing
module doNothing {}

/*
Multiline

comment

# Test Title

*/
module contains_submodule_submodule : int a, int b, int c -> int r {
// Temp val
int tmp = submodule(a, b)
doNothing()
reg r = tmp + c
}

31 changes: 31 additions & 0 deletions src/flattening/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,17 @@ impl<'l> FlatteningContext<'l> {
WireSource::Constant(Value::Error)
} else if kind == kind!("parenthesis_expression") {
return cursor.go_down_content(kind!("parenthesis_expression"), |cursor| self.flatten_expr(cursor));
} else if kind == kind!("field_access") {
cursor.go_down_no_check(|cursor| {
cursor.field(field!("left"));
if let Some(instr_id) = self.get_module_by_global_identifier(cursor) {
let submodule = self.instructions[instr_id].extract_submodule();

//submodule.module_uuid
}
});
println!("TODO: Field access");
WireSource::Constant(Value::Error)
} else {
cursor.could_not_match();
};
Expand Down Expand Up @@ -751,6 +762,20 @@ impl<'l> FlatteningContext<'l> {

Some(flattened_arr_expr)
})
} else if kind == kind!("field_access") {
cursor.go_down_no_check(|cursor| {
cursor.field(field!("left"));
let flattened_arr_expr_opt = self.flatten_assignable_expr(write_modifiers, cursor);

cursor.field(field!("name"));
//let (idx, bracket_span) = self.flatten_array_bracket(cursor);

//let mut flattened_arr_expr = flattened_arr_expr_opt?; // only unpack the subexpr after flattening the idx, so we catch all errors

println!("TODO: Field access in assign");

return None
})
} else if kind == kind!("number") {self.errors.error_basic(span, "Cannot assign to constant"); None
} else if kind == kind!("unary_op") {self.errors.error_basic(span, "Cannot assign to the result of an operator"); None
} else if kind == kind!("binary_op") {self.errors.error_basic(span, "Cannot assign to the result of an operator"); None
Expand Down Expand Up @@ -896,6 +921,12 @@ impl<'l> FlatteningContext<'l> {

for_stmt.loop_body = UUIDRange(code_start, code_end);
})
} else if kind == kind!("interface_statement") {
println!("TODO: Interface Statement");
} else if kind == kind!("cross_statement") {
println!("TODO: Cross Statement");
} else {
cursor.could_not_match()
}
cursor.clear_gathered_comments(); // Clear comments after every statement, so comments don't bleed over
});
Expand Down
2 changes: 2 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ fn print_current_node_indented(file_text : &FileText, cursor : &TreeCursor) -> S
let cursor_span = Span::from(n.byte_range());
let node_name = if n.kind_id() == kind!("identifier") {
format!("\"{}\"", &file_text[cursor_span])
} else if n.kind_id() == kw!("\n") {
"\\n".to_owned()
} else {
n.kind().to_owned()
};
Expand Down
7 changes: 7 additions & 0 deletions tinyTestFile.sus
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@

module submodule_fifo : int i -> int o {
o = i
}

module fifo {
interface a

submodule_fifo sf

sf.i = 4

}

2 changes: 1 addition & 1 deletion tree-sitter-sus
Submodule tree-sitter-sus updated 6 files
+2 −2 Cargo.toml
+674 −0 LICENSE
+52 −17 grammar.js
+156 −22 src/grammar.json
+176 −0 src/node-types.json
+2,348 −2,101 src/parser.c

0 comments on commit 8490a4d

Please sign in to comment.