From 0fd3aee6b584f82c69b7af55dab0b50d80aaa498 Mon Sep 17 00:00:00 2001 From: Erin Date: Wed, 7 Jun 2023 15:17:45 +0200 Subject: [PATCH] Assembler program --- hbasm/src/lib.rs | 9 +++++++++ hbasm/src/main.rs | 15 +++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/hbasm/src/lib.rs b/hbasm/src/lib.rs index c73feff8..6c9125f5 100644 --- a/hbasm/src/lib.rs +++ b/hbasm/src/lib.rs @@ -1,3 +1,4 @@ +use std::fmt::{Display, Formatter}; use { logos::{Lexer, Logos, Span}, std::{ops::Range, str::FromStr}, @@ -58,6 +59,14 @@ pub struct Error { span: Span, } +impl Display for Error { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!(f, "Error {:?} at {:?}", self.kind, self.span) + } +} + +impl std::error::Error for Error {} + macro_rules! expect_matches { ($self:expr, $($pat:pat),* $(,)?) => {$( let $pat = $self.next()? diff --git a/hbasm/src/main.rs b/hbasm/src/main.rs index 171cfe28..bdb6a7a7 100644 --- a/hbasm/src/main.rs +++ b/hbasm/src/main.rs @@ -1,3 +1,14 @@ -fn main() { - // TODO +use std::{ + error::Error, + io::{stdin, stdout, Read, Write}, +}; + +fn main() -> Result<(), Box> { + let mut code = String::new(); + stdin().read_to_string(&mut code)?; + + let mut buf = vec![]; + hbasm::assembly(&code, &mut buf)?; + stdout().write_all(&buf)?; + Ok(()) }