diff --git a/bootstrap/repr/main.c b/bootstrap/repr/main.c index 8736cd7..4b1041b 100644 --- a/bootstrap/repr/main.c +++ b/bootstrap/repr/main.c @@ -1,10 +1,10 @@ -#include #include +#include extern uint64_t add(uint64_t, uint64_t); int main() { - printf("Hello"); - printf("Hello %lu", add(2, 7)); - puts("Hello"); + uint64_t val = add(2, 7); + printf("Hello %lu\n", val); + return val; } diff --git a/bootstrap/repr/makefile b/bootstrap/repr/makefile index 3ab941f..7e3d3d9 100644 --- a/bootstrap/repr/makefile +++ b/bootstrap/repr/makefile @@ -2,6 +2,7 @@ all: .ty/main.o .ty/integrationc.o .ty/integration.o .ty/repr-37b621cda8f778ea.r cd .ty && objdump -D integrationc.o > integrationc.o.txt cd .ty && objdump -D integration.o > integrationty.o.txt cd .ty && objdump -D repr-37b621cda8f778ea.repr.c0ded12167d2f276-cgu.0.rcgu.o > integrationrs.o.txt + cc -o .ty/mainty .ty/integration.o .ty/main.o touch .ty/all .ty/main.o: main.c diff --git a/fir/src/lib.rs b/fir/src/lib.rs index 8ff91f2..177b115 100644 --- a/fir/src/lib.rs +++ b/fir/src/lib.rs @@ -44,23 +44,29 @@ impl Fir { types: &Vec, oir: &mut Oir, ) -> Function { - let sig = Signature::new(CallConv::Cold); + let sig = Signature::new(CallConv::Fast); let name = UserFuncName::user(namespace, index); // todo:: types need to be worked out, params and returns defined let mut func = Function::with_name_signature(name, sig); let mut builder = FunctionBuilder::new(&mut func, ctx); let root_block = builder.create_block(); - // todo:: this is the issue with function arguments not working simple repr add case - func_def.args.iter().for_each(|x| { + let mut result_sets = vec![]; + for x in func_def.args.iter() { let z = self .recurse(*x, &mut builder, dtbl, scopes, types, oir) .unwrap(); builder.func.signature.params.push(AbiParam::new(I64)); - //let res = builder.block_params(root_block)[z.as_u32() as usize]; - }); - builder.func.signature.returns.push(AbiParam::new(I64)); + result_sets.push(z); + } builder.append_block_params_for_function_params(root_block); builder.switch_to_block(root_block); + + for (i, x) in result_sets.iter().enumerate() { + let res = builder.block_params(root_block)[i]; + builder.def_var(*x, res); + } + builder.func.signature.returns.push(AbiParam::new(I64)); + let _result = self.recurse(func_def.block, &mut builder, dtbl, scopes, types, oir); builder.seal_block(root_block); builder.finalize(); @@ -76,6 +82,7 @@ impl Fir { oir: &mut Oir, ) -> ResultFir { let result = self.add_var(); + builder.declare_var(result, I64); self.sym.table.insert(op.ident.clone(), result.as_u32()); Ok(result) }