Implement nested and mutable statics (fixes #9)
This commit is contained in:
parent
7f62fedeb8
commit
6d1f0068d1
@ -44,6 +44,7 @@ unsafe impl Sync for i16 {}
|
||||
unsafe impl Sync for i32 {}
|
||||
unsafe impl Sync for isize {}
|
||||
unsafe impl Sync for char {}
|
||||
unsafe impl<'a, T: ?Sized> Sync for &'a T {}
|
||||
|
||||
#[lang = "freeze"]
|
||||
trait Freeze {}
|
||||
|
@ -16,7 +16,8 @@ extern "C" {
|
||||
fn puts(s: *const u8);
|
||||
}
|
||||
|
||||
static NUM: u8 = 6 * 7;
|
||||
static mut NUM: u8 = 6 * 7;
|
||||
static NUM_REF: &'static u8 = unsafe { &NUM };
|
||||
|
||||
#[lang = "start"]
|
||||
fn start(_main: *const u8, i: isize, _: *const *const u8) -> isize {
|
||||
@ -25,5 +26,8 @@ fn start(_main: *const u8, i: isize, _: *const *const u8) -> isize {
|
||||
puts(ptr);
|
||||
}
|
||||
|
||||
NUM as isize
|
||||
unsafe {
|
||||
NUM = 43;
|
||||
*NUM_REF as isize
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
use cranelift_module::*;
|
||||
use crate::prelude::*;
|
||||
use rustc::mir::interpret::{read_target_uint, AllocId, ConstValue, GlobalId};
|
||||
use syntax::ast::Mutability as AstMutability;
|
||||
use rustc::mir::interpret::{read_target_uint, AllocId, AllocType, ConstValue, GlobalId};
|
||||
use rustc::ty::Const;
|
||||
use rustc_mir::interpret::{CompileTimeEvaluator, Memory};
|
||||
|
||||
@ -191,12 +192,24 @@ fn define_all_allocs<'a, 'tcx: 'a, B: Backend + 'a>(
|
||||
|
||||
data_ctx.define(
|
||||
alloc.bytes.to_vec().into_boxed_slice(),
|
||||
Writability::Readonly,
|
||||
match alloc.runtime_mutability {
|
||||
AstMutability::Mutable => Writability::Writable,
|
||||
AstMutability::Immutable => Writability::Readonly,
|
||||
},
|
||||
);
|
||||
|
||||
for &(offset, reloc) in alloc.relocations.iter() {
|
||||
cx.todo.insert(TodoItem::Alloc(reloc));
|
||||
let data_id = data_id_for_alloc_id(module, reloc);
|
||||
let data_id = match tcx.alloc_map.lock().get(reloc).unwrap() {
|
||||
AllocType::Memory(_) => {
|
||||
cx.todo.insert(TodoItem::Alloc(reloc));
|
||||
data_id_for_alloc_id(module, reloc)
|
||||
}
|
||||
AllocType::Function(_) => unimplemented!("function static reference"),
|
||||
AllocType::Static(def_id) => {
|
||||
cx.todo.insert(TodoItem::Static(def_id));
|
||||
data_id_for_static(tcx, module, def_id)
|
||||
}
|
||||
};
|
||||
|
||||
let reloc_offset = {
|
||||
let endianness = memory.endianness();
|
||||
|
Loading…
x
Reference in New Issue
Block a user