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: Initial support for local labels …
Browse files Browse the repository at this point in the history
…inside asm{}
  • Loading branch information
Emmett81 committed Oct 19, 2021
1 parent 1ecb2d5 commit 381c192
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 48 deletions.
110 changes: 62 additions & 48 deletions src/asm/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1386,68 +1386,82 @@ 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(
self.get_addr(info.report.clone(), &inner_ctx, &subparser_span)?)
);
subparser.expect(syntax::TokenKind::Colon)?;
}
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
{
result = bigint;
}
else
if size > 0
{
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()?;
}

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 ; = 0x00_01_00_01_04
nested_test ; = 0x05_06_05_06_09_0a_0b_0a_0b_0e

0 comments on commit 381c192

Please sign in to comment.