Skip to content

Commit

Permalink
fix #113 and fix #114: fix checks for string arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
hlorenzi committed Oct 10, 2021
1 parent 1b026f0 commit cca2ec0
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "customasm"
version = "0.11.11"
version = "0.11.12"
edition = "2018"
authors = ["hlorenzi <https://hlorenzi.com>"]
description = "An assembler for custom, user-defined instruction sets!"
Expand Down
18 changes: 11 additions & 7 deletions src/asm/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ impl State
{
let data_invoc = &invocation.get_data_invoc();

let mut resolved = self.eval_expr(
let resolved = self.eval_expr(
report.clone(),
&data_invoc.expr,
&invocation.ctx,
Expand All @@ -618,9 +618,9 @@ impl State

if let Some(elem_size) = data_invoc.elem_size
{
match resolved
match resolved.get_bigint()
{
expr::Value::Integer(ref mut bigint) =>
Some(mut bigint) =>
{
let mut size = bigint.min_size();
if let Some(intrinsic_size) = bigint.size
Expand All @@ -639,8 +639,9 @@ impl State
}

bigint.size = Some(elem_size);
return Ok(expr::Value::make_integer(bigint));
}
_ => {}
None => {}
}
}

Expand Down Expand Up @@ -900,7 +901,7 @@ impl State

asm::PatternParameterType::Unsigned(size) =>
{
if let expr::Value::Integer(value_int) = value
if let Some(mut value_int) = value.get_bigint()
{
if value_int.sign() == -1 ||
value_int.min_size() > size
Expand All @@ -913,6 +914,7 @@ impl State
else
{
value_int.size = Some(size);
*value = expr::Value::make_integer(value_int);
Ok(())
}
}
Expand All @@ -927,7 +929,7 @@ impl State

asm::PatternParameterType::Signed(size) =>
{
if let expr::Value::Integer(value_int) = value
if let Some(mut value_int) = value.get_bigint()
{
if (value_int.sign() == 0 && size == 0) ||
(value_int.sign() == 1 && value_int.min_size() >= size) ||
Expand All @@ -941,6 +943,7 @@ impl State
else
{
value_int.size = Some(size);
*value = expr::Value::make_integer(value_int);
Ok(())
}
}
Expand All @@ -955,7 +958,7 @@ impl State

asm::PatternParameterType::Integer(size) =>
{
if let expr::Value::Integer(value_int) = value
if let Some(mut value_int) = value.get_bigint()
{
if value_int.min_size() > size
{
Expand All @@ -967,6 +970,7 @@ impl State
else
{
value_int.size = Some(size);
*value = expr::Value::make_integer(value_int);
Ok(())
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/data_simple/36.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#d8 "a" ; = 0x61
#d16 "b" ; = 0x0062
1 change: 1 addition & 0 deletions tests/data_simple/37.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#d8 "abc" ; error: larger
2 changes: 2 additions & 0 deletions tests/issue113/1.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#d3 "test" ; error: larger
#d8 "ü" ; error: larger
10 changes: 10 additions & 0 deletions tests/rule_arg_typed/55.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ruledef test
{
ld1 {x: i8} => 0xaa @ x
ld2 {x: s8} => 0xbb @ x
ld3 {x: u16} => 0xcc @ x
}

ld1 "a" ; = 0xaa61
ld2 "b" ; = 0xbb62
ld3 "c" ; = 0xcc0063
10 changes: 10 additions & 0 deletions tests/rule_arg_typed/56.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#ruledef test
{
ld1 {x: i8} => 0xaa @ x
ld2 {x: s8} => 0xbb @ x
ld3 {x: u8} => 0xcc @ x
}

ld1 "abc" ; error: failed / error: out of range
ld2 "ã" ; error: failed / error: out of range
ld3 "ü" ; error: failed / error: out of range

0 comments on commit cca2ec0

Please sign in to comment.