From fdb04a1a43b65c5842e003cb81b74cced15e4dab Mon Sep 17 00:00:00 2001 From: Goren Barak Date: Tue, 21 Nov 2023 10:06:21 -0500 Subject: [PATCH] Fixed everything, removed compile time and logical errors. --- src/main.rs | 24 +++++++++++++++++++++++- src/parse/ast.rs | 11 ++++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index fdb9362..ea39b7c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,28 @@ use crate::parse::ast::*; pub mod parse; fn main() { - let fc = fasm_codegen(&vec![Expr::VarDefinition(VarDefinition {name: "goren", value: Value::Number(10)}), Expr::MathExpr(Math { left: Value::Var(VarReference { name: "goren"}), right: Value::Number(17), operator: MathOperator::OP_MULT}), Expr::FunDefinition(FunDefinition {name: "adder", contents: vec![Expr::MathExpr(Math {left: Value::Param(ParamReference {param_number: 0}), right: Value::Param(ParamReference {param_number: 1}), operator: MathOperator::OP_ADD})]}), Expr::Breakpoint], true); + let fc = fasm_codegen(& + vec![ + Expr::VarDefinition(VarDefinition {name: "goren", value: Value::Number(10)}), + Expr::MathExpr(Math { + left: &Value::Var(VarReference { name: "goren"}), + right: &Value::Number(17), + operator: MathOperator::OP_MULT + } + ), + Expr::FunDefinition(FunDefinition { + name: "adder", contents: vec![ + Expr::Return(Value::Math( + Math { + left: &Value::Param(ParamReference {param_number: 0}), + right: &Value::Param(ParamReference {param_number: 1}), + operator: MathOperator::OP_ADD + } + )) + ] + }), + Expr::Breakpoint], + true + ); println!("{}", fc); } diff --git a/src/parse/ast.rs b/src/parse/ast.rs index bf20a51..5bf5acb 100644 --- a/src/parse/ast.rs +++ b/src/parse/ast.rs @@ -10,14 +10,14 @@ pub enum Expr<'a> { // MATH EXPRESSION -#[derive(Debug)] +#[derive(Debug, Copy, Clone)] pub struct Math<'a> { - pub left: Value<'a>, - pub right: Value<'a>, + pub left: &'a Value<'a>, + pub right: &'a Value<'a>, pub operator: MathOperator } -#[derive(Debug)] +#[derive(Debug, Copy, Clone)] pub enum MathOperator { OP_ADD, // Addition OP_SUB, // Subtraction @@ -59,6 +59,7 @@ pub struct VarDefinition<'a> { pub value: Value<'a>, } + #[derive(Debug, Copy, Clone)] pub struct VarReference<'a> { pub name: &'a str, @@ -74,7 +75,7 @@ pub enum Value<'a> { Var(VarReference<'a>), Param(ParamReference), Number(u64), - Math(Math), + Math(Math<'a>), } impl<'a> Value<'a> {