GitLab will be upgraded on June 2nd 2020 at 2.00 pm (AEDT) to 3.00 pm (AEDT) due to Critical Security Patch Availability. During the update, GitLab and Mattermost services will not be available. If you have any concerns with this, please talk to local Gitlab admin team.

Commit 0dbbcdfd authored by Kunshan Wang's avatar Kunshan Wang

API: current_thread_as_mu_thread in MuVM

parent 5be79e86
......@@ -46,9 +46,17 @@ impl MuVM {
panic!("Not implemented")
}
pub fn compile_to_sharedlib(&mut self, lib_name: String, extra_srcs: Vec<String>) {
panic!("Not implemented")
}
pub fn current_thread_as_mu_thread(&mut self, threadlocal: CMuCPtr) {
panic!("Not implemented")
}
}
impl<'v> MuCtx<'v> {
impl MuCtx {
pub fn id_of(&mut self, name: MuName) -> MuID {
panic!("Not implemented")
}
......@@ -407,7 +415,7 @@ impl<'v> MuCtx<'v> {
}
impl<'c> MuIRBuilder<'c> {
impl MuIRBuilder {
pub fn load(&mut self) {
panic!("Not implemented")
}
......
......@@ -243,13 +243,20 @@ extern fn _forwarder__MuVM__set_trap_handler(mvm: *mut CMuVM, trap_handler: CMuT
};
}
extern fn _forwarder__MuVM__compile_to_sharedlib(mvm: *mut CMuVM, lib_name: CMuCString,
extra_srcs: *const CMuCString, n: usize) {
extern fn _forwarder__MuVM__compile_to_sharedlib(mvm: *mut CMuVM, lib_name: CMuCString, extra_srcs: *mut CMuCString, n_extra_srcs: CMuArraySize) {
let mut _arg_mvm = from_MuVM_ptr(mvm);
let mut _arg_lib_name = from_MuCString(lib_name);
let _arg_extra_srcs = from_MuCString_array(extra_srcs, n);
let mut _arg_extra_srcs = from_MuCString_array(extra_srcs, n_extra_srcs);
unsafe {
(*_arg_mvm).compile_to_sharedlib(&_arg_lib_name, _arg_extra_srcs)
(*_arg_mvm).compile_to_sharedlib(_arg_lib_name, _arg_extra_srcs)
};
}
extern fn _forwarder__MuVM__current_thread_as_mu_thread(mvm: *mut CMuVM, threadlocal: CMuCPtr) {
let mut _arg_mvm = from_MuVM_ptr(mvm);
let mut _arg_threadlocal = threadlocal;
unsafe {
(*_arg_mvm).current_thread_as_mu_thread(_arg_threadlocal)
};
}
......@@ -2048,6 +2055,7 @@ pub fn make_new_MuVM(header: *mut c_void) -> *mut CMuVM {
name_of: _forwarder__MuVM__name_of,
set_trap_handler: _forwarder__MuVM__set_trap_handler,
compile_to_sharedlib: _forwarder__MuVM__compile_to_sharedlib,
current_thread_as_mu_thread: _forwarder__MuVM__current_thread_as_mu_thread,
});
Box::into_raw(bx)
......
......@@ -109,8 +109,8 @@ pub struct CMuVM {
pub id_of: extern fn(*mut CMuVM, CMuName) -> CMuID,
pub name_of: extern fn(*mut CMuVM, CMuID) -> CMuName,
pub set_trap_handler: extern fn(*mut CMuVM, CMuTrapHandler, CMuCPtr),
// this function is only used in testing jit
pub compile_to_sharedlib: extern fn(*mut CMuVM, CMuCString, *const CMuCString, CMuArraySize),
pub compile_to_sharedlib: extern fn(*mut CMuVM, CMuCString, *mut CMuCString, CMuArraySize),
pub current_thread_as_mu_thread: extern fn(*mut CMuVM, CMuCPtr),
}
#[repr(C)]
......
use super::common::*;
use std::sync::Arc;
use runtime::thread;
use utils::Address;
use std::mem::transmute;
pub struct MuVM {
// The actual VM
pub vm: Arc<VM>,
......@@ -70,7 +74,7 @@ impl MuVM {
panic!("Not implemented")
}
pub fn compile_to_sharedlib(&self, lib_name: &str, extra_srcs: Vec<String>) {
pub fn compile_to_sharedlib(&self, lib_name: String, extra_srcs: Vec<String>) {
extern crate libloading as ll;
use compiler::*;
......@@ -88,7 +92,16 @@ impl MuVM {
func_names.push(func.name().unwrap());
}
backend::emit_context(&self.vm);
aot::link_dylib_with_extra_srcs(func_names, extra_srcs, lib_name);
aot::link_dylib_with_extra_srcs(func_names, extra_srcs, &lib_name);
}
pub fn current_thread_as_mu_thread(&self, threadlocal: CMuCPtr) {
unsafe {
thread::MuThread::current_thread_as_mu_thread(
transmute::<CMuCPtr, Address>(threadlocal),
self.vm.clone()
)
}
}
}
......
......@@ -13,3 +13,16 @@ mod deps {
extern crate ast;
}
use runtime::thread;
use utils::Address;
#[no_mangle]
pub fn current_thread_as_mu_thread(threadlocal: Address, api_vm: *const api_c::CMuVM) {
unsafe {
let hdr = ((*api_vm).header) as *const api_impl::MuVM;
let vm = ((*hdr).vm).clone();
thread::MuThread::current_thread_as_mu_thread(threadlocal, vm)
}
}
......@@ -272,6 +272,7 @@ struct MuVM {
void (*set_trap_handler)(MuVM *mvm, MuTrapHandler trap_handler, MuCPtr userdata);
void (*compile_to_sharedlib)(MuVM *mvm, MuCString lib_name, MuCString *extra_srcs, MuArraySize n_extra_srcs); /// MUAPIPARSER extra_srcs:array:n_extra_srcs
void (*current_thread_as_mu_thread)(MuVM *mvm, MuCPtr threadlocal);
};
// A local context. It can only be used by one thread at a time. It holds many
......
......@@ -435,7 +435,8 @@ pub fn make_new_{name}(header: *mut c_void) -> *mut {rust_name} {{
stubs_joined = "\n".join(stubs)
lifetime_params = _lifetime_params[name]
#lifetime_params = _lifetime_params[name]
lifetime_params = ""
stub_impl = """\
impl{lifetime_params} {name}{lifetime_params} {{
......
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