Fixed everything, removed compile time and logical errors.
This commit is contained in:
parent
d9bb758569
commit
fdb04a1a43
24
src/main.rs
24
src/main.rs
|
@ -7,6 +7,28 @@ use crate::parse::ast::*;
|
||||||
pub mod parse;
|
pub mod parse;
|
||||||
|
|
||||||
fn main() {
|
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);
|
println!("{}", fc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,14 +10,14 @@ pub enum Expr<'a> {
|
||||||
|
|
||||||
// MATH EXPRESSION
|
// MATH EXPRESSION
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub struct Math<'a> {
|
pub struct Math<'a> {
|
||||||
pub left: Value<'a>,
|
pub left: &'a Value<'a>,
|
||||||
pub right: Value<'a>,
|
pub right: &'a Value<'a>,
|
||||||
pub operator: MathOperator
|
pub operator: MathOperator
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub enum MathOperator {
|
pub enum MathOperator {
|
||||||
OP_ADD, // Addition
|
OP_ADD, // Addition
|
||||||
OP_SUB, // Subtraction
|
OP_SUB, // Subtraction
|
||||||
|
@ -59,6 +59,7 @@ pub struct VarDefinition<'a> {
|
||||||
pub value: Value<'a>,
|
pub value: Value<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub struct VarReference<'a> {
|
pub struct VarReference<'a> {
|
||||||
pub name: &'a str,
|
pub name: &'a str,
|
||||||
|
@ -74,7 +75,7 @@ pub enum Value<'a> {
|
||||||
Var(VarReference<'a>),
|
Var(VarReference<'a>),
|
||||||
Param(ParamReference),
|
Param(ParamReference),
|
||||||
Number(u64),
|
Number(u64),
|
||||||
Math(Math),
|
Math(Math<'a>),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Value<'a> {
|
impl<'a> Value<'a> {
|
||||||
|
|
Loading…
Reference in a new issue