Skip to content

Commit

Permalink
implement rebase_stack, stop popping so much!
Browse files Browse the repository at this point in the history
  • Loading branch information
drewrip committed May 1, 2024
1 parent 731c16b commit faaa339
Show file tree
Hide file tree
Showing 3 changed files with 590 additions and 409 deletions.
14 changes: 7 additions & 7 deletions src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ pub type Block = Vec<Arc<Stmt>>;

#[derive(Debug, Clone)]
pub struct Frame {
pub progress: i32,
pub total: i32,
pub progress: usize,
pub total: usize,
pub checked: bool,
pub node: Node,
pub type_t: types::Type,
}

pub fn new_frame(node: Node, type_t: types::Type, total: i32, checked: bool) -> Frame {
pub fn new_frame(node: Node, type_t: types::Type, total: usize, checked: bool) -> Frame {
Frame {
progress: 0,
total,
Expand All @@ -26,23 +26,23 @@ pub fn new_frame(node: Node, type_t: types::Type, total: i32, checked: bool) ->
}

impl Frame {
pub fn get_prog(&self) -> i32 {
pub fn get_prog(&self) -> usize {
self.progress
}

pub fn set_prog(&mut self, progress: i32) {
pub fn set_prog(&mut self, progress: usize) {
self.progress = progress;
}

pub fn inc_prog(&mut self) {
self.progress += 1;
}

pub fn get_total(&self) -> i32 {
pub fn get_total(&self) -> usize {
self.total
}

pub fn set_total(&mut self, total: i32) {
pub fn set_total(&mut self, total: usize) {
self.total = total;
}

Expand Down
47 changes: 47 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ fn type_checking_passing1() {
let mut state = semantic::new_state(root);
// Perform semantic checks and type checking
let build_res = state.build();

assert!(build_res.is_ok());
}

#[test]
fn type_checking_passing2() {
let source = r#"
Expand All @@ -99,3 +101,48 @@ fn type_checking_passing2() {
let build_res = state.build();
assert!(build_res.is_ok());
}

#[test]
#[should_panic]
fn type_checking_func_failing1() {
let source = r#"
function foo(a: int32, b: float32) -> float32
let c = a;
let d = b;
end
program passing1
let x: int32 = 431;
let test = foo(x, x);
end
"#;
let root = rascal_grammar::RootParser::new().parse(source).unwrap();
let mut state = semantic::new_state(root);
// Perform semantic checks and type checking
let build_res = state.build();
}

fn type_checking_ifs_passing1() {
let source = r#"
let x = 4;
program test_if
if x == 4 then
let y = 2;
end
if x == 5 then
x = 10;
else if x == 6 then
x = 11;
else then
x = 12;
end
end
"#;
let root = rascal_grammar::RootParser::new().parse(source).unwrap();
let mut state = semantic::new_state(root);
// Perform semantic checks and type checking
let build_res = state.build();
assert!(build_res.is_ok());
}
Loading

0 comments on commit faaa339

Please sign in to comment.