-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
206 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use crate::*; | ||
|
||
|
||
#[derive(Clone, Debug)] | ||
pub struct AstDirectiveAssert | ||
{ | ||
pub header_span: diagn::Span, | ||
pub condition_expr: expr::Expr, | ||
} | ||
|
||
|
||
pub fn parse( | ||
report: &mut diagn::Report, | ||
walker: &mut syntax::Walker, | ||
header_span: diagn::Span) | ||
-> Result<AstDirectiveAssert, ()> | ||
{ | ||
let expr = expr::parse(report, walker)?; | ||
|
||
walker.expect_linebreak(report)?; | ||
|
||
Ok(AstDirectiveAssert { | ||
header_span, | ||
condition_expr: expr, | ||
}) | ||
} |
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,41 @@ | ||
use crate::*; | ||
|
||
|
||
pub fn resolve_assert( | ||
report: &mut diagn::Report, | ||
opts: &asm::AssemblyOptions, | ||
fileserver: &mut dyn util::FileServer, | ||
ast_assert: &asm::AstDirectiveAssert, | ||
decls: &asm::ItemDecls, | ||
defs: &mut asm::ItemDefs, | ||
ctx: &asm::ResolverContext) | ||
-> Result<asm::ResolutionState, ()> | ||
{ | ||
if !ctx.is_last_iteration | ||
{ | ||
return Ok(asm::ResolutionState::Unresolved); | ||
} | ||
|
||
let value = asm::resolver::eval( | ||
report, | ||
opts, | ||
fileserver, | ||
decls, | ||
defs, | ||
ctx, | ||
&mut expr::EvalContext::new(), | ||
&ast_assert.condition_expr)?; | ||
|
||
let satisfied = value.expect_bool( | ||
report, | ||
ast_assert.condition_expr.span())?; | ||
|
||
if !satisfied | ||
{ | ||
report.error_span( | ||
"assertion failed", | ||
ast_assert.condition_expr.span()); | ||
} | ||
|
||
Ok(asm::ResolutionState::Resolved) | ||
} |
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,27 @@ | ||
#ruledef test | ||
{ | ||
ld {x} => | ||
{ | ||
assert(x <= 0x8) | ||
0x11 @ x`16 | ||
} | ||
|
||
ld {x} => | ||
{ | ||
assert(x > 0x8) | ||
0x22 @ x`8 | ||
} | ||
} | ||
#assert $ == 0x0 | ||
|
||
ld label | ||
ld label | ||
label: | ||
|
||
#assert label == 0x4 ; error: assertion | ||
|
||
ld label | ||
ld label | ||
#assert $ == 0x8 ; error: assertion |
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,3 @@ | ||
x = 0xff | ||
#d x | ||
#assert x == 0xee ; error: assertion |
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,3 @@ | ||
#d x | ||
#assert x == 0xee ; error: assertion | ||
x = 0xff |
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,2 @@ | ||
#d 0xff | ||
#assert 1 + 1 ; error: expected boolean |
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,2 @@ | ||
#d 0xff | ||
#assert 1 + 1 == 5 ; error: assertion |
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 @@ | ||
#assert x ; error: unknown symbol |
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,27 @@ | ||
#ruledef test | ||
{ | ||
ld {x} => | ||
{ | ||
assert(x <= 0x8) | ||
0x11 @ x`16 | ||
} | ||
|
||
ld {x} => | ||
{ | ||
assert(x > 0x8) | ||
0x22 @ x`8 | ||
} | ||
} | ||
#assert $ == 0x0 | ||
|
||
ld label ; = 0x110006 | ||
ld label ; = 0x110006 | ||
label: | ||
|
||
#assert label == 0x6 | ||
|
||
ld label ; = 0x110006 | ||
ld label ; = 0x110006 | ||
#assert $ == 0xc |
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,3 @@ | ||
x = 0xff | ||
#d x ; = 0xff | ||
#assert x == 0xff |
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,3 @@ | ||
#d x ; = 0xff | ||
#assert x == 0xff | ||
x = 0xff |
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,2 @@ | ||
#d 0xff ; = 0xff | ||
#assert 1 + 1 == 2 |