forked from AbleScript/ablescript
Better BF function conversions
This commit is contained in:
parent
8824633aae
commit
7812058fbf
|
@ -209,10 +209,12 @@ impl Value {
|
||||||
Value::Int(i) => Functio::BfFunctio {
|
Value::Int(i) => Functio::BfFunctio {
|
||||||
instructions: {
|
instructions: {
|
||||||
let instruction_mappings = [b'[', b']', b'+', b'-', b',', b'.', b'<', b'>'];
|
let instruction_mappings = [b'[', b']', b'+', b'-', b',', b'.', b'<', b'>'];
|
||||||
std::iter::successors(Some(i), |i| Some(i >> 3))
|
std::iter::successors(Some(i as usize), |i| {
|
||||||
.take_while(|&i| i != 0)
|
Some(i / instruction_mappings.len())
|
||||||
.map(|i| instruction_mappings[(i & 0x07) as usize])
|
})
|
||||||
.collect()
|
.take_while(|&i| i != 0)
|
||||||
|
.map(|i| instruction_mappings[i % instruction_mappings.len()])
|
||||||
|
.collect()
|
||||||
},
|
},
|
||||||
tape_len: crate::brian::DEFAULT_TAPE_SIZE_LIMIT,
|
tape_len: crate::brian::DEFAULT_TAPE_SIZE_LIMIT,
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue