Skip to content

Commit

Permalink
continue reorganizing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hlorenzi committed Apr 11, 2023
1 parent 90b22e5 commit 84dbd98
Show file tree
Hide file tree
Showing 228 changed files with 597 additions and 991 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/target/
/pkg/
/.pkgtemp/
/.vscode/
/Cargo.lock
/test.asm

Expand Down
1 change: 1 addition & 0 deletions .gitignore.ghpages
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/target/
/pkg/
/.pkgtemp/
/.vscode/
/Cargo.lock
2 changes: 2 additions & 0 deletions src/asm2/defs/ruledef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::*;
pub struct Ruledef
{
pub item_ref: util::ItemRef<Self>,
pub is_subruledef: bool,
pub rules: Vec<Rule>,
}

Expand Down Expand Up @@ -82,6 +83,7 @@ pub fn define(

let ruledef = Ruledef {
item_ref,
is_subruledef: node.is_subruledef,
rules,
};

Expand Down
31 changes: 19 additions & 12 deletions src/asm2/matcher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ pub fn match_instr(
for i in 0..defs.ruledefs.defs.len()
{
let ruledef_ref = util::ItemRef::<asm2::Ruledef>::new(i);
let ruledef = defs.ruledefs.get(ruledef_ref);

if ruledef.is_subruledef
{
continue;
}

let mut walker = syntax::TokenWalker::new(tokens);

Expand Down Expand Up @@ -221,7 +227,7 @@ fn get_match_static_size(
let rule = &ruledef.get_rule(mtch.rule_ref);

let mut info = expr::StaticSizeInfo::new();

for i in 0..rule.parameters.len()
{
let param = &rule.parameters[i];
Expand Down Expand Up @@ -395,7 +401,10 @@ fn match_with_expr<'tokens>(
{
match walker.maybe_expect_partial_usize()
{
None => vec![],
None =>
{
return vec![];
}
Some(value) =>
{
let expr = expr::Value::make_integer(value)
Expand All @@ -405,8 +414,6 @@ fn match_with_expr<'tokens>(
kind: InstructionArgumentKind::Expr(expr),
tokens: Vec::new(),
});

vec![(match_so_far.clone(), walker.clone())]
}
}
}
Expand Down Expand Up @@ -436,15 +443,15 @@ fn match_with_expr<'tokens>(
token_start,
token_end),
});

match_with_rule(
defs,
rule,
walker,
needs_consume_all_tokens,
at_pattern_part + 1,
match_so_far)
}

match_with_rule(
defs,
rule,
walker,
needs_consume_all_tokens,
at_pattern_part + 1,
match_so_far)
}


Expand Down
4 changes: 2 additions & 2 deletions src/asm2/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ pub fn parse_and_resolve_includes<S>(
None,
root_filename.borrow())?;

