1use crate::Engine;
4use bitflags::bitflags;
5#[cfg(feature = "no_std")]
6use std::prelude::v1::*;
7
8bitflags! {
9 #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)]
11 pub struct LangOptions: u16 {
12 const IF_EXPR = 0b_0000_0000_0001;
14 const SWITCH_EXPR = 0b_0000_0000_0010;
16 const LOOP_EXPR = 0b_0000_0000_0100;
18 const STMT_EXPR = 0b_0000_0000_1000;
20 #[cfg(not(feature = "no_function"))]
22 const ANON_FN = 0b_0000_0001_0000;
23 const LOOPING = 0b_0000_0010_0000;
25 const SHADOWING = 0b_0000_0100_0000;
27 const STRICT_VAR = 0b_0000_1000_0000;
29 #[cfg(not(feature = "no_object"))]
32 const FAIL_ON_INVALID_MAP_PROPERTY = 0b_0001_0000_0000;
33 const FAST_OPS = 0b_0010_0000_0000;
35 }
36}
37
38impl LangOptions {
39 #[inline(always)]
41 #[must_use]
42 pub const fn new() -> Self {
43 Self::from_bits_truncate(
44 Self::IF_EXPR.bits()
45 | Self::SWITCH_EXPR.bits()
46 | Self::LOOP_EXPR.bits()
47 | Self::STMT_EXPR.bits()
48 | Self::LOOPING.bits()
49 | Self::SHADOWING.bits()
50 | Self::FAST_OPS.bits()
51 | {
52 #[cfg(not(feature = "no_function"))]
53 {
54 Self::ANON_FN.bits()
55 }
56 #[cfg(feature = "no_function")]
57 {
58 Self::empty().bits()
59 }
60 },
61 )
62 }
63}
64
65impl Engine {
66 #[inline(always)]
69 #[must_use]
70 pub const fn allow_if_expression(&self) -> bool {
71 self.options.intersects(LangOptions::IF_EXPR)
72 }
73 #[inline(always)]
75 pub fn set_allow_if_expression(&mut self, enable: bool) -> &mut Self {
76 self.options.set(LangOptions::IF_EXPR, enable);
77 self
78 }
79 #[inline(always)]
82 #[must_use]
83 pub const fn allow_switch_expression(&self) -> bool {
84 self.options.intersects(LangOptions::SWITCH_EXPR)
85 }
86 #[inline(always)]
88 pub fn set_allow_switch_expression(&mut self, enable: bool) -> &mut Self {
89 self.options.set(LangOptions::SWITCH_EXPR, enable);
90 self
91 }
92 #[inline(always)]
95 #[must_use]
96 pub const fn allow_loop_expressions(&self) -> bool {
97 self.options.intersects(LangOptions::LOOP_EXPR)
98 }
99 #[inline(always)]
101 pub fn set_allow_loop_expressions(&mut self, enable: bool) -> &mut Self {
102 self.options.set(LangOptions::LOOP_EXPR, enable);
103 self
104 }
105 #[inline(always)]
108 #[must_use]
109 pub const fn allow_statement_expression(&self) -> bool {
110 self.options.intersects(LangOptions::STMT_EXPR)
111 }
112 #[inline(always)]
114 pub fn set_allow_statement_expression(&mut self, enable: bool) -> &mut Self {
115 self.options.set(LangOptions::STMT_EXPR, enable);
116 self
117 }
118 #[cfg(not(feature = "no_function"))]
123 #[inline(always)]
124 #[must_use]
125 pub const fn allow_anonymous_fn(&self) -> bool {
126 self.options.intersects(LangOptions::ANON_FN)
127 }
128 #[cfg(not(feature = "no_function"))]
132 #[inline(always)]
133 pub fn set_allow_anonymous_fn(&mut self, enable: bool) -> &mut Self {
134 self.options.set(LangOptions::ANON_FN, enable);
135 self
136 }
137 #[inline(always)]
140 #[must_use]
141 pub const fn allow_looping(&self) -> bool {
142 self.options.intersects(LangOptions::LOOPING)
143 }
144 #[inline(always)]
146 pub fn set_allow_looping(&mut self, enable: bool) -> &mut Self {
147 self.options.set(LangOptions::LOOPING, enable);
148 self
149 }
150 #[inline(always)]
153 #[must_use]
154 pub const fn allow_shadowing(&self) -> bool {
155 self.options.intersects(LangOptions::SHADOWING)
156 }
157 #[inline(always)]
159 pub fn set_allow_shadowing(&mut self, enable: bool) -> &mut Self {
160 self.options.set(LangOptions::SHADOWING, enable);
161 self
162 }
163 #[inline(always)]
166 #[must_use]
167 pub const fn strict_variables(&self) -> bool {
168 self.options.intersects(LangOptions::STRICT_VAR)
169 }
170 #[inline(always)]
172 pub fn set_strict_variables(&mut self, enable: bool) -> &mut Self {
173 self.options.set(LangOptions::STRICT_VAR, enable);
174 self
175 }
176 #[cfg(not(feature = "no_object"))]
181 #[inline(always)]
182 #[must_use]
183 pub const fn fail_on_invalid_map_property(&self) -> bool {
184 self.options
185 .intersects(LangOptions::FAIL_ON_INVALID_MAP_PROPERTY)
186 }
187 #[cfg(not(feature = "no_object"))]
191 #[inline(always)]
192 pub fn set_fail_on_invalid_map_property(&mut self, enable: bool) -> &mut Self {
193 self.options
194 .set(LangOptions::FAIL_ON_INVALID_MAP_PROPERTY, enable);
195 self
196 }
197 #[inline(always)]
200 #[must_use]
201 pub const fn fast_operators(&self) -> bool {
202 self.options.intersects(LangOptions::FAST_OPS)
203 }
204 #[inline(always)]
206 pub fn set_fast_operators(&mut self, enable: bool) -> &mut Self {
207 self.options.set(LangOptions::FAST_OPS, enable);
208 self
209 }
210}