WARNING! Access to this system is limited to authorised users only.
Unauthorised users may be subject to prosecution.
Unauthorised access to this system is a criminal offence under Australian law (Federal Crimes Act 1914 Part VIA)
It is a criminal offence to:
(1) Obtain access to data without authority. -Penalty 2 years imprisonment.
(2) Damage, delete, alter or insert data without authority. -Penalty 10 years imprisonment.
User activity is monitored and recorded. Anyone using this system expressly consents to such monitoring and recording.

To protect your data, the CISO officer has suggested users to enable 2FA as soon as possible.
Currently 2.7% of users enabled 2FA.

Commit 1ac03aae authored by qinsoon's avatar qinsoon
Browse files

fixed the test. instsel for factorial seems fine

parent d70ebbd5
......@@ -55,6 +55,7 @@ impl MuFunction {
pub fn new_ssa(&mut self, tag: MuTag, ty: P<MuType>) -> P<TreeNode> {
let id = self.get_id();
self.context.value_tags.insert(tag, id);
self.context.values.insert(id, ValueEntry{id: id, tag: tag, ty: ty.clone(), use_count: Cell::new(0), expr: None});
P(TreeNode {
......@@ -119,15 +120,33 @@ impl FunctionContent {
#[derive(Debug)]
pub struct FunctionContext {
pub value_tags: HashMap<MuTag, MuID>,
pub values: HashMap<MuID, ValueEntry>
}
impl FunctionContext {
fn new() -> FunctionContext {
FunctionContext {
value_tags: HashMap::new(),
values: HashMap::new()
}
}
pub fn get_value_by_tag(&self, tag: MuTag) -> Option<&ValueEntry> {
match self.value_tags.get(tag) {
Some(id) => self.get_value(*id),
None => None
}
}
pub fn get_value_mut_by_tag(&mut self, tag: MuTag) -> Option<&mut ValueEntry> {
let id : MuID = match self.value_tags.get(tag) {
Some(id) => *id,
None => return None
};
self.get_value_mut(id)
}
pub fn get_value(&self, id: MuID) -> Option<&ValueEntry> {
self.values.get(&id)
......
......@@ -24,14 +24,13 @@ fn test_use_count() {
compiler.compile(&vm_context, &mut factorial_func);
assert!(factorial_func.context.get_value(0).unwrap().use_count.get() == 2, "blk_0_n_3 use should be 2");
assert!(factorial_func.context.get_value(1).unwrap().use_count.get() == 1, "blk_0_v48 use should be 1");
assert!(factorial_func.context.get_value(2).unwrap().use_count.get() == 1, "blk_2_v53 use should be 1");
assert!(factorial_func.context.get_value(3).unwrap().use_count.get() == 2, "blk_1_n_3 use should be 2");
assert!(factorial_func.context.get_value(4).unwrap().use_count.get() == 1, "blk_1_v50 use should be 1");
assert!(factorial_func.context.get_value(5).unwrap().use_count.get() == 1, "blk_1_v51 use should be 1");
assert!(factorial_func.context.get_value(6).unwrap().use_count.get() == 1, "blk_1_fac use should be 1");
assert!(factorial_func.context.get_value(7).unwrap().use_count.get() == 1, "blk_1_v52 use should be 1");
assert!(factorial_func.context.get_value_by_tag("blk_0_n_3").unwrap().use_count.get() == 2, "blk_0_n_3 use should be 2");
assert!(factorial_func.context.get_value_by_tag("blk_0_v48").unwrap().use_count.get() == 1, "blk_0_v48 use should be 1");
assert!(factorial_func.context.get_value_by_tag("blk_2_v53").unwrap().use_count.get() == 1, "blk_2_v53 use should be 1");
assert!(factorial_func.context.get_value_by_tag("blk_1_n_3").unwrap().use_count.get() == 2, "blk_1_n_3 use should be 2");
assert!(factorial_func.context.get_value_by_tag("blk_1_v50").unwrap().use_count.get() == 1, "blk_1_v50 use should be 1");
assert!(factorial_func.context.get_value_by_tag("blk_1_v51").unwrap().use_count.get() == 1, "blk_1_v51 use should be 1");
assert!(factorial_func.context.get_value_by_tag("blk_1_v52").unwrap().use_count.get() == 1, "blk_1_v52 use should be 1");
}
#[test]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment