adding comments

This commit is contained in:
mlokr 2024-06-25 19:55:25 +02:00
parent 876690319f
commit 93deeee6b9
No known key found for this signature in database
GPG key ID: DEA147DDEE644993
4 changed files with 22 additions and 1 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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, .. } => {

View file

@ -0,0 +1,3 @@
code size: 153
ret: 0
status: Ok(())