From 14d25b3b9d54eed1c5bf93f762a3711d707f1df3 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Sun, 13 Feb 2022 17:21:42 +0800 Subject: [PATCH] Fixed broken tests --- nac3core/src/codegen/expr.rs | 1 + nac3standalone/demo/src/lists.py | 14 +++++++------- nac3standalone/src/basic_symbol_resolver.rs | 12 ++++++++++-- nac3standalone/src/main.rs | 5 +++-- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/nac3core/src/codegen/expr.rs b/nac3core/src/codegen/expr.rs index ff47a12b1..badd9f4a3 100644 --- a/nac3core/src/codegen/expr.rs +++ b/nac3core/src/codegen/expr.rs @@ -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"); diff --git a/nac3standalone/demo/src/lists.py b/nac3standalone/demo/src/lists.py index e4d2ffc49..911737a81 100644 --- a/nac3standalone/demo/src/lists.py +++ b/nac3standalone/demo/src/lists.py @@ -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]) \ No newline at end of file + output_int32_list([int32(t[4][2]) for t in tl8]) diff --git a/nac3standalone/src/basic_symbol_resolver.rs b/nac3standalone/src/basic_symbol_resolver.rs index 8b5f1d680..6e886fdfc 100644 --- a/nac3standalone/src/basic_symbol_resolver.rs +++ b/nac3standalone/src/basic_symbol_resolver.rs @@ -17,6 +17,7 @@ pub struct ResolverInternal { pub id_to_def: Mutex>, pub class_names: Mutex>, pub module_globals: Mutex>, + pub str_store: Mutex>, } 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 + } } } diff --git a/nac3standalone/src/main.rs b/nac3standalone/src/main.rs index b91ef2c9f..c6dcf56cf 100644 --- a/nac3standalone/src/main.rs +++ b/nac3standalone/src/main.rs @@ -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>>> = 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");