-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add the
#const
directive and the noemit
attribute
- Loading branch information
Showing
15 changed files
with
189 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use super::*; | ||
|
||
|
||
pub fn parse( | ||
report: &mut diagn::Report, | ||
walker: &mut syntax::TokenWalker, | ||
_header_span: diagn::Span) | ||
-> Result<AstSymbol, ()> | ||
{ | ||
let mut no_emit = false; | ||
|
||
if let Some(_) = walker.maybe_expect(syntax::TokenKind::ParenOpen) | ||
{ | ||
let tk_attrb = walker.expect(report, syntax::TokenKind::Identifier)?; | ||
let attrb = tk_attrb.excerpt.as_ref().unwrap(); | ||
|
||
match attrb.as_ref() | ||
{ | ||
"noemit" => no_emit = true, | ||
_ => | ||
{ | ||
report.error_span( | ||
format!("invalid attribute `{}`", attrb), | ||
tk_attrb.span); | ||
|
||
return Err(()); | ||
} | ||
} | ||
|
||
walker.expect(report, syntax::TokenKind::ParenClose)?; | ||
} | ||
|
||
|
||
let mut decl_span = diagn::Span::new_dummy(); | ||
let mut hierarchy_level = 0; | ||
|
||
while let Some(tk_dot) = walker.maybe_expect(syntax::TokenKind::Dot) | ||
{ | ||
hierarchy_level += 1; | ||
decl_span = decl_span.join(tk_dot.span); | ||
} | ||
|
||
let tk_name = walker.expect(report, syntax::TokenKind::Identifier)?; | ||
let name = tk_name.excerpt.clone().unwrap(); | ||
decl_span = decl_span.join(tk_name.span); | ||
|
||
|
||
walker.expect(report, syntax::TokenKind::Equal)?; | ||
|
||
let expr = expr::parse(report, walker)?; | ||
walker.expect_linebreak(report)?; | ||
|
||
Ok(AstSymbol { | ||
decl_span, | ||
hierarchy_level, | ||
name, | ||
kind: AstSymbolKind::Constant(AstSymbolConstant { | ||
expr, | ||
}), | ||
no_emit, | ||
|
||
item_ref: None, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#ruledef test | ||
{ | ||
ld {x: u8} => 0x55 @ x | ||
} | ||
|
||
#fn add1(x) => x + 1 | ||
|
||
start: | ||
x1 = add1(0x10) | ||
ld x1 | ||
|
||
#const x2 = 0x11 | ||
ld x2 | ||
|
||
#const(noemit) x3 = 0x11 | ||
ld x3 | ||
|
||
loop: | ||
#const y1 = 0x22 | ||
ld y1 | ||
|
||
#const y2 = 0x22 | ||
ld y2 | ||
|
||
#const(noemit) y3 = 0x22 | ||
ld y3 | ||
|
||
.inner: | ||
.z1 = 0x33 | ||
ld .z1 | ||
|
||
#const .z2 = 0x33 | ||
ld .z2 | ||
|
||
#const(noemit) .z3 = 0x33 | ||
ld .z3 | ||
|
||
; command: main.asm -f symbols -o out.txt | ||
; output: out.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
start = 0x0 | ||
x1 = 0x11 | ||
x2 = 0x11 | ||
loop = 0x6 | ||
y1 = 0x22 | ||
y2 = 0x22 | ||
y3.inner = 0xc | ||
y3.z1 = 0x33 | ||
y3.z2 = 0x33 |
8 changes: 8 additions & 0 deletions
8
tests/symbol_constant_simple/err_literal_const_invalid_attrb.asm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ruledef test | ||
{ | ||
ld {x} => 0x55 @ x`8 | ||
} | ||
|
||
|
||
#const(invalid) val = 0xaa ; error: invalid attribute | ||
ld val |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ruledef test | ||
{ | ||
ld {x} => 0x55 @ x`8 | ||
} | ||
|
||
|
||
#const val = 0xaa | ||
ld val ; = 0x55aa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ruledef test | ||
{ | ||
ld {x} => 0x55 @ x`8 | ||
} | ||
|
||
|
||
#const(noemit) val = 0xaa | ||
ld val ; = 0x55aa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ruledef test | ||
{ | ||
ld {x}, {y}, {z} => 0x55 @ x`8 @ y`8 @ z`8 | ||
} | ||
|
||
|
||
x = 0x11 | ||
.y = 0x22 | ||
..z = 0x33 | ||
ld x, .y, ..z ; = 0x55112233 | ||
ld x, x.y, x.y.z ; = 0x55112233 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ruledef test | ||
{ | ||
ld {x}, {y}, {z} => 0x55 @ x`8 @ y`8 @ z`8 | ||
} | ||
|
||
|
||
#const x = 0x11 | ||
#const .y = 0x22 | ||
#const ..z = 0x33 | ||
ld x, .y, ..z ; = 0x55112233 | ||
ld x, x.y, x.y.z ; = 0x55112233 |