Skip to content

Commit

Permalink
Add wait and post
Browse files Browse the repository at this point in the history
  • Loading branch information
leonidas1712 committed Apr 18, 2024
1 parent 0760cfb commit 14a1189
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
13 changes: 11 additions & 2 deletions compiler/oxidate/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,17 @@ impl Compiler {
// push RESET
arr.push(ByteCode::RESET(bytecode::FrameType::CallFrame))
}
Decl::WaitStmt(_) => {}
Decl::PostStmt(_) => {}
// These don't return anything, so push unit after as well
Decl::WaitStmt(sem) => {
arr.push(ByteCode::ld(sem));
arr.push(ByteCode::WAIT);
arr.push(ByteCode::ldc(Value::Unit));
}
Decl::PostStmt(sem) => {
arr.push(ByteCode::ld(sem));
arr.push(ByteCode::POST);
arr.push(ByteCode::ldc(Value::Unit));
}
};

Ok(())
Expand Down
10 changes: 10 additions & 0 deletions compiler/oxidate/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1162,4 +1162,14 @@ mod tests {
],
);
}

#[test]
fn test_compile_wait_post() {
let t = r"
wait sem;
2;
post sem;
";
// test_comp(t, vec![]);
}
}
2 changes: 2 additions & 0 deletions example/concurrency-03.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Expected: inconsistent count on each run due to race on count

let count = 0;

fn increment(times: int) {
Expand Down
2 changes: 2 additions & 0 deletions example/concurrency-04.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Expected: count = 3000 on each run

let count = 0;
let sem = sem_create();

Expand Down

0 comments on commit 14a1189

Please sign in to comment.