Skip to content

Commit

Permalink
Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert-M-Lucas committed Jun 7, 2024
1 parent a53da1c commit aecfff9
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 21 deletions.
22 changes: 18 additions & 4 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 38 additions & 14 deletions build/out.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Binary file modified build/out.o
Binary file not shown.
Binary file modified build/out.out
Binary file not shown.
7 changes: 5 additions & 2 deletions main.why
Original file line number Diff line number Diff line change
@@ -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;
}
}

Expand Down
13 changes: 12 additions & 1 deletion src/root/compiler/compile_evaluable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions todo.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit aecfff9

Please sign in to comment.