Commit c29c8471 authored by qinsoon's avatar qinsoon

[wip] fixed rwlock problem. failing doctest

parent 27886d4d
...@@ -1160,9 +1160,13 @@ pub fn emit_context(vm: &VM) { ...@@ -1160,9 +1160,13 @@ pub fn emit_context(vm: &VM) {
} }
// serialize vm // serialize vm
file.write("\t.data\n".as_bytes()).unwrap(); {
file.write_fmt(format_args!("vm: .asciiz \"{}\"", json::encode(&vm).unwrap())).unwrap(); let serialize_vm = json::encode(&vm).unwrap();
file.write("\n".as_bytes()).unwrap();
file.write("\t.data\n".as_bytes()).unwrap();
file.write_fmt(format_args!("vm: .asciiz \"{}\"", serialize_vm)).unwrap();
file.write("\n".as_bytes()).unwrap();
}
// main_thread // main_thread
// let primordial = vm.primordial.read().unwrap(); // let primordial = vm.primordial.read().unwrap();
......
pub extern crate immix_rust as gc;
pub use gc::common::Address; pub use gc::common::Address;
pub use gc::common::ObjectReference; pub use gc::common::ObjectReference;
......
...@@ -5,7 +5,7 @@ use ast::ptr::*; ...@@ -5,7 +5,7 @@ use ast::ptr::*;
use ast::types::*; use ast::types::*;
use vm::VM; use vm::VM;
use runtime::ValueLocation; use runtime::ValueLocation;
use runtime::gc; use gc;
use utils::ByteSize; use utils::ByteSize;
use utils::Address; use utils::Address;
......
...@@ -8,10 +8,10 @@ use compiler::backend; ...@@ -8,10 +8,10 @@ use compiler::backend;
use compiler::backend::BackendTypeInfo; use compiler::backend::BackendTypeInfo;
use vm::machine_code::CompiledFunction; use vm::machine_code::CompiledFunction;
use vm::vm_options::VMOptions; use vm::vm_options::VMOptions;
use runtime::gc;
use runtime::thread::*; use runtime::thread::*;
use runtime::ValueLocation; use runtime::ValueLocation;
use utils::Address; use utils::Address;
use gc;
use rustc_serialize::{Encodable, Encoder, Decodable, Decoder}; use rustc_serialize::{Encodable, Encoder, Decodable, Decoder};
...@@ -60,7 +60,7 @@ impl Encodable for VM { ...@@ -60,7 +60,7 @@ impl Encodable for VM {
fn encode<S: Encoder> (&self, s: &mut S) -> Result<(), S::Error> { fn encode<S: Encoder> (&self, s: &mut S) -> Result<(), S::Error> {
// serialize VM_SERIALIZE_FIELDS fields // serialize VM_SERIALIZE_FIELDS fields
// PLUS ONE extra global STRUCT_TAG_MAP // PLUS ONE extra global STRUCT_TAG_MAP
s.emit_struct("VM", VM_SERIALIZE_FIELDS, |s| { s.emit_struct("VM", VM_SERIALIZE_FIELDS + 1, |s| {
// next_id // next_id
try!(s.emit_struct_field("next_id", 0, |s| { try!(s.emit_struct_field("next_id", 0, |s| {
s.emit_usize(self.next_id.load(Ordering::SeqCst)) s.emit_usize(self.next_id.load(Ordering::SeqCst))
......
extern crate mu; extern crate mu;
extern crate log; extern crate log;
extern crate simple_logger; extern crate simple_logger;
extern crate immix_rust as gc;
mod test_ir; mod test_ir;
mod test_compiler; mod test_compiler;
......
...@@ -25,12 +25,14 @@ fn test_global_access() { ...@@ -25,12 +25,14 @@ fn test_global_access() {
Box::new(backend::code_emission::CodeEmission::new()) Box::new(backend::code_emission::CodeEmission::new())
]), vm.clone()); ]), vm.clone());
let func_id = vm.id_of("global_access"); {
let funcs = vm.funcs().read().unwrap(); let func_id = vm.id_of("global_access");
let func = funcs.get(&func_id).unwrap().read().unwrap(); let funcs = vm.funcs().read().unwrap();
let func_vers = vm.func_vers().read().unwrap(); let func = funcs.get(&func_id).unwrap().read().unwrap();
let mut func_ver = func_vers.get(&func.cur_ver.unwrap()).unwrap().write().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);
compiler.compile(&mut func_ver);
}
backend::emit_context(&vm); backend::emit_context(&vm);
} }
...@@ -21,13 +21,15 @@ fn test_thread_create() { ...@@ -21,13 +21,15 @@ fn test_thread_create() {
let compiler = Compiler::new(CompilerPolicy::default(), vm.clone()); let compiler = Compiler::new(CompilerPolicy::default(), vm.clone());
let func_id = vm.id_of("fac"); let func_id = vm.id_of("fac");
let funcs = vm.funcs().read().unwrap(); {
let func = funcs.get(&func_id).unwrap().read().unwrap(); let funcs = vm.funcs().read().unwrap();
let func_vers = vm.func_vers().read().unwrap(); let func = funcs.get(&func_id).unwrap().read().unwrap();
let mut func_ver = func_vers.get(&func.cur_ver.unwrap()).unwrap().write().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);
compiler.compile(&mut func_ver);
}
vm.make_primordial_thread(func_id, vec![Constant::Int(5)]); vm.make_primordial_thread(func_id, vec![Constant::Int(5)]);
backend::emit_context(&vm); backend::emit_context(&vm);
......
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