Skip to content
This repository has been archived by the owner on Dec 10, 2023. It is now read-only.

Commit

Permalink
Partial fix for issue hlorenzi#115: Partial support for labels inside…
Browse files Browse the repository at this point in the history
… asm{}
  • Loading branch information
Emmett81 committed Oct 18, 2021
1 parent 1ecb2d5 commit a92d37d
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 49 deletions.
109 changes: 60 additions & 49 deletions src/asm/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1386,69 +1386,80 @@ impl State
subparser.suppress_reports();

//println!("> after subs `{:?}`", subs_tokens);

let matches = asm::parser::match_rule_invocation(
&self,
subparser,
inner_ctx.clone(),
fileserver,
info.report.clone())?;

let value = self.resolve_rule_invocation(
info.report.clone(),
&matches,
fileserver,
true,
info.args)?;

//println!(" value = {:?}", value);

let (bigint, size) = match value.get_bigint()
if subparser.next_is(0, syntax::TokenKind::Identifier) &&
subparser.next_is(1, syntax::TokenKind::Colon)
{
Some(bigint) =>
let label_tk = subparser.expect(syntax::TokenKind::Identifier)?;
let label_name = label_tk.excerpt.as_ref().unwrap();
info.args.set_local(
label_name,
expr::Value::make_integer(inner_ctx.bit_offset / inner_ctx.cur_wordsize)
);
} else {
let matches = asm::parser::match_rule_invocation(
&self,
subparser,
inner_ctx.clone(),
fileserver,
info.report.clone())?;

let value = self.resolve_rule_invocation(
info.report.clone(),
&matches,
fileserver,
true,
info.args)?;

//println!(" value = {:?}", value);

let (bigint, size) = match value.get_bigint()
{
match bigint.size
Some(bigint) =>
{
Some(size) => (bigint, size),
None =>
match bigint.size
{
info.report.error_span(
"cannot infer size of instruction",
&subparser_span);
Some(size) => (bigint, size),
None =>
{
info.report.error_span(
"cannot infer size of instruction",
&subparser_span);

return Err(());
return Err(());
}
}
}
}

_ =>
{
info.report.error_span(
"wrong type returned from instruction",
&subparser_span);
_ =>
{
info.report.error_span(
"wrong type returned from instruction",
&subparser_span);

return Err(());
}
};
return Err(());
}
};

if size > 0
{
if result.size.unwrap() == 0
if size > 0
{
result = bigint;
}
else
{
result = result.concat(
(result.size.unwrap(), 0),
&bigint,
(size, 0));
if result.size.unwrap() == 0
{
result = bigint;
}
else
{
result = result.concat(
(result.size.unwrap(), 0),
&bigint,
(size, 0));
}

inner_ctx.bit_offset += size;
}

inner_ctx.bit_offset += size;
}

}
parser.expect_linebreak()?;

}

//println!(" result size = {:?}", result.size);
Expand Down
29 changes: 29 additions & 0 deletions tests/issue115/3.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#ruledef {
emit {x:u8} => x

nested_test => asm
{
label:
emit $
label2:
emit $
emit label
emit label2
emit $
test
}

test => asm
{
label:
emit $
label2:
emit $
emit label
emit label2
emit $
}
}

test ;= 00_01_00_01_04
nested_test ;= 05_06_05_06_09_0a_0b_0a_0b_0e

0 comments on commit a92d37d

Please sign in to comment.