WIP: Adding BVTON instruction to convert from ByteVector to Number
Some checks failed
per-push tests / build (pull_request) Failing after 54s
per-push tests / test-frontend (pull_request) Has been skipped
per-push tests / timed-decomposer-parse (pull_request) Has been skipped
per-push tests / test-utility (pull_request) Has been skipped
per-push tests / test-backend (pull_request) Has been skipped
Some checks failed
per-push tests / build (pull_request) Failing after 54s
per-push tests / test-frontend (pull_request) Has been skipped
per-push tests / timed-decomposer-parse (pull_request) Has been skipped
per-push tests / test-utility (pull_request) Has been skipped
per-push tests / test-backend (pull_request) Has been skipped
This commit is contained in:
parent
c25a57a92f
commit
37b21935cc
2 changed files with 30 additions and 3 deletions
|
|
@ -398,12 +398,20 @@ impl VM {
|
||||||
n.0 > u8::MAX.into() || n.0 < 0.0 {
|
n.0 > u8::MAX.into() || n.0 < 0.0 {
|
||||||
e!("input to NTOBV cannot cleanly convert");
|
e!("input to NTOBV cannot cleanly convert");
|
||||||
}
|
}
|
||||||
Datum::ByteVector(n.0.to_bits().to_ne_bytes().to_vec()).into()
|
Datum::ByteVector(n.0.to_ne_bytes().to_vec()).into()
|
||||||
} else {
|
} else {
|
||||||
e!("illegal argument to NTOBV instruction");
|
e!("illegal argument to NTOBV instruction");
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
i::BVTON => access!(&instr.1[0], {
|
||||||
|
if let Datum::ByteVector(sbv) = **access!(&instr.1[0]) {
|
||||||
|
Datum::Number(Number::Fra(Fraction(f64::from_ne_bytes(sbv) as isize, 1))).into()
|
||||||
|
} else {
|
||||||
|
e!("illegal argument to BVTON instruction");
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
i::NTOC => access!(&instr.1[0], {
|
i::NTOC => access!(&instr.1[0], {
|
||||||
if let Datum::Number(snum) = **access!(&instr.1[0]) {
|
if let Datum::Number(snum) = **access!(&instr.1[0]) {
|
||||||
let n = snum.make_inexact();
|
let n = snum.make_inexact();
|
||||||
|
|
@ -1132,6 +1140,10 @@ mod tests {
|
||||||
Instruction(i::NTOBV, vec![Operand(Address::Expr, 0)]),
|
Instruction(i::NTOBV, vec![Operand(Address::Expr, 0)]),
|
||||||
Instruction(i::PUSH, vec![Operand(Address::Expr, 0)]),
|
Instruction(i::PUSH, vec![Operand(Address::Expr, 0)]),
|
||||||
|
|
||||||
|
// convert back to inexact and push to stack
|
||||||
|
Instruction(i::BVTON, vec![Operand(Address::Expr, 0)]),
|
||||||
|
Instruction(i::PUSH, vec![Operand(Address::Expr, 0)]),
|
||||||
|
|
||||||
// create a char and push to stack
|
// create a char and push to stack
|
||||||
Instruction(i::NTOC, vec![Operand(Address::Expr, 0)]),
|
Instruction(i::NTOC, vec![Operand(Address::Expr, 0)]),
|
||||||
Instruction(i::PUSH, vec![Operand(Address::Expr, 0)]),
|
Instruction(i::PUSH, vec![Operand(Address::Expr, 0)]),
|
||||||
|
|
@ -1150,8 +1162,9 @@ mod tests {
|
||||||
(2, Datum::Number(Number::Flt(Float(97.0))).into()),
|
(2, Datum::Number(Number::Flt(Float(97.0))).into()),
|
||||||
(3, Datum::Number(Number::Fra(Fraction(97, 1))).into()),
|
(3, Datum::Number(Number::Fra(Fraction(97, 1))).into()),
|
||||||
(4, Datum::String(vec![b'a']).into()),
|
(4, Datum::String(vec![b'a']).into()),
|
||||||
(5, Datum::Number(Number::Fra(Fraction(97, 1))).into()),
|
(5, Datum::ByteVector(vec![0, 0, 0, 0, 0, 64, 88, 64]).into()),
|
||||||
(6, Datum::Char(b'a').into()),
|
(6, Datum::Number(Number::Fra(Fraction(97, 1))).into()),
|
||||||
|
(7, Datum::Char(b'a').into()),
|
||||||
],
|
],
|
||||||
syms: vec![],
|
syms: vec![],
|
||||||
errr: None,
|
errr: None,
|
||||||
|
|
|
||||||
|
|
@ -655,6 +655,20 @@ float datum casted to ByteVector datum.
|
||||||
Requires mutable access to input address.
|
Requires mutable access to input address.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
[[instructions]]
|
||||||
|
name = "bvton"
|
||||||
|
args = ["src"]
|
||||||
|
output = ""
|
||||||
|
description = """
|
||||||
|
The bvton instruction accepts a byte vector input. This operand is overwritten
|
||||||
|
by a new number datum that represents the inexact form of the source byte vector.
|
||||||
|
|
||||||
|
The normalized fraction or scientific notation data represented in a
|
||||||
|
ByteVector datum is casted to an inexact floating point number.
|
||||||
|
|
||||||
|
Requires mutable access to input address.
|
||||||
|
"""
|
||||||
|
|
||||||
[[instructions]]
|
[[instructions]]
|
||||||
name = "ntoc"
|
name = "ntoc"
|
||||||
args = ["src"]
|
args = ["src"]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue