From 19548be636bb5267b97ce42d719d1651c7971f04 Mon Sep 17 00:00:00 2001 From: mlokr Date: Tue, 25 Jun 2024 19:55:25 +0200 Subject: [PATCH] adding comments --- hblang/src/codegen.rs | 9 +++++++++ hblang/src/lexer.rs | 2 +- hblang/src/parser.rs | 9 +++++++++ hblang/tests/codegen_tests_comments.txt | 3 +++ 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 hblang/tests/codegen_tests_comments.txt diff --git a/hblang/src/codegen.rs b/hblang/src/codegen.rs index c9f44ca0..30e558c2 100644 --- a/hblang/src/codegen.rs +++ b/hblang/src/codegen.rs @@ -1964,6 +1964,7 @@ impl Codegen { unimplemented!("{:#?}", op) } + E::Comment { .. } => Some(Value::void()), ast => unimplemented!("{:#?}", ast), }?; @@ -2253,6 +2254,9 @@ impl Codegen { fn load_arg(&mut self, flags: parser::IdentFlags, ty: ty::Id, parama: &mut ParamAlloc) -> Loc { let size = self.tys.size_of(ty) as Size; + if size == 0 { + return Loc::default(); + } let (src, dst) = match size { 0 => (Loc::default(), Loc::default()), ..=8 if flags & idfl::REFERENCED == 0 => { @@ -2395,6 +2399,10 @@ impl Codegen { }; } + if size == 0 { + return; + } + src.as_ref().assert_valid(); dst.as_ref().assert_valid(); @@ -2884,6 +2892,7 @@ mod tests { arithmetic => README; variables => README; functions => README; + comments => README; if_statements => README; loops => README; fb_driver => README; diff --git a/hblang/src/lexer.rs b/hblang/src/lexer.rs index 7ce0ebc3..df150192 100644 --- a/hblang/src/lexer.rs +++ b/hblang/src/lexer.rs @@ -1,4 +1,4 @@ -use std::{convert::identity, simd::cmp::SimdPartialEq}; +use std::simd::cmp::SimdPartialEq; const fn ascii_mask(chars: &[u8]) -> u128 { let mut eq = 0; diff --git a/hblang/src/parser.rs b/hblang/src/parser.rs index 909d538b..28ec64dc 100644 --- a/hblang/src/parser.rs +++ b/hblang/src/parser.rs @@ -367,6 +367,10 @@ impl<'a, 'b> Parser<'a, 'b> { self.expect_advance(T::RParen); expr } + T::Comment => Expr::Comment { + pos: token.start, + literal: self.move_str(token), + }, tok => self.report(format_args!("unexpected token: {tok:?}")), }; @@ -577,6 +581,10 @@ macro_rules! generate_expr { generate_expr! { #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Expr<'a> { + Comment { + pos: Pos, + literal: &'a str, + }, Break { pos: Pos, }, @@ -725,6 +733,7 @@ impl<'a> std::fmt::Display for Expr<'a> { } match *self { + Self::Comment { literal, .. } => write!(f, "{literal}"), Self::Mod { path, .. } => write!(f, "@mod(\"{path}\")"), Self::Field { target, field } => write!(f, "{}.{field}", Postfix(target)), Self::Directive { name, args, .. } => { diff --git a/hblang/tests/codegen_tests_comments.txt b/hblang/tests/codegen_tests_comments.txt new file mode 100644 index 00000000..5bd77137 --- /dev/null +++ b/hblang/tests/codegen_tests_comments.txt @@ -0,0 +1,3 @@ +code size: 153 +ret: 0 +status: Ok(())