Commit 09971f3a authored by qinsoon's avatar qinsoon

move stuff related with primordial to runtime mod

parent 8f5cfd09
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <string.h>
extern void* vm;
extern void mu_main(char* vm);
extern void mu_trace_level_log();
int main() {
mu_trace_level_log();
printf("main(), going to launch mu_main()\n");
char* serialize_vm = (char*) &vm;
printf("%s\n", serialize_vm);
mu_main(serialize_vm);
}
......@@ -5,18 +5,24 @@ pub mod entrypoints;
pub use runtime::mm::common::Address;
pub use runtime::mm::common::ObjectReference;
use log;
use simple_logger;
use utils;
use ast::ir;
use ast::ptr::*;
use ast::types::MuType_;
use ast::types::MuType;
use ast::ir::*;
use vm::VM;
use compiler::backend::Word;
use compiler::backend::RegGroup;
use std::os::raw::c_char;
use std::os::raw::c_void;
use std::ffi::CString;
use std::ffi::CStr;
use std::sync::Arc;
lazy_static! {
pub static ref ADDRESS_TYPE : P<MuType> = P(
......@@ -77,4 +83,36 @@ impl ValueLocation {
_ => unimplemented!()
}
}
}
#[no_mangle]
pub extern fn mu_trace_level_log() {
simple_logger::init_with_level(log::LogLevel::Trace).ok();
}
#[no_mangle]
pub extern fn mu_main(serialized_vm : *const c_char) {
debug!("mu_main() started...");
let str_vm = unsafe{CStr::from_ptr(serialized_vm)}.to_str().unwrap();
let vm : Arc<VM> = Arc::new(VM::resume_vm(str_vm));
let primordial = vm.primordial.read().unwrap();
if primordial.is_none() {
panic!("no primordial thread/stack/function. Client should provide an entry point");
} else {
let primordial = primordial.as_ref().unwrap();
// create mu stack
let stack = vm.new_stack(primordial.func_id);
let args : Vec<ValueLocation> = primordial.args.iter().map(|arg| ValueLocation::from_constant(arg.clone())).collect();
// FIXME: currently assumes no user defined thread local
// will need to fix this after we can serialize heap object
let thread = vm.new_thread_normal(stack, unsafe{Address::zero()}, args);
thread.join().unwrap();
}
}
\ No newline at end of file
......@@ -13,17 +13,12 @@ use runtime::ValueLocation;
use utils::Address;
use runtime::mm as gc;
use log;
use simple_logger;
use rustc_serialize::{Encodable, Encoder, Decodable, Decoder};
use std::path;
use std::sync::RwLock;
use std::sync::atomic::{AtomicUsize, AtomicBool, ATOMIC_BOOL_INIT, ATOMIC_USIZE_INIT, Ordering};
use std::thread::JoinHandle;
use std::sync::Arc;
use std::os::raw::c_char;
use std::ffi::CStr;
pub struct VM {
// serialize
......@@ -510,36 +505,4 @@ impl <'a> VM {
unimplemented!()
}
#[no_mangle]
pub extern fn mu_trace_level_log() {
simple_logger::init_with_level(log::LogLevel::Trace).ok();
}
#[no_mangle]
pub extern fn mu_main(serialized_vm : *const c_char) {
debug!("mu_main() started...");
let str_vm = unsafe{CStr::from_ptr(serialized_vm)}.to_str().unwrap();
let vm : Arc<VM> = Arc::new(VM::resume_vm(str_vm));
let primordial = vm.primordial.read().unwrap();
if primordial.is_none() {
panic!("no primordial thread/stack/function. Client should provide an entry point");
} else {
let primordial = primordial.as_ref().unwrap();
// create mu stack
let stack = vm.new_stack(primordial.func_id);
let args : Vec<ValueLocation> = primordial.args.iter().map(|arg| ValueLocation::from_constant(arg.clone())).collect();
// FIXME: currently assumes no user defined thread local
// will need to fix this after we can serialize heap object
let thread = vm.new_thread_normal(stack, unsafe{Address::zero()}, args);
thread.join().unwrap();
}
}
}
}
\ No newline at end of file
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