From aecfff9b31a0a4f041ebdcaf52f4edd36abe7303 Mon Sep 17 00:00:00 2001 From: Robert-M-Lucas Date: Fri, 7 Jun 2024 22:12:26 +0100 Subject: [PATCH] Testing --- .idea/workspace.xml | 22 +++++++++-- build/out.asm | 52 ++++++++++++++++++------- build/out.o | Bin 704 -> 784 bytes build/out.out | Bin 16512 -> 16536 bytes main.why | 7 +++- src/root/compiler/compile_evaluable.rs | 13 ++++++- todo.txt | 6 +++ 7 files changed, 79 insertions(+), 21 deletions(-) create mode 100644 todo.txt diff --git a/.idea/workspace.xml b/.idea/workspace.xml index ff53f32..3e680f9 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -7,8 +7,13 @@ - + + + + + + @@ -362,6 +375,7 @@ - \ No newline at end of file diff --git a/build/out.asm b/build/out.asm index b8b4c39..556c2a7 100644 --- a/build/out.asm +++ b/build/out.asm @@ -2,20 +2,6 @@ section .text -_1: - push rbp - mov rbp, rsp - - mov rax, qword [rbp+16] - mov qword [rbp-8], rax - mov rax, qword [rbp+24] - mov qword [rbp-16], rax - mov rax, qword [rbp-8] - add rax, qword [rbp-16] - mov qword [rbp+32], rax - leave - ret - main: push rbp mov rbp, rsp @@ -35,3 +21,41 @@ main: leave ret +_1: + push rbp + mov rbp, rsp + + mov rax, qword [rbp+16] + mov qword [rbp-8], rax + mov rax, qword [rbp+24] + mov qword [rbp-16], rax + mov rax, qword [rbp-8] + mov qword [rbp-40], rax + mov rax, qword [rbp-16] + mov qword [rbp-48], rax + sub rsp, 48 + call _2 + add rsp, 48 + mov rax, qword [rbp-32] + mov qword [rbp+32], rax + leave + ret + +_2: + push rbp + mov rbp, rsp + + mov rax, qword [rbp+16] + mov qword [rbp-16], rax + mov rax, qword [rbp+24] + mov qword [rbp-24], rax + mov rax, qword [rbp-16] + add rax, qword [rbp-24] + mov qword [rbp-8], rax + mov qword [rbp-32], 1 + mov rax, qword [rbp-8] + add rax, qword [rbp-32] + mov qword [rbp+32], rax + leave + ret + diff --git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U~G&dh7T4ACS5q=YB4 XI%sohm_bAqO}2C}XFN5z&_NvlqX%sl diff --git a/main.why b/main.why index af803de..09c2ada 100644 --- a/main.why +++ b/main.why @@ -1,7 +1,10 @@ - impl int { fn sub(lhs: int, rhs: int) -> int { - return lhs + rhs + rhs; + return lhs == rhs; + } + + fn eq(lhs: int, rhs: int) -> int { + return lhs + rhs + 1; } } diff --git a/src/root/compiler/compile_evaluable.rs b/src/root/compiler/compile_evaluable.rs index 237cc90..53a03ba 100644 --- a/src/root/compiler/compile_evaluable.rs +++ b/src/root/compiler/compile_evaluable.rs @@ -217,7 +217,18 @@ pub fn compile_evaluable_type_only( let tid = literal.literal().default_type(); TypeRef::new(tid.clone(), Indirection(0)) } - EvaluableTokens::InfixOperator(_, _, _) => todo!(), + EvaluableTokens::InfixOperator(lhs, op, _) => { + if op.is_prefix_opt_t() { + return Err(WErr::n(EvalErrs::FoundPrefixNotInfixOp(op.operator().to_str().to_string()), op.location().clone())); + } + + // let (mut code, lhs) = compile_evaluable(fid, lhs, local_variables, global_table, function_calls)?; + let lhs_type = compile_evaluable_type_only(fid, lhs, local_variables, global_table, function_calls)?; + // code += "\n"; + let op_fn = global_table.get_operator_function(*lhs_type.type_id(), op)?; + let signature = global_table.get_function_signature(op_fn); + signature.return_type().as_ref().unwrap().clone() + }, EvaluableTokens::PrefixOperator(_, _) => todo!(), EvaluableTokens::DynamicAccess(_, _) => todo!(), // Accessed methods must be called EvaluableTokens::StaticAccess(_, n) => return Err(WErr::n(NRErrors::CannotFindConstantAttribute(n.name().clone()), n.location().clone())), // Accessed methods must be called diff --git a/todo.txt b/todo.txt new file mode 100644 index 0000000..aaec117 --- /dev/null +++ b/todo.txt @@ -0,0 +1,6 @@ +Add support for multiple functions with the same name but different signatures +Allow operators to be both prefix and infix i.e. -a or a - b +Fix evaluables such as (a + b) or (a + b) + c or a + b + c not working +Add rich parser errors +Add all errors in +All other todos, of course \ No newline at end of file