Skip to content

Commit 9f46335

Browse files
committed
Fix builds
1 parent 46f7a76 commit 9f46335

File tree

8 files changed

+73
-49
lines changed

8 files changed

+73
-49
lines changed

src/eval/expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use super::{Caches, EvalContext, GlobalRuntimeState, Target};
44
use crate::ast::Expr;
55
use crate::packages::string_basic::{print_with_func, FUNC_TO_STRING};
6-
use crate::types::{dynamic::AccessMode, fn_ptr::FnPtrType};
6+
use crate::types::dynamic::AccessMode;
77
use crate::{Dynamic, Engine, RhaiResult, RhaiResultOf, Scope, SmartString, ERR};
88
#[cfg(feature = "no_std")]
99
use std::prelude::v1::*;
@@ -78,7 +78,7 @@ impl Engine {
7878
name: v.1.clone(),
7979
curry: <_>::default(),
8080
env: None,
81-
typ: FnPtrType::Script(fn_def.clone()),
81+
typ: crate::types::fn_ptr::FnPtrType::Script(fn_def.clone()),
8282
}
8383
.into();
8484
return Ok(val.into());

src/func/call.rs

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -812,15 +812,17 @@ impl Engine {
812812
)
813813
})?;
814814

815-
let (
816-
is_anon,
817-
FnPtr {
818-
name,
819-
curry,
820-
env,
821-
typ,
822-
},
823-
) = (fn_ptr.is_anonymous(), fn_ptr);
815+
let _is_anon = false;
816+
#[cfg(not(feature = "no_function"))]
817+
let _is_anon = fn_ptr.is_anonymous();
818+
819+
let FnPtr {
820+
name,
821+
curry,
822+
#[cfg(not(feature = "no_function"))]
823+
env,
824+
typ,
825+
} = fn_ptr;
824826

