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.

test_thread.rs 2.31 KB
Newer Older
qinsoon's avatar
qinsoon committed
1
2
#![allow(unused_imports)]

3
4
5
6
7
8
9
10
11
12
13
extern crate mu;
extern crate log;
extern crate simple_logger;

use self::mu::ast::types::*;
use self::mu::ast::ir::*;
use self::mu::ast::inst::*;
use self::mu::ast::op::*;
use self::mu::vm::*;
use self::mu::compiler::*;

14
use aot;
15
16

use std::sync::Arc;
17
18
use std::sync::RwLock;
use std::collections::HashMap;
19
20
21

#[test]
fn test_thread_create() {
22
23
    simple_logger::init_with_level(log::LogLevel::Trace).ok();
    
24
    let vm = Arc::new(primordial_main());
25
26
27
    
    let compiler = Compiler::new(CompilerPolicy::default(), vm.clone());
    
28
    let func_id = vm.id_of("primordial_main");    
29
30
31
32
33
34
35
36
    {
        let funcs = vm.funcs().read().unwrap();
        let func = funcs.get(&func_id).unwrap().read().unwrap();
        let func_vers = vm.func_vers().read().unwrap();
        let mut func_ver = func_vers.get(&func.cur_ver.unwrap()).unwrap().write().unwrap();
        
        compiler.compile(&mut func_ver);
    }
37
    
38
    vm.make_primordial_thread(func_id, vec![]);
39
    backend::emit_context(&vm);
40
41
42
    
    let executable = aot::link_primordial(vec!["primordial_main".to_string()], "primordial_main_test");
    aot::execute(executable);
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
}

fn primordial_main() -> VM {
    let vm = VM::new();
    
    let sig = vm.declare_func_sig(vm.next_id(), vec![], vec![]);
    let func = MuFunction::new(vm.next_id(), sig.clone());
    vm.set_name(func.as_entity(), "primordial_main".to_string());
    let func_id = func.id();
    vm.declare_func(func);
    
    let mut func_ver = MuFunctionVersion::new(vm.next_id(), func_id, sig.clone());
    
    let mut blk_entry = Block::new(vm.next_id());
    vm.set_name(blk_entry.as_entity(), "entry".to_string());
qinsoon's avatar
qinsoon committed
58
59
    let thread_exit = func_ver.new_inst(Instruction {
        hdr: MuEntityHeader::unnamed(vm.next_id()),
60
61
62
63
64
65
66
        value: None,
        ops: RwLock::new(vec![]),
        v: Instruction_::ThreadExit
    });
    
    let blk_entry_content = BlockContent {
        args: vec![],
67
        exn_arg: None,
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
        body: vec![thread_exit],
        keepalives: None
    };
    blk_entry.content = Some(blk_entry_content);
    
    func_ver.define(FunctionContent {
        entry: blk_entry.id(),
        blocks: {
            let mut blocks = HashMap::new();
            blocks.insert(blk_entry.id(), blk_entry);
            blocks
        }
    });
    
    vm.define_func_version(func_ver);
    
    vm
85
}