Compare commits
No commits in common. "fb098123d5b7e72e221b27ca7e6223d25389951c" and "102df4a53134e9698cdb8f7cfc836fcddfd2519b" have entirely different histories.
fb098123d5
...
102df4a531
|
@ -8,12 +8,19 @@ macro_rules! fasm_codegen {
|
|||
fasm_codegen($exprs, true)
|
||||
};
|
||||
|
||||
(function: $exprs:expr) => {
|
||||
(fun: $exprs:expr) => {
|
||||
fasm_codegen($exprs, false)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn temp(counter: u64) -> String {
|
||||
format!("tmp{:?}", counter)
|
||||
}
|
||||
|
||||
pub fn fasm_codegen(exprs: &Vec<Expr>, not_a_function: bool) -> String {
|
||||
// A counter for how many temporary variables have been created. This is used to create new ones. The new ones will be called tmp1, tmp2, etc.
|
||||
let mut tmp_counter: u64 = 0;
|
||||
|
||||
// Define asm_func, used for functions.
|
||||
let mut asm_func = String::new();
|
||||
// Define asm_data, used for variables.
|
||||
|
@ -159,6 +166,7 @@ pub fn fasm_codegen(exprs: &Vec<Expr>, not_a_function: bool) -> String {
|
|||
Expr::Breakpoint => {
|
||||
// Write the interrupt for a debugger breakpoint.
|
||||
asm_start.push_str("\tint3\n");
|
||||
asm_start.push_str("\txor rax, rax\n");
|
||||
},
|
||||
|
||||
// Return something from a function.
|
||||
|
@ -166,7 +174,8 @@ pub fn fasm_codegen(exprs: &Vec<Expr>, not_a_function: bool) -> String {
|
|||
// Do the operation that should later be returned.
|
||||
asm_start.push_str(fasm_codegen!(fun: &e).as_str());
|
||||
// Move the return value to rbp + 8.
|
||||
// [rbp + 8] ← return_value
|
||||
asm_start.push_str("mov [rbp + 8], rax");
|
||||
// 8(%rbp) ← return_value
|
||||
},
|
||||
|
||||
// A function defenition.
|
||||
|
@ -174,7 +183,7 @@ pub fn fasm_codegen(exprs: &Vec<Expr>, not_a_function: bool) -> String {
|
|||
// In x86-64 assembly, a function is defined as <function_name>:. Push this to the `asm_func`.
|
||||
asm_func.push_str(format!("{}:\n", e.name).as_str());
|
||||
// Call the function itself specifying that you are defining a function, and push the returned value to `asm_func`.
|
||||
asm_func.push_str(fasm_codegen!(function: &e.contents).as_str());
|
||||
asm_func.push_str(fasm_codegen!(fun: &e.contents).as_str());
|
||||
// Use the ret instruction to return from the procedure.
|
||||
asm_func.push_str("\tret\n");
|
||||
},
|
||||
|
@ -204,13 +213,15 @@ pub fn fasm_codegen(exprs: &Vec<Expr>, not_a_function: bool) -> String {
|
|||
asm_func.push_str("\tret\n");
|
||||
|
||||
}
|
||||
|
||||
_ => unsafe {
|
||||
// Write some data I randomly typed to your memory because don't going around playing with something that I haven't implemented yet.
|
||||
let mut ptr = 0x00 as *mut f64;
|
||||
::std::ptr::write(ptr, 124010240120401240.12410240124120401240);
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use std::rc::Rc;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Expr<'a> {
|
||||
MathExpr(Math<'a>),
|
||||
|
@ -78,24 +80,11 @@ pub struct ParamReference {
|
|||
// CONDITIONS
|
||||
|
||||
#[derive(Debug)]
|
||||
<<<<<<< HEAD
|
||||
pub struct IfCondition<'a> {
|
||||
pub left: Expr<'a>,
|
||||
pub right: Expr<'a>,
|
||||
pub cond: COND_OP,
|
||||
pub action: Vec<Expr<'a>>
|
||||
=======
|
||||
pub struct IfStatement<'a> {
|
||||
pub condition: Condition<'a>,
|
||||
pub if_true: Vec<Expr<'a>>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Condition<'a> {
|
||||
pub left: Value<'a>,
|
||||
pub right: Value<'a>,
|
||||
pub between: COND_OP,
|
||||
>>>>>>> parent of 2f942d3 (Added if statements, and made `Expr::Return` work.)
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
Loading…
Reference in a new issue