825827
// Adding the curried arguments and the remaining arguments
826828
let mut curry = curry.into_iter().collect::<FnArgsVec<_>>();
@@ -871,7 +873,7 @@ impl Engine {
871873
// Recalculate hash
872874
let num_args = args.len();
873875

874-
let new_hash = if !is_anon && !is_valid_function_name(&name) {
876+
let new_hash = if !_is_anon && !is_valid_function_name(&name) {
875877
FnCallHashes::from_native_only(calc_fn_hash(None, &name, num_args))
876878
} else {
877879
#[cfg(not(feature = "no_function"))]
@@ -954,7 +956,17 @@ impl Engine {
954956
_linked = Some((Some(fn_def.clone()), None, fn_ptr.env.clone()))
955957
}
956958
FnPtrType::Native(ref func) => {
957-
_linked = Some((None, Some(func.clone()), fn_ptr.env.clone()))
959+
_linked = Some((
960+
#[cfg(not(feature = "no_function"))]
961+
None,
962+
#[cfg(feature = "no_function")]
963+
Option::<()>::None,
964+
Some(func.clone()),
965+
#[cfg(not(feature = "no_function"))]
966+
fn_ptr.env.clone(),
967+
#[cfg(feature = "no_function")]
968+
Option::<()>::None,
969+
))
958970
}
959971
_ => {
960972
let _is_anon = false;
@@ -1086,15 +1098,17 @@ impl Engine {
10861098
)
10871099
})?;
10881100

1089-
let (
1090-
is_anon,
1091-
FnPtr {
1092-
name,
1093-
curry: extra_curry,
1094-
env,
1095-
typ,
1096-
},
1097-
) = (fn_ptr.is_anonymous(), fn_ptr);
1101+
let _is_anon = false;
1102+
#[cfg(not(feature = "no_function"))]
1103+
let _is_anon = fn_ptr.is_anonymous();
1104+
1105+
let FnPtr {
1106+
name,
1107+
curry: extra_curry,
1108+
#[cfg(not(feature = "no_function"))]
1109+
env,
1110+
typ,
1111+
} = fn_ptr;
10981112

10991113
curry.extend(extra_curry);
11001114

@@ -1164,7 +1178,7 @@ impl Engine {
11641178
// Recalculate hash
11651179
let args_len = num_args + curry.len();
11661180

1167-
hashes = if !is_anon && !is_valid_function_name(fn_name) {
1181+
hashes = if !_is_anon && !is_valid_function_name(fn_name) {
11681182
FnCallHashes::from_native_only(calc_fn_hash(None, fn_name, args_len))
11691183
} else {
11701184
FnCallHashes::from_hash(calc_fn_hash(None, fn_name, args_len))

src/module/mod.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2350,6 +2350,7 @@ impl Module {
23502350
let _ = result?;
23512351

23522352
// Encapsulated environment
2353+
#[cfg(not(feature = "no_function"))]
23532354
let env = Shared::new(crate::ast::EncapsulatedEnviron {
23542355
#[cfg(not(feature = "no_function"))]
23552356
lib: ast.shared_lib().clone(),
@@ -2363,15 +2364,16 @@ impl Module {
23632364
while i > 0 {
23642365
i -= 1;
23652366

2366-
let (mut value, mut aliases) = if i >= orig_scope_len {
2367+
let (mut _value, mut aliases) = if i >= orig_scope_len {
23672368
let (_, v, a) = scope.pop_entry().unwrap();
23682369
(v, a)
23692370
} else {
23702371
let (_, v, a) = scope.get_entry_by_index(i);
23712372
(v.clone(), a.to_vec())
23722373
};
23732374

2374-
value.deep_scan(|v| {
2375+
#[cfg(not(feature = "no_function"))]
2376+
_value.deep_scan(|v| {
23752377
if let Some(fn_ptr) = v.downcast_mut::<crate::FnPtr>() {
23762378
fn_ptr.env = Some(env.clone());
23772379
}
@@ -2382,7 +2384,7 @@ impl Module {
23822384
1 => {
23832385
let alias = aliases.pop().unwrap();
23842386
if !module.contains_var(&alias) {
2385-
module.set_var(alias, value);
2387+
module.set_var(alias, _value);
23862388
}
23872389
}
23882390
_ => {
@@ -2396,12 +2398,12 @@ impl Module {
23962398
if first_alias.is_none() {
23972399
first_alias = Some(alias);
23982400
} else {
2399-
module.set_var(alias, value.clone());
2401+
module.set_var(alias, _value.clone());
24002402
}
24012403
}
24022404

24032405
if let Some(alias) = first_alias {
2404-
module.set_var(alias, value);
2406+
module.set_var(alias, _value);
24052407
}
24062408
}
24072409
}

src/packages/array_basic.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,7 @@ pub mod array_functions {
12721272
let comparer = FnPtr {
12731273
name: ctx.engine().get_interned_string(OP_EQUALS),
12741274
curry: <_>::default(),
1275+
#[cfg(not(feature = "no_function"))]
12751276
env: None,
12761277
typ: FnPtrType::Normal,
12771278
};

src/parser.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ use crate::tokenizer::{
1313
is_reserved_keyword_or_symbol, is_valid_function_name, is_valid_identifier, Token, TokenStream,
1414
TokenizerControl,
1515
};
16-
use crate::types::{
17-
dynamic::{AccessMode, Union},
18-
fn_ptr::FnPtrType,
19-
};
16+
use crate::types::dynamic::{AccessMode, Union};
2017
use crate::{
2118
calc_fn_hash, Dynamic, Engine, EvalAltResult, EvalContext, ExclusiveRange, FnArgsVec,
2219
ImmutableString, InclusiveRange, LexError, ParseError, Position, Scope, Shared, SmartString,
@@ -3814,8 +3811,9 @@ impl Engine {
38143811
let fn_ptr = crate::FnPtr {
38153812
name: fn_name,
38163813
curry: ThinVec::new(),
3814+
#[cfg(not(feature = "no_function"))]
38173815
env: None,
3818-
typ: FnPtrType::Normal,
3816+
typ: crate::types::fn_ptr::FnPtrType::Normal,
38193817
};
38203818

38213819
let expr = Expr::DynamicConstant(Box::new(fn_ptr.into()), new_settings.pos);

src/types/dynamic.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ impl Hash for Dynamic {
406406
Union::Blob(ref a, ..) => a.hash(state),
407407
#[cfg(not(feature = "no_object"))]
408408
Union::Map(ref m, ..) => m.hash(state),
409+
#[cfg(not(feature = "no_function"))]
409410
Union::FnPtr(ref f, ..) if f.env.is_some() => {
410411
unimplemented!("FnPtr with embedded environment cannot be hashed")
411412
}
@@ -1216,7 +1217,9 @@ impl Dynamic {
12161217
Union::Blob(..) => true,
12171218
#[cfg(not(feature = "no_object"))]
12181219
Union::Map(ref m, ..) => m.values().all(Self::is_hashable),
1219-
Union::FnPtr(ref f, ..) => f.env.is_none() && f.curry().iter().all(Self::is_hashable),
1220+
#[cfg(not(feature = "no_function"))]
1221+
Union::FnPtr(ref f, ..) if f.env.is_some() => false,
1222+
Union::FnPtr(ref f, ..) => f.curry().iter().all(Self::is_hashable),
12201223
#[cfg(not(feature = "no_time"))]
12211224
Union::TimeStamp(..) => false,
12221225

src/types/fn_ptr.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! The `FnPtr` type.
22
3-
use crate::ast::EncapsulatedEnviron;
43
use crate::func::FnCallArgs;
54
use crate::tokenizer::{is_reserved_keyword_or_symbol, is_valid_function_name, Token};
65
use crate::types::dynamic::Variant;
@@ -58,7 +57,8 @@ pub struct FnPtr {
5857
/// Curried arguments.
5958
pub(crate) curry: ThinVec<Dynamic>,
6059
/// Encapsulated environment.
61-
pub(crate) env: Option<Shared<EncapsulatedEnviron>>,
60+
#[cfg(not(feature = "no_function"))]
61+
pub(crate) env: Option<Shared<crate::ast::EncapsulatedEnviron>>,
6262
/// Type of function pointer.
6363
pub(crate) typ: FnPtrType,
6464
}
@@ -326,7 +326,10 @@ impl FnPtr {
326326
caches,
327327
&mut crate::Scope::new(),
328328
this_ptr,
329+
#[cfg(not(feature = "no_function"))]
329330
self.env.as_deref(),
331+
#[cfg(feature = "no_function")]
332+
None,
330333
fn_def,
331334
args,
332335
true,
@@ -496,6 +499,7 @@ impl TryFrom<ImmutableString> for FnPtr {
496499
Ok(Self {
497500
name: value,
498501
curry: ThinVec::new(),
502+
#[cfg(not(feature = "no_function"))]
499503
env: None,
500504
typ: FnPtrType::Normal,
501505
})
@@ -518,6 +522,7 @@ impl<T: Into<Shared<crate::ast::ScriptFuncDef>>> From<T> for FnPtr {
518522
Self {
519523
name: fn_def.name.clone(),
520524
curry: ThinVec::new(),
525+
#[cfg(not(feature = "no_function"))]
521526
env: None,
522527
typ: FnPtrType::Script(fn_def),
523528
}

tests/fn_ptr.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -189,21 +189,8 @@ fn test_fn_ptr_embed() {
189189
})
190190
.unwrap();
191191

192-
let f2 = FnPtr::from_fn("foo", |_, args| {
193-
if args.len() != 2 {
194-
panic!();
195-
}
196-
let y = args[1].as_int().unwrap();
197-
let map = &mut *args[0].write_lock::<rhai::Map>().unwrap();
198-
let x = &mut *map.get_mut("a").unwrap().write_lock::<INT>().unwrap();
199-
*x += y;
200-
Ok(Dynamic::UNIT)
201-
})
202-
.unwrap();
203-
204192
let mut scope = Scope::new();
205193
scope.push("f1", f1);
206-
scope.push("f2", f2);
207194

208195
assert_eq!(
209196
engine
@@ -221,6 +208,20 @@ fn test_fn_ptr_embed() {
221208

222209
#[cfg(not(feature = "no_object"))]
223210
{
211+
let f2 = FnPtr::from_fn("foo", |_, args| {
212+
if args.len() != 2 {
213+
panic!();
214+
}
215+
let y = args[1].as_int().unwrap();
216+
let map = &mut *args[0].write_lock::<rhai::Map>().unwrap();
217+
let x = &mut *map.get_mut("a").unwrap().write_lock::<INT>().unwrap();
218+
*x += y;
219+
Ok(Dynamic::UNIT)
220+
})
221+
.unwrap();
222+
223+
scope.push("f2", f2);
224+
224225
assert_eq!(
225226
engine
226227
.eval_with_scope::<INT>(

0 commit comments

Comments
 (0)