To protect your data, the CISO officer has suggested users to enable GitLab 2FA as soon as possible.

Commit 3b88ae36 authored by qinsoon's avatar qinsoon
Browse files

remove RwLock on MuEntityHeader.name (Issue#15), rewrite all tests in Rust with

macro.
parent 2026c567
...@@ -9,7 +9,6 @@ use utils::LinkedHashSet; ...@@ -9,7 +9,6 @@ use utils::LinkedHashSet;
use std::fmt; use std::fmt;
use std::default; use std::default;
use std::sync::RwLock;
use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering};
pub type WPID = usize; pub type WPID = usize;
...@@ -74,9 +73,9 @@ pub struct MuFunction { ...@@ -74,9 +73,9 @@ pub struct MuFunction {
} }
impl MuFunction { impl MuFunction {
pub fn new(id: MuID, sig: P<MuFuncSig>) -> MuFunction { pub fn new(entity: MuEntityHeader, sig: P<MuFuncSig>) -> MuFunction {
MuFunction { MuFunction {
hdr: MuEntityHeader::unnamed(id), hdr: entity,
sig: sig, sig: sig,
cur_ver: None, cur_ver: None,
all_vers: vec![] all_vers: vec![]
...@@ -143,9 +142,9 @@ impl fmt::Debug for MuFunctionVersion { ...@@ -143,9 +142,9 @@ impl fmt::Debug for MuFunctionVersion {
} }
impl MuFunctionVersion { impl MuFunctionVersion {
pub fn new(id: MuID, func: MuID, sig: P<MuFuncSig>) -> MuFunctionVersion { pub fn new(entity: MuEntityHeader, func: MuID, sig: P<MuFuncSig>) -> MuFunctionVersion {
MuFunctionVersion{ MuFunctionVersion{
hdr: MuEntityHeader::unnamed(id), hdr: entity,
func_id: func, func_id: func,
sig: sig, sig: sig,
orig_content: None, orig_content: None,
...@@ -194,9 +193,10 @@ impl MuFunctionVersion { ...@@ -194,9 +193,10 @@ impl MuFunctionVersion {
self.is_compiled = true; self.is_compiled = true;
} }
pub fn new_ssa(&mut self, id: MuID, ty: P<MuType>) -> P<TreeNode> { pub fn new_ssa(&mut self, entity: MuEntityHeader, ty: P<MuType>) -> P<TreeNode> {
let id = entity.id();
let val = P(Value{ let val = P(Value{
hdr: MuEntityHeader::unnamed(id), hdr: entity,
ty: ty, ty: ty,
v: Value_::SSAVar(id) v: Value_::SSAVar(id)
}); });
...@@ -425,8 +425,8 @@ impl fmt::Debug for Block { ...@@ -425,8 +425,8 @@ impl fmt::Debug for Block {
} }
impl Block { impl Block {
pub fn new(id: MuID) -> Block { pub fn new(entity: MuEntityHeader) -> Block {
Block{hdr: MuEntityHeader::unnamed(id), content: None, control_flow: ControlFlow::default()} Block{hdr: entity, content: None, control_flow: ControlFlow::default()}
} }
pub fn is_receiving_exception_arg(&self) -> bool { pub fn is_receiving_exception_arg(&self) -> bool {
...@@ -1002,14 +1002,14 @@ impl fmt::Display for MemoryLocation { ...@@ -1002,14 +1002,14 @@ impl fmt::Display for MemoryLocation {
#[derive(Debug)] // Display, PartialEq, Clone #[derive(Debug)] // Display, PartialEq, Clone
pub struct MuEntityHeader { pub struct MuEntityHeader {
id: MuID, id: MuID,
name: RwLock<Option<MuName>> name: Option<MuName>
} }
impl Clone for MuEntityHeader { impl Clone for MuEntityHeader {
fn clone(&self) -> Self { fn clone(&self) -> Self {
MuEntityHeader { MuEntityHeader {
id: self.id, id: self.id,
name: RwLock::new(self.name.read().unwrap().clone()) name: self.name.clone()
} }
} }
} }
...@@ -1020,7 +1020,7 @@ impl Encodable for MuEntityHeader { ...@@ -1020,7 +1020,7 @@ impl Encodable for MuEntityHeader {
s.emit_struct("MuEntityHeader", 2, |s| { s.emit_struct("MuEntityHeader", 2, |s| {
try!(s.emit_struct_field("id", 0, |s| self.id.encode(s))); try!(s.emit_struct_field("id", 0, |s| self.id.encode(s)));
let name = &self.name.read().unwrap(); let name = &self.name;
try!(s.emit_struct_field("name", 1, |s| name.encode(s))); try!(s.emit_struct_field("name", 1, |s| name.encode(s)));
Ok(()) Ok(())
...@@ -1036,7 +1036,7 @@ impl Decodable for MuEntityHeader { ...@@ -1036,7 +1036,7 @@ impl Decodable for MuEntityHeader {
Ok(MuEntityHeader{ Ok(MuEntityHeader{
id: id, id: id,
name: RwLock::new(name) name: name
}) })
}) })
} }
...@@ -1058,14 +1058,14 @@ impl MuEntityHeader { ...@@ -1058,14 +1058,14 @@ impl MuEntityHeader {
pub fn unnamed(id: MuID) -> MuEntityHeader { pub fn unnamed(id: MuID) -> MuEntityHeader {
MuEntityHeader { MuEntityHeader {
id: id, id: id,
name: RwLock::new(None) name: None
} }
} }
pub fn named(id: MuID, name: MuName) -> MuEntityHeader { pub fn named(id: MuID, name: MuName) -> MuEntityHeader {
MuEntityHeader { MuEntityHeader {
id: id, id: id,
name: RwLock::new(Some(name_check(name))) name: Some(name_check(name))
} }
} }
...@@ -1074,12 +1074,7 @@ impl MuEntityHeader { ...@@ -1074,12 +1074,7 @@ impl MuEntityHeader {
} }
pub fn name(&self) -> Option<MuName> { pub fn name(&self) -> Option<MuName> {
self.name.read().unwrap().clone() self.name.clone()
}
pub fn set_name(&self, name: MuName) {
let mut name_guard = self.name.write().unwrap();
*name_guard = Some(name_check(name));
} }
fn abbreviate_name(&self) -> Option<MuName> { fn abbreviate_name(&self) -> Option<MuName> {
...@@ -1129,7 +1124,6 @@ impl fmt::Display for MuEntityHeader { ...@@ -1129,7 +1124,6 @@ impl fmt::Display for MuEntityHeader {
pub trait MuEntity { pub trait MuEntity {
fn id(&self) -> MuID; fn id(&self) -> MuID;
fn name(&self) -> Option<MuName>; fn name(&self) -> Option<MuName>;
fn set_name(&self, name: MuName);
fn as_entity(&self) -> &MuEntity; fn as_entity(&self) -> &MuEntity;
} }
...@@ -1155,13 +1149,6 @@ impl MuEntity for TreeNode { ...@@ -1155,13 +1149,6 @@ impl MuEntity for TreeNode {
} }
} }
fn set_name(&self, name: MuName) {
match self.v {
TreeNode_::Instruction(ref inst) => inst.set_name(name),
TreeNode_::Value(ref pv) => pv.set_name(name)
}
}
fn as_entity(&self) -> &MuEntity { fn as_entity(&self) -> &MuEntity {
match self.v { match self.v {
TreeNode_::Instruction(ref inst) => inst.as_entity(), TreeNode_::Instruction(ref inst) => inst.as_entity(),
......
#[macro_use]
extern crate log; extern crate log;
extern crate simple_logger; extern crate simple_logger;
#[macro_use] #[macro_use]
...@@ -14,9 +13,6 @@ macro_rules! impl_mu_entity { ...@@ -14,9 +13,6 @@ macro_rules! impl_mu_entity {
fn id(&self) -> MuID {self.hdr.id()} fn id(&self) -> MuID {self.hdr.id()}
#[inline(always)] #[inline(always)]
fn name(&self) -> Option<MuName> {self.hdr.name()} fn name(&self) -> Option<MuName> {self.hdr.name()}
fn set_name(&self, name: MuName) {
self.hdr.set_name(name);
}
fn as_entity(&self) -> &MuEntity { fn as_entity(&self) -> &MuEntity {
let ref_ty : &$entity = self; let ref_ty : &$entity = self;
ref_ty as &MuEntity ref_ty as &MuEntity
......
...@@ -3555,7 +3555,7 @@ pub fn spill_rewrite( ...@@ -3555,7 +3555,7 @@ pub fn spill_rewrite(
// generate a random new temporary // generate a random new temporary
let temp_ty = val_reg.ty.clone(); let temp_ty = val_reg.ty.clone();
let temp = func.new_ssa(vm.next_id(), temp_ty.clone()).clone_value(); let temp = func.new_ssa(MuEntityHeader::unnamed(vm.next_id()), temp_ty.clone()).clone_value();
// maintain mapping // maintain mapping
trace!("reg {} used in Inst{} is replaced as {}", val_reg, i, temp); trace!("reg {} used in Inst{} is replaced as {}", val_reg, i, temp);
...@@ -3603,7 +3603,7 @@ pub fn spill_rewrite( ...@@ -3603,7 +3603,7 @@ pub fn spill_rewrite(
temp_for_cur_inst.get(&reg).unwrap().clone() temp_for_cur_inst.get(&reg).unwrap().clone()
} else { } else {
let temp_ty = val_reg.ty.clone(); let temp_ty = val_reg.ty.clone();
let temp = func.new_ssa(vm.next_id(), temp_ty.clone()).clone_value(); let temp = func.new_ssa(MuEntityHeader::unnamed(vm.next_id()), temp_ty.clone()).clone_value();
spilled_scratch_temps.insert(temp.id(), reg); spilled_scratch_temps.insert(temp.id(), reg);
......
...@@ -178,11 +178,11 @@ impl CompilerPass for GenMovPhi { ...@@ -178,11 +178,11 @@ impl CompilerPass for GenMovPhi {
// insert new blocks here // insert new blocks here
for block_info in new_blocks_to_insert { for block_info in new_blocks_to_insert {
let block = { let block = {
let mut ret = Block::new(block_info.blk_id);
let target_id = block_info.target; let target_id = block_info.target;
let name = format!("intermediate_block_{}_to_{}", block_info.blk_id, target_id); let name = format!("intermediate_block_{}_to_{}", block_info.blk_id, target_id);
vm.set_name(ret.as_entity(), name);
let mut ret = Block::new(MuEntityHeader::named(block_info.blk_id, name));
vm.set_name(ret.as_entity());
let mut target_block = f_content.get_block_mut(target_id); let mut target_block = f_content.get_block_mut(target_id);
......
...@@ -177,7 +177,10 @@ impl Inlining { ...@@ -177,7 +177,10 @@ impl Inlining {
let old_name = cur_block.name().unwrap(); let old_name = cur_block.name().unwrap();
// start a new block // start a new block
cur_block = Block::new(vm.next_id()); let new_name = format!("{}_cont_after_inline_{}", old_name, inst_id);
trace!("create continue block for EXPRCALL/CCALL: {}", &new_name);
cur_block = Block::new(MuEntityHeader::named(vm.next_id(), new_name));
cur_block.content = Some(BlockContent{ cur_block.content = Some(BlockContent{
args: { args: {
if inst.value.is_none() { if inst.value.is_none() {
...@@ -190,9 +193,7 @@ impl Inlining { ...@@ -190,9 +193,7 @@ impl Inlining {
body: vec![], body: vec![],
keepalives: None keepalives: None
}); });
let new_name = format!("{}_cont_after_inline_{}", old_name, inst_id); vm.set_name(cur_block.as_entity());
trace!("create continue block for EXPRCALL/CCALL: {}", &new_name);
vm.set_name(cur_block.as_entity(), new_name);
// deal with the inlined function // deal with the inlined function
copy_inline_blocks(&mut new_blocks, cur_block.id(), copy_inline_blocks(&mut new_blocks, cur_block.id(),
...@@ -225,8 +226,9 @@ impl Inlining { ...@@ -225,8 +226,9 @@ impl Inlining {
// other than the inlined function returns, we need an intermediate block to pass extra arguments // other than the inlined function returns, we need an intermediate block to pass extra arguments
if resume.normal_dest.args.len() != inlined_fv_guard.sig.ret_tys.len() { if resume.normal_dest.args.len() != inlined_fv_guard.sig.ret_tys.len() {
debug!("need an extra block for passing normal dest arguments"); debug!("need an extra block for passing normal dest arguments");
let mut intermediate_block = Block::new(vm.next_id()); let int_block_name = format!("inline_{}_arg_pass", inst_id);
vm.set_name(intermediate_block.as_entity(), format!("inline_{}_arg_pass", inst_id)); let mut intermediate_block = Block::new(MuEntityHeader::named(vm.next_id(), int_block_name));
vm.set_name(intermediate_block.as_entity());
// branch to normal_dest with normal_dest arguments // branch to normal_dest with normal_dest arguments
let normal_dest_args = resume.normal_dest.get_arguments_as_node(&ops); let normal_dest_args = resume.normal_dest.get_arguments_as_node(&ops);
......
...@@ -573,9 +573,9 @@ impl <'a> VM { ...@@ -573,9 +573,9 @@ impl <'a> VM {
self.is_running.load(Ordering::Relaxed) self.is_running.load(Ordering::Relaxed)
} }
pub fn set_name(&self, entity: &MuEntity, name: MuName) { pub fn set_name(&self, entity: &MuEntity) {
let id = entity.id(); let id = entity.id();
entity.set_name(name.clone()); let name = entity.name().unwrap();
let mut map = self.id_name_map.write().unwrap(); let mut map = self.id_name_map.write().unwrap();
map.insert(id, name.clone()); map.insert(id, name.clone());
...@@ -601,11 +601,11 @@ impl <'a> VM { ...@@ -601,11 +601,11 @@ impl <'a> VM {
map.get(&id).unwrap().clone() map.get(&id).unwrap().clone()
} }
pub fn declare_const(&self, id: MuID, ty: P<MuType>, val: Constant) -> P<Value> { pub fn declare_const(&self, entity: MuEntityHeader, ty: P<MuType>, val: Constant) -> P<Value> {
let mut constants = self.constants.write().unwrap(); let mut constants = self.constants.write().unwrap();
let ret = P(Value{hdr: MuEntityHeader::unnamed(id), ty: ty, v: Value_::Constant(val)}); let ret = P(Value{hdr: entity, ty: ty, v: Value_::Constant(val)});
self.declare_const_internal(&mut constants, id, ret.clone()); self.declare_const_internal(&mut constants, ret.id(), ret.clone());
ret ret
} }
...@@ -644,17 +644,17 @@ impl <'a> VM { ...@@ -644,17 +644,17 @@ impl <'a> VM {
ValueLocation::Relocatable(backend::RegGroup::GPR, name) ValueLocation::Relocatable(backend::RegGroup::GPR, name)
} }
pub fn declare_global(&self, id: MuID, ty: P<MuType>) -> P<Value> { pub fn declare_global(&self, entity: MuEntityHeader, ty: P<MuType>) -> P<Value> {
let global = P(Value{ let global = P(Value{
hdr: MuEntityHeader::unnamed(id), hdr: entity,
ty: self.declare_type(self.next_id(), MuType_::iref(ty.clone())), ty: self.declare_type(MuEntityHeader::unnamed(self.next_id()), MuType_::iref(ty.clone())),
v: Value_::Global(ty) v: Value_::Global(ty)
}); });
let mut globals = self.globals.write().unwrap(); let mut globals = self.globals.write().unwrap();
let mut global_locs = self.global_locations.write().unwrap(); let mut global_locs = self.global_locations.write().unwrap();
self.declare_global_internal(&mut globals, &mut global_locs, id, global.clone()); self.declare_global_internal(&mut globals, &mut global_locs, global.id(), global.clone());
global global
} }
...@@ -692,12 +692,12 @@ impl <'a> VM { ...@@ -692,12 +692,12 @@ impl <'a> VM {
global_locs.insert(id, loc); global_locs.insert(id, loc);
} }
pub fn declare_type(&self, id: MuID, ty: MuType_) -> P<MuType> { pub fn declare_type(&self, entity: MuEntityHeader, ty: MuType_) -> P<MuType> {
let ty = P(MuType{hdr: MuEntityHeader::unnamed(id), v: ty}); let ty = P(MuType{hdr: entity, v: ty});
let mut types = self.types.write().unwrap(); let mut types = self.types.write().unwrap();
self.declare_type_internal(&mut types, id, ty.clone()); self.declare_type_internal(&mut types, ty.id(), ty.clone());
ty ty
} }
...@@ -729,11 +729,11 @@ impl <'a> VM { ...@@ -729,11 +729,11 @@ impl <'a> VM {
} }
} }
pub fn declare_func_sig(&self, id: MuID, ret_tys: Vec<P<MuType>>, arg_tys: Vec<P<MuType>>) -> P<MuFuncSig> { pub fn declare_func_sig(&self, entity: MuEntityHeader, ret_tys: Vec<P<MuType>>, arg_tys: Vec<P<MuType>>) -> P<MuFuncSig> {
let ret = P(MuFuncSig{hdr: MuEntityHeader::unnamed(id), ret_tys: ret_tys, arg_tys: arg_tys}); let ret = P(MuFuncSig{hdr: entity, ret_tys: ret_tys, arg_tys: arg_tys});
let mut func_sigs = self.func_sigs.write().unwrap(); let mut func_sigs = self.func_sigs.write().unwrap();
self.declare_func_sig_internal(&mut func_sigs, id, ret.clone()); self.declare_func_sig_internal(&mut func_sigs, ret.id(), ret.clone());
ret ret
} }
......
macro_rules! typedef { macro_rules! typedef {
// int, floating point // int, floating point
(($vm: expr) $name: ident = mu_int($len: expr)) => { (($vm: expr) $name: ident = mu_int($len: expr)) => {
let $name = $vm.declare_type($vm.next_id(), MuType_::int($len)); let $name = $vm.declare_type(MuEntityHeader::named($vm.next_id(), Mu(stringify!($name))), MuType_::int($len));
$vm.set_name($name.as_entity(), Mu(stringify!($name))); $vm.set_name($name.as_entity());
}; };
(($vm: expr) $name: ident = mu_double) => { (($vm: expr) $name: ident = mu_double) => {
let $name = $vm.declare_type($vm.next_id(), MuType_::double()); let $name = $vm.declare_type(MuEntityHeader::named($vm.next_id(), Mu(stringify!($name))), MuType_::double());
$vm.set_name($name.as_entity(), Mu(stringify!($name))); $vm.set_name($name.as_entity());
}; };
// ref, iref, ptr // ref, iref, ptr
(($vm: expr) $name: ident = mu_ref($ty: ident)) => { (($vm: expr) $name: ident = mu_ref($ty: ident)) => {
let $name = $vm.declare_type($vm.next_id(), MuType_::muref($ty.clone())); let $name = $vm.declare_type(MuEntityHeader::named($vm.next_id(), Mu(stringify!($name))), MuType_::muref($ty.clone()));
$vm.set_name($name.as_entity(), Mu(stringify!($name))); $vm.set_name($name.as_entity());
}; };
(($vm: expr) $name: ident = mu_iref($ty: ident)) => { (($vm: expr) $name: ident = mu_iref($ty: ident)) => {
let $name = $vm.declare_type($vm.next_id(), MuType_::iref($ty.clone())); let $name = $vm.declare_type(MuEntityHeader::named($vm.next_id(), Mu(stringify!($name))), MuType_::iref($ty.clone()));
$vm.set_name($name.as_entity(), Mu(stringify!($name))); $vm.set_name($name.as_entity());
}; };
(($vm: expr) $name: ident = mu_uptr($ty: ident)) => { (($vm: expr) $name: ident = mu_uptr($ty: ident)) => {
let $name = $vm.declare_type($vm.next_id(), MuType_::uptr($ty.clone())); let $name = $vm.declare_type(MuEntityHeader::named($vm.next_id(), Mu(stringify!($name))), MuType_::uptr($ty.clone()));
$vm.set_name($name.as_entity(), Mu(stringify!($name))); $vm.set_name($name.as_entity());
}; };
// struct // struct
(($vm: expr) $name: ident = mu_struct($($ty: ident), *)) => { (($vm: expr) $name: ident = mu_struct($($ty: ident), *)) => {
let $name = $vm.declare_type($vm.next_id(), MuType_::mustruct(Mu(stringify!($name)), vec![$($ty.clone()),*])); let $name = $vm.declare_type(MuEntityHeader::named($vm.next_id(), Mu(stringify!($name))), MuType_::mustruct(Mu(stringify!($name)), vec![$($ty.clone()),*]));
$vm.set_name($name.as_entity(), Mu(stringify!($name))); $vm.set_name($name.as_entity());
}; };
(($vm: expr) $name: ident = mu_struct()) => { (($vm: expr) $name: ident = mu_struct()) => {
let $name = $vm.declare_type($vm.next_id(), MuType_::mustruct(Mu(stringify!($name)), vec![])); let $name = $vm.declare_type(MuEntityHeader::named($vm.next_id(), Mu(stringify!($name))), MuType_::mustruct(Mu(stringify!($name)), vec![]));
$vm.set_name($name.as_entity(), Mu(stringify!($name))); $vm.set_name($name.as_entity());
}; };
(($vm: expr) $name: ident = mu_struct_placeholder()) => { (($vm: expr) $name: ident = mu_struct_placeholder()) => {
let $name = $vm.declare_type($vm.next_id(), MuType_::mustruct_empty(Mu(stringify!($name)))); let $name = $vm.declare_type(MuEntityHeader::named($vm.next_id(), Mu(stringify!($name))), MuType_::mustruct_empty(Mu(stringify!($name))));
$vm.set_name($name.as_entity(), Mu(stringify!($name))); $vm.set_name($name.as_entity());
}; };
(($vm: expr) mu_struct_put($name: ident, $($ty: ident), *)) => { (($vm: expr) mu_struct_put($name: ident, $($ty: ident), *)) => {
MuType_::mustruct_put(&Mu(stringify!($name)), vec![$($ty.clone()), *]) MuType_::mustruct_put(&Mu(stringify!($name)), vec![$($ty.clone()), *])
}; };
// hybrid // hybrid
(($vm: expr) $name: ident = mu_hybrid($($ty: ident), *); $var_ty: ident) => { (($vm: expr) $name: ident = mu_hybrid($($ty: ident), *)($var_ty: ident)) => {
let $name = $vm.declare_type($vm.next_id(), MuType_::hybrid(Mu(stringify!($name)), vec![$($ty.clone()), *], $var_ty.clone())); let $name = $vm.declare_type(MuEntityHeader::named($vm.next_id(), Mu(stringify!($name))), MuType_::hybrid(Mu(stringify!($name)), vec![$($ty.clone()), *], $var_ty.clone()));
$vm.set_name($name.as_entity(), Mu(stringify!($name))); $vm.set_name($name.as_entity());
};
(($vm: expr) $name: ident = mu_hybrid(none; $var_ty: ident)) => {
let $name = $vm.declare_type($vm.next_id(), MuType_::hybrid(Mu(stringify!($name)), vec![], $var_ty.clone()));
$vm.set_name($name.as_entity(), Mu(stringify!($name)));
}; };
// array // array
(($vm: expr) $name: ident = mu_array($ty: ident, $len: expr)) => { (($vm: expr) $name: ident = mu_array($ty: ident, $len: expr)) => {
let $name = $vm.declare_type($vm.next_id(), MuType_::array($ty.clone(), $len)); let $name = $vm.declare_type(MuEntityHeader::named($vm.next_id(), Mu(stringify!($name))), MuType_::array($ty.clone(), $len));
$vm.set_name($name.as_entity(), Mu(stringify!($name))); $vm.set_name($name.as_entity());
}; };
// funcref // funcref
(($vm: expr) $name: ident = mu_funcref($sig: ident)) => { (($vm: expr) $name: ident = mu_funcref($sig: ident)) => {
let $name = $vm.declare_type($vm.next_id(), MuType_::funcref($sig.clone())); let $name = $vm.declare_type(MuEntityHeader::named($vm.next_id(), Mu(stringify!($name))), MuType_::funcref($sig.clone()));
$vm.set_name($name.as_entity(), Mu(stringify!($name))); $vm.set_name($name.as_entity());
} };
// ufuncptr
(($vm: expr) $name: ident = mu_ufuncptr($sig: ident)) => {
let $name = $vm.declare_type(MuEntityHeader::named($vm.next_id(), Mu(stringify!($name))), MuType_::ufuncptr($sig.clone()));
$vm.set_name($name.as_entity());
};
} }
macro_rules! constdef { macro_rules! constdef {
(($vm: expr) <$ty: ident> $name: ident = $val: expr) => { (($vm: expr) <$ty: ident> $name: ident = $val: expr) => {
let $name = $vm.declare_const($vm.next_id(), $ty.clone(), $val); let $name = $vm.declare_const(MuEntityHeader::named($vm.next_id(), Mu(stringify!($name))), $ty.clone(), $val);
$vm.set_name($name.as_entity(), Mu(stringify!($name))); $vm.set_name($name.as_entity());
} }
} }
macro_rules! globaldef { macro_rules! globaldef {
(($vm: expr) <$ty: ident> $name: ident) => { (($vm: expr) <$ty: ident> $name: ident) => {
let $name = $vm.declare_global($vm.next_id(), $ty.clone()); let $name = $vm.declare_global(MuEntityHeader::named($vm.next_id(), Mu(stringify!($name))), $ty.clone());
$vm.set_name($name.as_entity(), Mu(stringify!($name))); $vm.set_name($name.as_entity());
}