test script::mod_storage::tests::write_1000_kv_pairs_in_isolated_txns ... bench: 6,806,585 ns/iter (+/- 491,140)
test script::mod_storage::tests::write_1000_kv_pairs_in_isolated_txns_baseline ... bench: 2,587,774 ns/iter (+/- 168,159)
// Copyright (c) 2017, All Contributors (see CONTRIBUTORS file)
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
pub enum Continuation<'a> {
Instruction(&'a [u8], &'a Continuation<'a>),
// Comparison (TODO: LessThan, GreaterThan)
Equal(&'a [u8], &'a Continuation<'a>),
// Boolean
Not(&'a Continuation<'a>),
// Stack
Swap(&'a Continuation<'a>),
Push(&'a [u8], &'a Continuation<'a>),
Dup(&'a Continuation<'a>),
// Control flow
While(&'a Continuation<'a>, &'a Continuation<'a>),
Halt,
}
#[cfg(test)]
mod tests {
use super::Continuation::*;
#[test]
fn test() {
// [SAVE] 10 TIMES:
let prog0 = Push(b"representation for [SAVE]", &Push(&[10u8], &Instruction(b"TIMES", &Halt)));
let prog1 = Push(b"representation for [SAVE]", &Push(&[10u8],
&Dup(&Equal(&[0u8], &Not(
&While(&Instruction(b"UINT/DEC",
&Swap(&Dup(&Instruction("EVAL", &Swap(&Dup(&Equal(&[0u8], &Not(&Halt)))))))), &Halt))))));
}
}
EVAL
would try to avoid re-interpreting [SAVE] by simply caching the Continuation
derived for it
Cond
instead of While
at first but it proved to be difficult
While
can be seen as a higher level generalization (one can imagine implementing IF
through While
)
Halt
to the first Push
)
#[derive(Debug)]
pub enum Continuation<'a> {
Instruction(Vec<u8>, &'a Continuation<'a>),
// Comparison (TODO: LessThan, GreaterThan)
Equal(Vec<u8>, &'a Continuation<'a>),
// Boolean
Not(&'a Continuation<'a>),
// Stack
Swap(&'a Continuation<'a>),
Push(Vec<u8>, &'a Continuation<'a>),
Dup(&'a Continuation<'a>),
// Control flow
If(&'a Continuation<'a>, &'a Continuation<'a>),
Defer(&'a Continuation<'a>, &'a Continuation<'a>),
Yield,
Undefer(&'a Continuation<'a>),
Halt,
}