<commit_before>use std::fmt;
use parking_lot::RwLock;
use elements::{GlobalType, ValueType, TableElementType};
use interpreter::Error;
use interpreter::value::RuntimeValue;

/// Variable type.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum VariableType {
	/// Any func value.
	AnyFunc,
	/// i32 value.
	I32,
	/// i64 value.
	I64,
	/// f32 value.
	F32,
	/// f64 value.
	F64,
}

/// Externally stored variable value.
pub trait ExternalVariableValue {
	/// Get variable value.
	fn get(&self) -> RuntimeValue;

	/// Set variable value.
	///
	/// WebAssembly specificaiton [requires][0] that if global variable is immutable, then
	/// it should remain unchanged.
	///
	/// [0]: https://webassembly.github.io/spec/appendix/properties.html#global-instance
	fn set(&mut self, value: RuntimeValue) -> Result<(), Error>;
}

/// Variable instance.
#[derive(Debug)]
pub struct VariableInstance {
	/// Is mutable?
	is_mutable: bool,
	/// Variable type.
	variable_type: VariableType,
	/// Global value.
	value: RwLock<VariableValue>,
}

/// Enum variable value.
enum VariableValue {
	/// Internal value.
	Internal(RuntimeValue),
	/// External value.
	External(Box<ExternalVariableValue>),
}

impl VariableInstance {
	/// New variable instance
	pub fn new(is_mutable: bool, variable_type: VariableType, value: RuntimeValue) -> Result<Self, Error> {<commit_msg>Move comment about spec to the trait header.<commit_after>use std::fmt;
use parking_lot::RwLock;
use elements::{GlobalType, ValueType, TableElementType};
use interpreter::Error;
use interpreter::value::RuntimeValue;

/// Variable type.
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum VariableType {
	/// Any func value.
	AnyFunc,
	/// i32 value.
	I32,
	/// i64 value.
	I64,
	/// f32 value.
	F32,
	/// f64 value.
	F64,
}

/// Externally stored variable value.
///
/// WebAssembly specificaiton [requires][0] that if a global variable is immutable, then
/// it should remain unchanged. To comply with specification you should ensure this invariant holds.
///
/// [0]: https://webassembly.github.io/spec/appendix/properties.html#global-instance
pub trait ExternalVariableValue {
	/// Get variable value.
	fn get(&self) -> RuntimeValue;

	/// Set variable value.
	fn set(&mut self, value: RuntimeValue) -> Result<(), Error>;
}

/// Variable instance.
#[derive(Debug)]
pub struct VariableInstance {
	/// Is mutable?
	is_mutable: bool,
	/// Variable type.
	variable_type: VariableType,
	/// Global value.
	value: RwLock<VariableValue>,
}

/// Enum variable value.
enum VariableValue {
	/// Internal value.
	Internal(RuntimeValue),
	/// External value.
	External(Box<ExternalVariableValue>),
}

impl VariableInstance {
	/// New variable instance
	pub fn new(is_mutable: bool, variable_type: VariableType, value: RuntimeValue) -> Result<Self, Error> {
{'fraction_non_alphanumeric': 0.14464733261725743, 'fraction_numerical': 0.01288936627282492, 'mean_word_length': 3.7679180887372015, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3192292', 'n_tokens_mistral': 906, 'n_tokens_neox': 868, 'n_words': 258}