Evaluating expressions

This commit is contained in:
2022-03-16 23:13:02 -05:00
parent 683ff3095e
commit ab2b0d3f86
3 changed files with 202 additions and 1 deletions
+8 -1
View File
@@ -5,6 +5,7 @@ use pest::iterators::Pair;
use vcore::opcodes::Opcode;
use crate::vasm_parser::Rule;
use std::fmt::{Display, Formatter};
/// A non-opcode directive to the assembler
#[derive(Debug, PartialEq, Copy, Clone)]
@@ -60,7 +61,7 @@ pub enum Node<'a> {
RelativeLabel(&'a str),
AbsoluteOffset(i32),
RelativeOffset(i32),
String(String),
String(String), // TODO: this shouldn't exist
Expr(Box<Node<'a>>, Vec<(Operator, Node<'a>)>),
}
@@ -147,6 +148,12 @@ impl<'a> From<Pair<'a, Rule>> for Node<'a> {
#[derive(Debug, PartialEq, Clone)]
pub struct Label<'a>(pub &'a str);
impl<'a> Display for Label<'a> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Debug, PartialEq, Clone)]
pub enum VASMLine<'a> {
Instruction(Option<Label<'a>>, Opcode, Option<Node<'a>>),