diff --git a/Cargo.toml b/Cargo.toml index 1196dee..0abaee5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,7 @@ members = [ "fir", "oir", "scir", - "datatable", + "datatable", "repr", ] resolver = "2" diff --git a/bootstrap/makefile b/bootstrap/makefile index 17e328d..0654872 100644 --- a/bootstrap/makefile +++ b/bootstrap/makefile @@ -1,5 +1,7 @@ .ty/token.o: ty obj src/token.ty +.PHONY: clean clean: rm -rf .ty + mkdir .ty diff --git a/bootstrap/repr/integration.c b/bootstrap/repr/integration.c new file mode 100644 index 0000000..f56d4aa --- /dev/null +++ b/bootstrap/repr/integration.c @@ -0,0 +1,6 @@ +#include + +uint64_t add(uint64_t left, uint64_t right) { + return left + right; +} + diff --git a/bootstrap/repr/integration.ty b/bootstrap/repr/integration.ty new file mode 100644 index 0000000..2921c0c --- /dev/null +++ b/bootstrap/repr/integration.ty @@ -0,0 +1,4 @@ +pub const add = fn(x: u64, y: u64) u64 { + return x + y +} + diff --git a/bootstrap/repr/main.c b/bootstrap/repr/main.c new file mode 100644 index 0000000..8736cd7 --- /dev/null +++ b/bootstrap/repr/main.c @@ -0,0 +1,10 @@ +#include +#include + +extern uint64_t add(uint64_t, uint64_t); + +int main() { + printf("Hello"); + printf("Hello %lu", add(2, 7)); + puts("Hello"); +} diff --git a/bootstrap/repr/makefile b/bootstrap/repr/makefile new file mode 100644 index 0000000..3ab941f --- /dev/null +++ b/bootstrap/repr/makefile @@ -0,0 +1,25 @@ +all: .ty/main.o .ty/integrationc.o .ty/integration.o .ty/repr-37b621cda8f778ea.repr.c0ded12167d2f276-cgu.0.rcgu.o + 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 + touch .ty/all + +.ty/main.o: main.c + cc -c main.c -o .ty/main.o -O3 + +.ty/integrationc.o: integration.c + cc -c integration.c -o .ty/integrationc.o -O3 + +.ty/integration.o: integration.ty + ty obj integration.ty + +.ty/repr-37b621cda8f778ea.repr.c0ded12167d2f276-cgu.0.rcgu.o: ../../target/release/librepr.rlib + cd .ty && ar x ../../../target/release/librepr.rlib + +../../target/release/librepr.rlib: ../../repr/src/lib.rs + cd ../.. && cargo build -p repr --release + +.PHONY: clean +clean: + rm -rf .ty + mkdir .ty diff --git a/fir/src/lib.rs b/fir/src/lib.rs index 36c7606..0ad10a5 100644 --- a/fir/src/lib.rs +++ b/fir/src/lib.rs @@ -45,17 +45,27 @@ impl Fir { type_tables: &Vec, oir: &mut Oir, ) -> Function { - let mut sig = Signature::new(CallConv::SystemV); + let sig = Signature::new(CallConv::Cold); let name = UserFuncName::user(namespace, index); // todo:: types need to be worked out, params and returns defined - func_def - .args - .iter() - .for_each(|_x| sig.params.push(AbiParam::new(I64))); - sig.returns.push(AbiParam::new(I64)); let mut func = Function::with_name_signature(name, sig); let mut builder = FunctionBuilder::new(&mut func, ctx); let root_block = builder.create_block(); + func_def.args.iter().for_each(|x| { + let z = self + .recurse( + x.as_ref().as_ref(), + &mut builder, + dtbl, + scopes, + type_tables, + 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)); builder.append_block_params_for_function_params(root_block); builder.switch_to_block(root_block); let _result = self.recurse( @@ -70,6 +80,19 @@ impl Fir { builder.finalize(); func } + pub fn handle_arg_init( + &mut self, + op: &SymbolInit, + builder: &mut FunctionBuilder, + dtbl: &DataTable, + scopes: &Vec, + type_tables: &Vec, + oir: &mut Oir, + ) -> ResultFir { + let result = self.add_var(); + self.sym.table.insert(op.ident.clone(), result.as_u32()); + Ok(result) + } pub fn handle_const_init( &mut self, op: &Initialization, @@ -265,6 +288,9 @@ impl Fir { TypeTree::ConstInit(op) => { self.handle_const_init(&op, builder, dtbl, scopes, type_tables, oir) } + TypeTree::ArgInit(op) => { + self.handle_arg_init(&op, builder, dtbl, scopes, type_tables, oir) + } TypeTree::SymbolAccess(op) => { self.handle_sym_access(&op, dtbl, scopes, type_tables, oir, builder) } diff --git a/linter/src/lib.rs b/linter/src/lib.rs index c78a7b1..abfd644 100644 --- a/linter/src/lib.rs +++ b/linter/src/lib.rs @@ -1205,7 +1205,21 @@ mod tests { ); } #[test] - fn it_should_handle_basic_types() { + fn it_should_handle_func_args() { + const TEST_STR: &'static str = "const add = fn(x: u64, y: u64) u64 { return x + y } + "; + let lexer = TLexer::new(TEST_STR); + let mut parser = Parser::new(lexer); + let result = parser.all(); + let mut tts = vec![]; + let mut scps = vec![]; + let mut linter = LintSource::new(TEST_STR, &mut scps, &mut tts); + let _ = linter.lint_check(&result.unwrap()); + + assert!(linter.issues.len() == 0); + } + #[test] + fn it_should_handle_global_data() { const TEST_STR: &'static str = "const val: usize = 2 const main = fn() void { return 7 + val } "; diff --git a/repr/Cargo.toml b/repr/Cargo.toml new file mode 100644 index 0000000..62df674 --- /dev/null +++ b/repr/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "repr" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/repr/src/lib.rs b/repr/src/lib.rs new file mode 100644 index 0000000..eeead7f --- /dev/null +++ b/repr/src/lib.rs @@ -0,0 +1,15 @@ +#[no_mangle] +pub extern "C" fn add(left: u64, right: u64) -> u64 { + left + right +} + +#[no_mangle] +pub fn make_binop(thing: u64, small: char, big: u64) -> BinOp { + return BinOp { thing, small, big }; +} + +pub struct BinOp { + thing: u64, + small: char, + big: u64, +}