Commit ff556adc authored by qinsoon's avatar qinsoon

[wip] working on using global through API. make sure bulk defining and

single defining has same behavior
parent a540f43e
......@@ -9,6 +9,7 @@ use ast::ptr::*;
use ast::types::*;
use utils::Address;
use compiler::backend::RegGroup;
use compiler::backend::BackendTypeInfo;
use vm::VM;
use runtime::ValueLocation;
use runtime::thread::MuThread;
......@@ -31,8 +32,7 @@ fn allocate(size: ByteSize, align: ByteSize, encode: u64, hybrid_len: Option<u64
ret
}
pub fn allocate_fixed(ty: P<MuType>, vm: &VM) -> Address {
let backendtype = vm.get_backend_type_info(ty.id());
pub fn allocate_fixed(ty: P<MuType>, backendtype: Box<BackendTypeInfo>) -> Address {
let gctype = backendtype.gc_type.clone();
let encode = get_gc_type_encode(gctype.id);
......@@ -43,8 +43,7 @@ pub fn allocate_fixed(ty: P<MuType>, vm: &VM) -> Address {
allocate(gctype.size(), gctype.alignment, encode, None).to_address()
}
pub fn allocate_hybrid(ty: P<MuType>, len: u64, vm: &VM) -> Address {
let backendtype = vm.get_backend_type_info((ty.id()));
pub fn allocate_hybrid(ty: P<MuType>, len: u64, backendtype: Box<BackendTypeInfo>) -> Address {
let gctype = backendtype.gc_type.clone();
let encode = get_gc_type_encode(gctype.id);
......@@ -55,12 +54,12 @@ pub fn allocate_hybrid(ty: P<MuType>, len: u64, vm: &VM) -> Address {
allocate(gctype.size_hybrid(len as u32), gctype.alignment, encode, Some(len)).to_address()
}
pub fn allocate_global(iref_global: P<Value>, vm: &VM) -> ValueLocation {
pub fn allocate_global(iref_global: P<Value>, backendtype: Box<BackendTypeInfo>) -> ValueLocation {
let referenced_type = match iref_global.ty.get_referenced_ty() {
Some(ty) => ty,
None => panic!("expected global to be an iref type, found {}", iref_global.ty)
};
let addr = allocate_fixed(referenced_type, vm);
let addr = allocate_fixed(referenced_type, backendtype);
ValueLocation::Direct(RegGroup::GPR, addr)
}
......@@ -334,6 +334,20 @@ impl MuThread {
// fake_swap_mu_thread(sp_threadlocal_loc);
// }
}
/// turn this current mu thread back as normal thread
pub unsafe fn cleanup_current_mu_thread() {
let mu_thread_addr = unsafe {muentry_get_thread_local()};
if !mu_thread_addr.is_zero() {
let mu_thread : *mut MuThread = mu_thread_addr.to_ptr_mut();
mm::drop_mutator(&mut (*mu_thread).allocator as *mut mm::Mutator);
let mu_thread : Box<MuThread> = unsafe {Box::from_raw(mu_thread)};
// drop mu_thread here
}
}
pub fn new_thread_normal(mut stack: Box<MuStack>, threadlocal: Address, vals: Vec<ValueLocation>, vm: Arc<VM>) -> JoinHandle<()> {
// set up arguments on stack
......
......@@ -23,7 +23,7 @@ pub fn current_thread_as_mu_thread(threadlocal: Address, api_vm: *const api_c::C
let hdr = ((*api_vm).header) as *const api_impl::MuVM;
let vm = ((*hdr).vm).clone();
thread::MuThread::current_thread_as_mu_thread(threadlocal, vm)
thread::MuThread::current_thread_as_mu_thread(threadlocal, vm);
}
}
This diff is collapsed.
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