Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
playXE committed May 24, 2019
1 parent ebe67c8 commit 24d61a7
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 41 deletions.
29 changes: 19 additions & 10 deletions src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,21 +877,30 @@ impl<'a> EvalCtx<'a>
}
else
{
match &stmt.kind {
StmtKind::CompTime(s) => return self.eval_stmt(s,true),
StmtKind::Block(b) => {
for s in b.iter() {self.eval_stmt(s,false);}
return Some(rc(Const::Void))
match &stmt.kind
{
StmtKind::CompTime(s) => return self.eval_stmt(s, true),
StmtKind::Block(b) =>
{
for s in b.iter()
{
self.eval_stmt(s, false);
}
return Some(rc(Const::Void));
}
StmtKind::Expr(e) => {
if let ExprKind::CompTime(s) = &e.kind { return Some(self.expr(s,true))}
else {
StmtKind::Expr(e) =>
{
if let ExprKind::CompTime(s) = &e.kind
{
return Some(self.expr(s, true));
}
else
{
return None;
}
}
_ => None
_ => None,
}

}
}

Expand Down
6 changes: 1 addition & 5 deletions src/gccjit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,6 @@ impl<'a> Codegen<'a>
}
let ty = if struct_.union
{

self.ctx
.new_union_type(None, &str(struct_.name).to_string(), &fields)
}
Expand Down Expand Up @@ -1376,7 +1375,6 @@ impl<'a> Codegen<'a>

if this.is_some()
{

let expr = this.clone().unwrap().clone();
let ty = self.get_id_type(expr.id);
let val = if !ty.is_ptr()
Expand All @@ -1387,7 +1385,7 @@ impl<'a> Codegen<'a>
id: expr.id,
kind: ExprKind::AddressOf(expr),
});
let val = self.ctx.new_cast(None,val,cty);
let val = self.ctx.new_cast(None, val, cty);
val
}
else
Expand Down Expand Up @@ -1461,12 +1459,10 @@ impl<'a> Codegen<'a>
&params,
);
}

else if let Some(var) = self.variables.get(&name.name())
{
var.lval
}

else
{
panic!();
Expand Down
7 changes: 3 additions & 4 deletions src/semantic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,6 @@ impl<'a> SemCheck<'a>
{
let _id = stmt.id;
match &stmt.kind

{
StmtKind::CFor(var, cond, then, body) =>
{
Expand Down Expand Up @@ -838,13 +837,13 @@ impl<'a> SemCheck<'a>
{
match &expr.kind
{
ExprKind::CompTime(e) => {
ExprKind::CompTime(e) =>
{
let ty = self.tc_expr(e);
let ty = self.infer_type(&ty);
self.types.insert(expr.id,ty.clone());
self.types.insert(expr.id, ty.clone());

return ty;

}
ExprKind::New(ty) =>
{
Expand Down
40 changes: 23 additions & 17 deletions src/syntax/ast/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl Display for ExprKind
{
match self
{
ExprKind::MacroCall(name,_) => write!(f,"{}!()",name),
ExprKind::MacroCall(name, _) => write!(f, "{}!()", name),
ExprKind::CompTime(e) => write!(f, "constexpr {}", e),
ExprKind::New(val) => write!(f, "new {}", val),
ExprKind::Int(i, base, _) => match base
Expand Down Expand Up @@ -216,25 +216,31 @@ impl Display for Global
}
}

impl Display for Macro {
fn fmt(&self,f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f,"macro {}!(",self.name)?;
for (i,var) in self.args.iter().enumerate() {
write!(f,"{}",var)?;
if i != self.args.len() - 1 {
write!(f,",")?;
impl Display for Macro
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
{
write!(f, "macro {}!(", self.name)?;
for (i, var) in self.args.iter().enumerate()
{
write!(f, "{}", var)?;
if i != self.args.len() - 1
{
write!(f, ",")?;
}
}
write!(f,") ")?;
write!(f,"{{\n")?;
for tok in self.body.iter() {
match tok {
MacroToken::Token(tok) => write!(f," {}",tok.name())?,
MacroToken::Var(var) => write!(f," ${}",var)?,
MacroToken::VarArgs => write!(f,"...")?,
write!(f, ") ")?;
write!(f, "{{\n")?;
for tok in self.body.iter()
{
match tok
{
MacroToken::Token(tok) => write!(f, " {}", tok.name())?,
MacroToken::Var(var) => write!(f, " ${}", var)?,
MacroToken::VarArgs => write!(f, "...")?,
}
}
write!(f,"\n}}")
write!(f, "\n}}")
}
}

Expand All @@ -251,7 +257,7 @@ impl Display for Elem
Elem::ConstExpr { name, expr, .. } => write!(f, "constexpr {} = {}", name, expr),
Elem::Global(g) => write!(f, "{}", g),
Elem::Link(l) => write!(f, "link \"{}\" ", l),
Elem::Macro(m) => write!(f,"{}",m),
Elem::Macro(m) => write!(f, "{}", m),
_ => write!(f, ""),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/syntax/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ impl Expr
#[derive(Clone, Debug)]
pub enum ExprKind
{
MacroCall(Name,Vec<Vec<Token>>),
MacroCall(Name, Vec<Vec<Token>>),
CompTime(Box<Expr>),
Unary(String, Box<Expr>),
Binary(String, Box<Expr>, Box<Expr>),
Expand Down
3 changes: 2 additions & 1 deletion src/syntax/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ impl Lexer
{
return self.read_identifier();
}
else if ch == Some('$') {
else if ch == Some('$')
{
self.read_char();
return Ok(self.build_token(TokenKind::Dollar));
}
Expand Down
5 changes: 2 additions & 3 deletions src/syntax/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,6 @@ impl<'a> Parser<'a>
TokenKind::LBracket => gen_t_tree!(TokenKind::LBracket, TokenKind::RBracket, t),
TokenKind::Dollar =>
{

let name = self.expect_identifier()?;
if args.contains(&name)
{
Expand Down Expand Up @@ -990,8 +989,8 @@ impl<'a> Parser<'a>
let mut body: Vec<MacroToken> = vec![];
loop
{

if self.token.is(TokenKind::RBrace) {
if self.token.is(TokenKind::RBrace)
{
self.advance_token()?;
break;
}
Expand Down

0 comments on commit 24d61a7

Please sign in to comment.