fixing constant fmt newline preservation
This commit is contained in:
parent
b8032aa840
commit
bedffa9b32
|
@ -324,11 +324,11 @@ note: values of global variables are evaluated at compile time
|
||||||
|
|
||||||
#### constants
|
#### constants
|
||||||
```hb
|
```hb
|
||||||
$some_const := 34
|
main := fn(): u32 {
|
||||||
|
|
||||||
main := fn(): uint {
|
|
||||||
return some_const + 35
|
return some_const + 35
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$some_const := 34
|
||||||
```
|
```
|
||||||
|
|
||||||
#### directives
|
#### directives
|
||||||
|
|
|
@ -399,7 +399,12 @@ impl<'a, 'b> Parser<'a, 'b> {
|
||||||
},
|
},
|
||||||
T::Ident | T::CtIdent => {
|
T::Ident | T::CtIdent => {
|
||||||
let (id, is_first) = self.resolve_ident(token);
|
let (id, is_first) = self.resolve_ident(token);
|
||||||
E::Ident { pos, is_ct: token.kind == T::CtIdent, id, is_first }
|
E::Ident {
|
||||||
|
pos: pos - (token.kind == T::CtIdent) as Pos,
|
||||||
|
is_ct: token.kind == T::CtIdent,
|
||||||
|
id,
|
||||||
|
is_first,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
T::Under => E::Wildcard { pos },
|
T::Under => E::Wildcard { pos },
|
||||||
T::If => E::If {
|
T::If => E::If {
|
||||||
|
|
|
@ -2517,7 +2517,7 @@ impl<'a> Codegen<'a> {
|
||||||
match decl.expand() {
|
match decl.expand() {
|
||||||
ty::Kind::NEVER => Value::NEVER,
|
ty::Kind::NEVER => Value::NEVER,
|
||||||
ty::Kind::Global(global) => self.gen_global(global),
|
ty::Kind::Global(global) => self.gen_global(global),
|
||||||
ty::Kind::Const(cnst) => self.gen_const(cnst),
|
ty::Kind::Const(cnst) => self.gen_const(cnst, ctx),
|
||||||
_ => Some(Value::new(Nid::MAX).ty(decl)),
|
_ => Some(Value::new(Nid::MAX).ty(decl)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2636,7 +2636,7 @@ impl<'a> Codegen<'a> {
|
||||||
{
|
{
|
||||||
ty::Kind::NEVER => Value::NEVER,
|
ty::Kind::NEVER => Value::NEVER,
|
||||||
ty::Kind::Global(global) => self.gen_global(global),
|
ty::Kind::Global(global) => self.gen_global(global),
|
||||||
ty::Kind::Const(cnst) => self.gen_const(cnst),
|
ty::Kind::Const(cnst) => self.gen_const(cnst, ctx),
|
||||||
v => Some(Value::new(Nid::MAX).ty(v.compress())),
|
v => Some(Value::new(Nid::MAX).ty(v.compress())),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -3783,14 +3783,14 @@ impl<'a> Codegen<'a> {
|
||||||
Some(Value::ptr(value).ty(gl.ty))
|
Some(Value::ptr(value).ty(gl.ty))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gen_const(&mut self, cnst: ty::Const) -> Option<Value> {
|
fn gen_const(&mut self, cnst: ty::Const, ctx: Ctx) -> Option<Value> {
|
||||||
let c = &self.tys.ins.consts[cnst];
|
let c = &self.tys.ins.consts[cnst];
|
||||||
let f = &self.files[c.file.index()];
|
let f = &self.files[c.file.index()];
|
||||||
let Expr::BinOp { left, right, .. } = c.ast.get(f) else { unreachable!() };
|
let Expr::BinOp { left, right, .. } = c.ast.get(f) else { unreachable!() };
|
||||||
|
|
||||||
left.find_pattern_path(c.name, right, |expr, is_ct| {
|
left.find_pattern_path(c.name, right, |expr, is_ct| {
|
||||||
debug_assert!(is_ct);
|
debug_assert!(is_ct);
|
||||||
self.expr(expr)
|
self.expr_ctx(expr, ctx)
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|_| unreachable!())
|
.unwrap_or_else(|_| unreachable!())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
main:
|
main:
|
||||||
LI64 r1, 69d
|
LI32 r1, 69w
|
||||||
JALA r0, r31, 0a
|
JALA r0, r31, 0a
|
||||||
code size: 29
|
code size: 25
|
||||||
ret: 69
|
ret: 69
|
||||||
status: Ok(())
|
status: Ok(())
|
||||||
|
|
|
@ -0,0 +1,80 @@
|
||||||
|
foo:
|
||||||
|
ADDI64 r254, r254, -200d
|
||||||
|
ST r31, r254, 80a, 120h
|
||||||
|
ADDI64 r32, r254, 64d
|
||||||
|
LRA r3, r0, :some_file
|
||||||
|
JAL r31, r0, :get
|
||||||
|
ST r1, r254, 64a, 16h
|
||||||
|
LI8 r33, 0b
|
||||||
|
LD r34, r254, 64a, 1h
|
||||||
|
ANDI r34, r34, 255d
|
||||||
|
ANDI r33, r33, 255d
|
||||||
|
JNE r34, r33, :0
|
||||||
|
ADDI64 r35, r254, 48d
|
||||||
|
ST r33, r254, 48a, 1h
|
||||||
|
LD r1, r35, 0a, 16h
|
||||||
|
JMP :1
|
||||||
|
0: LI8 r36, 1b
|
||||||
|
LI64 r37, 4d
|
||||||
|
LD r38, r254, 72a, 8h
|
||||||
|
JNE r38, r37, :2
|
||||||
|
ADDI64 r39, r254, 32d
|
||||||
|
ST r36, r254, 32a, 1h
|
||||||
|
LI64 r40, 2d
|
||||||
|
ST r40, r254, 40a, 8h
|
||||||
|
LD r1, r39, 0a, 16h
|
||||||
|
JMP :1
|
||||||
|
2: LRA r41, r0, :MAGIC
|
||||||
|
LD r42, r41, 0a, 8h
|
||||||
|
JNE r42, r38, :3
|
||||||
|
ADDI64 r43, r254, 16d
|
||||||
|
ST r36, r254, 16a, 1h
|
||||||
|
LI64 r44, 0d
|
||||||
|
ST r44, r254, 24a, 8h
|
||||||
|
LD r1, r43, 0a, 16h
|
||||||
|
JMP :1
|
||||||
|
3: ADDI64 r45, r254, 0d
|
||||||
|
ST r33, r254, 0a, 1h
|
||||||
|
LD r1, r45, 0a, 16h
|
||||||
|
1: LD r31, r254, 80a, 120h
|
||||||
|
ADDI64 r254, r254, 200d
|
||||||
|
JALA r0, r31, 0a
|
||||||
|
get:
|
||||||
|
ADDI64 r254, r254, -32d
|
||||||
|
LD r3, r3, 0a, 1h
|
||||||
|
LRA r5, r0, :MAGIC
|
||||||
|
ANDI r9, r3, 255d
|
||||||
|
LD r8, r5, 0a, 8h
|
||||||
|
JNE r8, r9, :0
|
||||||
|
LI8 r2, 1b
|
||||||
|
ADDI64 r1, r254, 16d
|
||||||
|
ST r2, r254, 16a, 1h
|
||||||
|
ST r8, r254, 24a, 8h
|
||||||
|
LD r1, r1, 0a, 16h
|
||||||
|
JMP :1
|
||||||
|
0: ADDI64 r7, r254, 0d
|
||||||
|
LI8 r9, 0b
|
||||||
|
ST r9, r254, 0a, 1h
|
||||||
|
LD r1, r7, 0a, 16h
|
||||||
|
1: ADDI64 r254, r254, 32d
|
||||||
|
JALA r0, r31, 0a
|
||||||
|
main:
|
||||||
|
ADDI64 r254, r254, -48d
|
||||||
|
ST r31, r254, 16a, 32h
|
||||||
|
ADDI64 r32, r254, 0d
|
||||||
|
JAL r31, r0, :foo
|
||||||
|
ST r1, r254, 0a, 16h
|
||||||
|
LI8 r33, 0b
|
||||||
|
LD r34, r254, 0a, 1h
|
||||||
|
ANDI r34, r34, 255d
|
||||||
|
ANDI r33, r33, 255d
|
||||||
|
JNE r34, r33, :0
|
||||||
|
LI64 r1, 100d
|
||||||
|
JMP :1
|
||||||
|
0: LD r1, r254, 8a, 8h
|
||||||
|
1: LD r31, r254, 16a, 32h
|
||||||
|
ADDI64 r254, r254, 48d
|
||||||
|
JALA r0, r31, 0a
|
||||||
|
code size: 768
|
||||||
|
ret: 0
|
||||||
|
status: Ok(())
|
|
@ -12,18 +12,18 @@ main:
|
||||||
LI8 r35, 0b
|
LI8 r35, 0b
|
||||||
LD r36, r254, 2a, 1h
|
LD r36, r254, 2a, 1h
|
||||||
CP r1, r32
|
CP r1, r32
|
||||||
ANDI r37, r37, 255d
|
|
||||||
ANDI r1, r1, 255d
|
ANDI r1, r1, 255d
|
||||||
|
ANDI r34, r34, 255d
|
||||||
CMPU r37, r1, r34
|
CMPU r37, r1, r34
|
||||||
CMPUI r37, r37, 0d
|
CMPUI r37, r37, 0d
|
||||||
ANDI r38, r38, 255d
|
|
||||||
ANDI r36, r36, 255d
|
ANDI r36, r36, 255d
|
||||||
|
ANDI r35, r35, 255d
|
||||||
CMPU r38, r36, r35
|
CMPU r38, r36, r35
|
||||||
CMPUI r38, r38, 0d
|
CMPUI r38, r38, 0d
|
||||||
LD r39, r254, 0a, 1h
|
LD r39, r254, 0a, 1h
|
||||||
AND r40, r38, r37
|
AND r40, r38, r37
|
||||||
ANDI r41, r41, 255d
|
|
||||||
ANDI r39, r39, 255d
|
ANDI r39, r39, 255d
|
||||||
|
ANDI r35, r35, 255d
|
||||||
CMPU r41, r39, r35
|
CMPU r41, r39, r35
|
||||||
CMPUI r41, r41, 0d
|
CMPUI r41, r41, 0d
|
||||||
AND r42, r41, r40
|
AND r42, r41, r40
|
||||||
|
|
Loading…
Reference in a new issue