Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
9fbd359
initial stub implementation of match statements
arihant2math Jan 19, 2025
bfb4091
formatting
arihant2math Jan 19, 2025
c021326
solved compilation errors
arihant2math Jan 20, 2025
6c7a543
almost working
arihant2math Jan 20, 2025
8617786
formatting
arihant2math Jan 20, 2025
a01240f
as and * support for switch case
arihant2math Jan 20, 2025
d8c4cff
replace todos with errors
arihant2math Jan 20, 2025
aaccadb
fix compile
arihant2math Jan 20, 2025
f9d2418
added Noop instruction
arihant2math Jan 20, 2025
5839dfd
finished default for switch case
arihant2math Jan 20, 2025
40e380e
fix compile
arihant2math Jan 20, 2025
8af2c42
formatting
arihant2math Jan 20, 2025
0774cbd
more implementation
arihant2math Jan 20, 2025
cd0f1cf
rename codegen_* to compile_*
arihant2math Jan 21, 2025
223fbe4
implement SWAP instruction
arihant2math Jan 21, 2025
4ef2a50
applied fix
youknowone Jan 21, 2025
aa6a040
enabled IR debug and attempted to fix codegen
arihant2math Jan 22, 2025
822d565
formatting
arihant2math Jan 22, 2025
ad164c0
basic match statement working
arihant2math Jan 22, 2025
e955ede
basic match statement working
arihant2math Jan 22, 2025
4649898
working as pattern (default works too by extension)
arihant2math Jan 23, 2025
493fc6e
fix rust tests
arihant2math Jan 23, 2025
fe7f8a3
cleanup
arihant2math Jan 23, 2025
805757a
fix clippy errors
arihant2math Jan 23, 2025
b176f9c
formatting
arihant2math Jan 23, 2025
8e78c6d
trivial edits
youknowone Jan 25, 2025
4beef2c
Remove currently unused Nop,Swap op
youknowone Jan 25, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
enabled IR debug and attempted to fix codegen
Signed-off-by: Ashwin Naren <arihant2math@gmail.com>
  • Loading branch information
arihant2math committed Jan 22, 2025
commit aa6a0409666b427a1364e8d61b78cd3527562e55
18 changes: 16 additions & 2 deletions compiler/codegen/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2054,7 +2054,7 @@ impl Compiler {
) -> CompileResult<()> {
self.compile_expression(subject)?;
// Block at the end of the switch statement that we jump to after finishing a branch
let pattern_blocks = std::iter::repeat_with(|| self.new_block())
let mut pattern_blocks = std::iter::repeat_with(|| self.new_block())
.take(cases.len() + 1)
.collect::<Vec<_>>();
eprintln!("created pattern_blocks: {:?} - {:?}(end block)", pattern_blocks.first().unwrap(), pattern_blocks.last().unwrap());
Expand Down Expand Up @@ -2118,7 +2118,21 @@ impl Compiler {
}
self.compile_statements(&m.body)?;
}

let block = self.new_block();
pattern_blocks.push(block);
let code = self.current_code_info();
let _ = pattern_blocks.iter()
.zip(pattern_blocks.iter().skip(1))
.for_each(|(a, b)| {
eprintln!("linking: {} -> {}", a.0, b.0);
code.blocks[a.0 as usize].next = *b;
});
self.switch_to_block(*pattern_blocks.last().unwrap());
let code = self.current_code_info();
for block in pattern_blocks {
let b = &code.blocks[block.0 as usize];
eprintln!("block: {} -> {}", block.0, b.next.0);
}
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/codegen/src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ impl CodeInfo {
let mut start_depths = vec![u32::MAX; self.blocks.len()];
start_depths[0] = 0;
stack.push(BlockIdx(0));
const DEBUG: bool = false;
const DEBUG: bool = true;
'process_blocks: while let Some(block) = stack.pop() {
let mut depth = start_depths[block.idx()];
if DEBUG {
Expand Down