u8 is too small for 256!

This commit is contained in:
Aaron Blankstein
2019-02-07 15:43:38 -06:00
parent ec2af760d2
commit ba2d70353f
2 changed files with 6 additions and 6 deletions

View File

@@ -5,7 +5,7 @@ use vm::errors::{Error, InterpreterResult as Result};
use vm::types::{DefinedFunction, FunctionIdentifier, Value};
use vm::database::ContractDatabase;
const MAX_CONTEXT_DEPTH: u8 = 256;
const MAX_CONTEXT_DEPTH: u16 = 256;
pub struct Environment <'a> {
pub global_context: Context <'a>,
@@ -28,7 +28,7 @@ pub struct Context <'a> {
pub parent: Option< &'a Context<'a>>,
pub variables: HashMap<String, Value>,
pub functions: HashMap<String, DefinedFunction>,
depth: u8
depth: u16
}
impl <'a> Context <'a> {

View File

@@ -47,20 +47,20 @@ fn test_bad_define_names() {
fn test_stack_depth() {
let mut function_defines = Vec::new();
function_defines.push("(define (foo-0 x) (+ 1 x))".to_string());
for i in 1..129 {
for i in 1..257 {
function_defines.push(
format!("(define (foo-{} x) (foo-{} (+ 1 x)))",
i, i-1));
}
function_defines.push(
format!("(foo-127 1)"));
format!("(foo-255 1)"));
let test0 = function_defines.join("\n");
function_defines.push(
format!("(foo-128 2)"));
format!("(foo-256 2)"));
let test1 = function_defines.join("\n");
assert_eq!(Ok(Value::Int(129)), execute(&test0));
assert_eq!(Ok(Value::Int(257)), execute(&test0));
assert_eq!(Err(Error::MaxStackDepthReached), execute(&test1));
}