Skip to content

Commit 59d753d

Browse files
committed
Added new statement (assert_eq)
- For issue #5, so transaction arguments can remain constant within body - Implemented Serializability - Implemented Type Checking - Updated add_struct test case
1 parent 2ebba96 commit 59d753d

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

src/ir.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ pub enum Stmt {
179179
Fork,
180180
While(ExprId, StmtId),
181181
IfElse(ExprId, StmtId, StmtId),
182+
AssertEq(ExprId, ExprId),
182183
}
183184

184185
#[derive(Clone, Copy, Hash, PartialEq, Eq, Default)]

src/serialize.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ fn build_statements(
9090
build_statements(out, tr, st, elsebody, index + 1)?;
9191
writeln!(out, "{}}}", " ".repeat(index))?;
9292
}
93+
Stmt::AssertEq(exprid1, exprid2) => {
94+
writeln!(
95+
out,
96+
"{}assert_eq({}, {});",
97+
" ".repeat(index),
98+
serialize_expr(tr, st, exprid1),
99+
serialize_expr(tr, st, exprid2)
100+
)?;
101+
}
93102
}
94103

95104
Ok(())
@@ -228,6 +237,7 @@ pub mod tests {
228237
add.add_expr_loc(b_expr, 208, 209, add_fileid);
229238
let dut_s_expr = add.e(Expr::Sym(dut_s));
230239
add.add_expr_loc(dut_s_expr, 271, 276, add_fileid);
240+
let s_expr = add.e(Expr::Sym(s));
231241

232242
// 4) create statements
233243
let a_assign = add.s(Stmt::Assign(dut_a, a_expr));
@@ -246,6 +256,8 @@ pub mod tests {
246256
add.add_stmt_loc(s_assign, 266, 277, add_fileid);
247257
let dut_s_assign = add.s(Stmt::Assign(dut_s, a_expr));
248258
add.add_stmt_loc(dut_s_assign, 281, 292, add_fileid);
259+
let assert = add.s(Stmt::AssertEq(s_expr, dut_s_expr));
260+
add.add_stmt_loc(assert, 296, 316, add_fileid);
249261
let body = vec![
250262
a_assign,
251263
b_assign,
@@ -255,6 +267,7 @@ pub mod tests {
255267
dut_b_assign,
256268
s_assign,
257269
dut_s_assign,
270+
assert,
258271
];
259272
add.body = add.s(Stmt::Block(body));
260273

src/typecheck.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,26 @@ fn check_stmt_types(
148148
Ok(())
149149
}
150150
}
151+
Stmt::AssertEq(exprid1, exprid2) => {
152+
let expr1_type = check_expr_types(tr, st, handler, exprid1)?;
153+
let expr2_type = check_expr_types(tr, st, handler, exprid2)?;
154+
if expr1_type.is_equivalent(&expr2_type) {
155+
Ok(())
156+
} else {
157+
let expr1_name = serialize_expr(tr, st, exprid1);
158+
let expr2_name = serialize_expr(tr, st, exprid2);
159+
handler.emit_diagnostic_stmt(
160+
tr,
161+
stmt_id,
162+
&format!(
163+
"Type mismatch in assert_eq: {} : {:?} and {} : {:?}.",
164+
expr1_name, expr1_type, expr2_name, expr2_type,
165+
),
166+
Level::Error,
167+
);
168+
Ok(())
169+
}
170+
}
151171
Stmt::Block(stmts) => {
152172
for stmtid in stmts {
153173
check_stmt_types(tr, st, handler, stmtid)?;

tests/addStruct.prot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ fn add<DUT: Adder>(in a: u32, in b: u32, out s: u32) {
1414
DUT.b := X;
1515
s := DUT.s;
1616
DUT.s := a;
17+
assert_eq(s, DUT.s);
1718
}

0 commit comments

Comments
 (0)