use crate::Engine;
use bitflags::bitflags;
#[cfg(feature = "no_std")]
use std::prelude::v1::*;
bitflags! {
pub struct LangOptions: u16 {
const IF_EXPR = 0b_0000_0000_0001;
const SWITCH_EXPR = 0b_0000_0000_0010;
const LOOP_EXPR = 0b_0000_0000_0100;
const STMT_EXPR = 0b_0000_0000_1000;
#[cfg(not(feature = "no_function"))]
const ANON_FN = 0b_0000_0001_0000;
const LOOPING = 0b_0000_0010_0000;
const SHADOWING = 0b_0000_0100_0000;
const STRICT_VAR = 0b_0000_1000_0000;
#[cfg(not(feature = "no_object"))]
const FAIL_ON_INVALID_MAP_PROPERTY = 0b_0001_0000_0000;
const FAST_OPS = 0b_0010_0000_0000;
}
}
impl LangOptions {
#[inline(always)]
#[must_use]
pub const fn new() -> Self {
Self::from_bits_truncate(
Self::IF_EXPR.bits()
| Self::SWITCH_EXPR.bits()
| Self::LOOP_EXPR.bits()
| Self::STMT_EXPR.bits()
| Self::LOOPING.bits()
| Self::SHADOWING.bits()
| Self::FAST_OPS.bits()
| {
#[cfg(not(feature = "no_function"))]
{
Self::ANON_FN.bits()
}
#[cfg(feature = "no_function")]
{
Self::empty().bits()
}
},
)
}
}
impl Engine {
#[inline(always)]
#[must_use]
pub const fn allow_if_expression(&self) -> bool {
self.options.contains(LangOptions::IF_EXPR)
}
#[inline(always)]
pub fn set_allow_if_expression(&mut self, enable: bool) -> &mut Self {
self.options.set(LangOptions::IF_EXPR, enable);
self
}
#[inline(always)]
#[must_use]
pub const fn allow_switch_expression(&self) -> bool {
self.options.contains(LangOptions::SWITCH_EXPR)
}
#[inline(always)]
pub fn set_allow_switch_expression(&mut self, enable: bool) -> &mut Self {
self.options.set(LangOptions::SWITCH_EXPR, enable);
self
}
#[inline(always)]
#[must_use]
pub const fn allow_loop_expressions(&self) -> bool {
self.options.contains(LangOptions::LOOP_EXPR)
}
#[inline(always)]
pub fn set_allow_loop_expressions(&mut self, enable: bool) -> &mut Self {
self.options.set(LangOptions::LOOP_EXPR, enable);
self
}
#[inline(always)]
#[must_use]
pub const fn allow_statement_expression(&self) -> bool {
self.options.contains(LangOptions::STMT_EXPR)
}
#[inline(always)]
pub fn set_allow_statement_expression(&mut self, enable: bool) -> &mut Self {
self.options.set(LangOptions::STMT_EXPR, enable);
self
}
#[cfg(not(feature = "no_function"))]
#[inline(always)]
#[must_use]
pub const fn allow_anonymous_fn(&self) -> bool {
self.options.contains(LangOptions::ANON_FN)
}
#[cfg(not(feature = "no_function"))]
#[inline(always)]
pub fn set_allow_anonymous_fn(&mut self, enable: bool) -> &mut Self {
self.options.set(LangOptions::ANON_FN, enable);
self
}
#[inline(always)]
#[must_use]
pub const fn allow_looping(&self) -> bool {
self.options.contains(LangOptions::LOOPING)
}
#[inline(always)]
pub fn set_allow_looping(&mut self, enable: bool) -> &mut Self {
self.options.set(LangOptions::LOOPING, enable);
self
}
#[inline(always)]
#[must_use]
pub const fn allow_shadowing(&self) -> bool {
self.options.contains(LangOptions::SHADOWING)
}
#[inline(always)]
pub fn set_allow_shadowing(&mut self, enable: bool) -> &mut Self {
self.options.set(LangOptions::SHADOWING, enable);
self
}
#[inline(always)]
#[must_use]
pub const fn strict_variables(&self) -> bool {
self.options.contains(LangOptions::STRICT_VAR)
}
#[inline(always)]
pub fn set_strict_variables(&mut self, enable: bool) -> &mut Self {
self.options.set(LangOptions::STRICT_VAR, enable);
self
}
#[cfg(not(feature = "no_object"))]
#[inline(always)]
#[must_use]
pub const fn fail_on_invalid_map_property(&self) -> bool {
self.options
.contains(LangOptions::FAIL_ON_INVALID_MAP_PROPERTY)
}
#[cfg(not(feature = "no_object"))]
#[inline(always)]
pub fn set_fail_on_invalid_map_property(&mut self, enable: bool) -> &mut Self {
self.options
.set(LangOptions::FAIL_ON_INVALID_MAP_PROPERTY, enable);
self
}
#[inline(always)]
#[must_use]
pub const fn fast_operators(&self) -> bool {
self.options.contains(LangOptions::FAST_OPS)
}
#[inline(always)]
pub fn set_fast_operators(&mut self, enable: bool) -> &mut Self {
self.options.set(LangOptions::FAST_OPS, enable);
self
}
}