let tokens = syntax::tokenize(
diagn::RcReport::new(),
let tokens = syntax::tokenize2(
report,
root_filename.borrow(),
&chars)?;

Expand Down
17 changes: 10 additions & 7 deletions src/asm2/resolver/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,10 @@ pub fn check_and_constrain_argument(
typ: asm2::RuleParameterType)
-> Result<expr::Value, ()>
{
let bigint = value.expect_bigint(report, span)?.clone();
let bigint = value
.coallesce_to_integer()
.expect_bigint(report, span)?
.to_owned();

match typ
{
Expand All @@ -404,7 +407,7 @@ pub fn check_and_constrain_argument(

asm2::RuleParameterType::Unsigned(size) =>
{
check_argument_for_integer_type(
check_and_constrain_value_for_integer_type(
report,
span,
size,
Expand All @@ -416,7 +419,7 @@ pub fn check_and_constrain_argument(

asm2::RuleParameterType::Signed(size) =>
{
check_argument_for_integer_type(
check_and_constrain_value_for_integer_type(
report,
span,
size,
Expand All @@ -429,7 +432,7 @@ pub fn check_and_constrain_argument(

asm2::RuleParameterType::Integer(size) =>
{
check_argument_for_integer_type(
check_and_constrain_value_for_integer_type(
report,
span,
size,
Expand All @@ -444,16 +447,16 @@ pub fn check_and_constrain_argument(
}


fn check_argument_for_integer_type(
fn check_and_constrain_value_for_integer_type(
report: &mut diagn::Report,
span: &diagn::Span,
size: usize,
typename_prefix: &'static str,
mut bigint: util::BigInt,
failure_fn: impl Fn(&util::BigInt) -> bool)
failure_check: impl Fn(&util::BigInt) -> bool)
-> Result<expr::Value, ()>
{
if failure_fn(&bigint)
if failure_check(&bigint)
{
let msg = diagn::Message::error_span(
format!(
Expand Down
4 changes: 2 additions & 2 deletions src/expr/eval2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,8 @@ impl expr::Expr
match (lhs.size, rhs.size)
{
(Some(lhs_width), Some(rhs_width)) => Ok(expr::Value::make_integer(lhs.concat((lhs_width, 0), &rhs, (rhs_width, 0)))),
(None, _) => Err(report.error_span("argument to concatenation with unspecified size", &lhs_expr.span())),
(_, None) => Err(report.error_span("argument to concatenation with unspecified size", &rhs_expr.span()))
(None, _) => Err(report.error_span("argument to concatenation with indefinite size", &lhs_expr.span())),
(_, None) => Err(report.error_span("argument to concatenation with indefinite size", &rhs_expr.span()))
}
}

Expand Down
21 changes: 12 additions & 9 deletions src/expr/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,17 @@ impl Value
}


pub fn coallesce_to_integer(self) -> expr::Value
pub fn coallesce_to_integer<'a>(
&'a self)
-> std::borrow::Cow<'a, expr::Value>
{
match self
{
Value::String(ref s) =>
expr::Value::Integer(s.to_bigint()),
std::borrow::Cow::Owned(
expr::Value::Integer(s.to_bigint())),

_ => self,
_ => std::borrow::Cow::Borrowed(self),
}
}

Expand Down Expand Up @@ -245,14 +248,14 @@ impl Value
span: &diagn::Span)
-> Result<expr::Value, ()>
{
match self.coallesce_to_integer()
match self.coallesce_to_integer().as_ref()
{
value @ expr::Value::Unknown |
value @ expr::Value::FailedConstraint(_) =>
Ok(value),
Ok(value.to_owned()),

value @ expr::Value::Integer(_) =>
Ok(value),
Ok(value.to_owned()),

_ =>
{
Expand All @@ -272,15 +275,15 @@ impl Value
span: &diagn::Span)
-> Result<expr::Value, ()>
{
match self.coallesce_to_integer()
match self.coallesce_to_integer().as_ref()
{
value @ expr::Value::Unknown |
value @ expr::Value::FailedConstraint(_) =>
Ok(value),
Ok(value.to_owned()),

expr::Value::Integer(bigint)
if bigint.size.is_some() =>
Ok(expr::Value::Integer(bigint)),
Ok(expr::Value::Integer(bigint.to_owned())),

_ =>
{
Expand Down
2 changes: 2 additions & 0 deletions src/syntax/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
mod token;
mod token2;
mod token_walker;
mod parser;
mod excerpt;
Expand All @@ -8,6 +9,7 @@ pub use self::token::Token;
pub use self::token::TokenKind;
pub use self::token::tokenize;
pub use self::token::is_whitespace;
pub use self::token2::tokenize2;
pub use self::token_walker::TokenWalker;
pub use self::parser::Parser;
pub use self::excerpt::excerpt_as_string_contents;
Expand Down
2 changes: 1 addition & 1 deletion src/syntax/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub enum TokenKind

impl TokenKind
{
fn needs_excerpt(self) -> bool
pub fn needs_excerpt(self) -> bool
{
self == TokenKind::Identifier ||
self == TokenKind::Number ||
Expand Down
Loading

0 comments on commit 84dbd98

Please sign in to comment.