Commit 9e4b362a authored by qinsoon's avatar qinsoon

api can properly create globals now

parent 69d2807d
......@@ -841,6 +841,12 @@ impl<'lb, 'lvm> BundleLoader<'lb, 'lvm> {
}
}
for id in self.b.bundle.globals.keys() {
if !self.visited.contains(id) {
self.build_global(*id)
}
}
for id in self.b.bundle.funcs.keys() {
if !self.visited.contains(id) {
self.build_func(*id)
......@@ -1079,6 +1085,27 @@ impl<'lb, 'lvm> BundleLoader<'lb, 'lvm> {
self.built_constants.insert(id, P(impl_val));
}
fn build_global(&mut self, id: MuID) {
self.visited.insert(id);
let global = self.b.bundle.globals.get(&id).unwrap();
trace!("Building global {} {:?}", id, global);
let hdr = self.make_mu_entity_header(id);
let impl_ty = self.ensure_type_rec(global.ty); // global type
let impl_val = Value {
hdr: hdr,
ty: self.ensure_iref(impl_ty.id()), // iref to global
v: Value_::Global(impl_ty)
};
trace!("Global built: {} {:?}", id, impl_val);
self.built_globals.insert(id, P(impl_val));
}
fn build_func(&mut self, id: MuID) {
self.visited.insert(id);
......@@ -1193,6 +1220,8 @@ impl<'lb, 'lvm> BundleLoader<'lb, 'lvm> {
tn.clone()
} else if let Some(v) = self.built_constants.get(&id) {
self.new_global(v.clone())
} else if let Some(v) = self.built_globals.get(&id) {
self.new_global(v.clone())
} else {
panic!("Operand {} is neither a local var or a global var", id)
}
......
......@@ -160,6 +160,35 @@ fn test_consts_loading() {
}
}
#[test]
#[allow(unused_variables)]
fn test_globals_loading() {
let mut csp : CStringPool = Default::default();
unsafe {
VM::start_logging_trace();
info!("Starting micro VM...");
let mvm = mu_fastimpl_new();
let ctx = ((*mvm).new_context)(mvm);
let b = ((*ctx).new_ir_builder)(ctx);
let id_int32 = ((*b).gen_sym)(b, csp.get("@i32"));
((*b).new_type_int)(b, id_int32, 32);
let id_global = ((*b).gen_sym)(b, csp.get("@my_global"));
((*b).new_global_cell)(b, id_global, id_int32);
((*b).load)(b);
((*ctx).close_context)(ctx);
info!("Finished. ");
}
}
#[test]
#[allow(unused_variables)]
......
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