forked from M-Labs/nac3
1
0
Fork 0

Fixed broken tests

This commit is contained in:
pca006132 2022-02-13 17:21:42 +08:00
parent 265d234266
commit 14d25b3b9d
4 changed files with 21 additions and 11 deletions

View File

@ -1193,6 +1193,7 @@ pub fn gen_expr<'ctx, 'a, G: CodeGenerator>(
.unwrap()
.to_basic_value_enum(ctx, generator)
.into_int_value();
let raw_index = ctx.builder.build_int_s_extend(raw_index, generator.get_size_type(ctx.ctx), "sext");
// handle negative index
let is_negative = ctx.builder.build_int_compare(inkwell::IntPredicate::SLT, raw_index,
generator.get_size_type(ctx.ctx).const_zero(), "is_neg");

View File

@ -29,8 +29,8 @@ def run() -> int32:
output_int32_list(data[m2::m1])
# work around https://git.m-labs.hk/M-Labs/nac3/issues/188
#get_list_slice()
#list_slice_assignment()
get_list_slice()
list_slice_assignment()
return 0
def get_list_slice():
@ -66,7 +66,7 @@ def get_list_slice():
il[15:50:1],
]:
output_int32_list(l0)
for l1 in [
bl[:],
bl[1:1],
@ -120,7 +120,7 @@ def get_list_slice():
fl[15:50:1],
]:
output_int32_list([int32(f) for f in l2])
for l3 in [
al[:],
al[1:1],
@ -148,7 +148,7 @@ def get_list_slice():
]:
output_int32_list([a.a for a in l3])
output_int32_list([int32(a.b) for a in l3])
for l4 in [
tl[:],
tl[1:1],
@ -188,7 +188,7 @@ def list_slice_assignment():
fl = [1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0, 10.1]
al = [A(i, bl[i]) for i in range(len(bl))]
tl = [(i, al[i], fl[i], (), (i, i + 1, bl[i])) for i in range(len(bl))]
il1 = il[:]
il1[2:5] = [99,98,97]
output_int32_list(il1)
@ -321,4 +321,4 @@ def list_slice_assignment():
output_int32_list([int32(t[2]) for t in tl8])
output_int32_list([t[4][0] for t in tl8])
output_int32_list([t[4][1] for t in tl8])
output_int32_list([int32(t[4][2]) for t in tl8])
output_int32_list([int32(t[4][2]) for t in tl8])

View File

@ -17,6 +17,7 @@ pub struct ResolverInternal {
pub id_to_def: Mutex<HashMap<StrRef, DefinitionId>>,
pub class_names: Mutex<HashMap<StrRef, Type>>,
pub module_globals: Mutex<HashMap<StrRef, SymbolValue>>,
pub str_store: Mutex<HashMap<String, i32>>,
}
impl ResolverInternal {
@ -71,7 +72,14 @@ impl SymbolResolver for Resolver {
self.0.id_to_def.lock().get(&id).cloned()
}
fn get_string_id(&self, _: &str) -> i32 {
unimplemented!()
fn get_string_id(&self, s: &str) -> i32 {
let mut str_store = self.0.str_store.lock();
if let Some(id) = str_store.get(s) {
*id
} else {
let id = str_store.len() as i32;
str_store.insert(s.to_string(), id);
id
}
}
}

View File

@ -52,6 +52,7 @@ fn main() {
id_to_def: builtins_def.into(),
class_names: Default::default(),
module_globals: Default::default(),
str_store: Default::default(),
}
.into();
let resolver =
@ -247,7 +248,7 @@ fn main() {
let membuffers: Arc<Mutex<Vec<Vec<u8>>>> = Default::default();
let membuffer = membuffers.clone();
let f = Arc::new(WithCall::new(Box::new(move |module| {
let buffer = module.write_bitcode_to_memory();
let buffer = buffer.as_slice().into();
@ -288,7 +289,7 @@ fn main() {
builder.set_inliner_with_threshold(255);
builder.populate_module_pass_manager(&passes);
passes.run_on(&main);
let triple = TargetMachine::get_default_triple();
let target =
Target::from_triple(&triple).expect("couldn't create target from target triple");