Commit Graph

2347 Commits

Author SHA1 Message Date
Stephen Chung
b6528bd51d Reduce usage of as_ref and as_mut. 2022-07-05 16:26:38 +08:00
Stephen Chung
9319f87a7b Fix builds. 2022-07-04 17:47:59 +08:00
Stephen Chung
dee66a409f Add case alternatives for switch. 2022-07-04 17:42:24 +08:00
Stephen Chung
6753566b03 Merge set of dynamic functions when merging modules. 2022-06-28 13:57:18 +08:00
Stephen Chung
0031678cd4 Fix shared variable assignment. 2022-06-26 18:09:15 +08:00
Stephen Chung
d9875ff81c Fix sync feature. 2022-06-26 17:14:10 +08:00
Stephen Chung
335957fbc2 Enable modifying constant shared values. 2022-06-26 17:04:08 +08:00
Stephen Chung
7068775f19 Use locked_read. 2022-06-26 14:10:09 +08:00
Stephen Chung
84b8e1ed87 Detect whether dynamic functions exist to save checking. 2022-06-24 11:30:54 +08:00
Stephen Chung
d6bfd8f617 Streamline step ranges. 2022-06-20 18:52:07 +08:00
Stephen Chung
addb579f30 Streamline Dynamic. 2022-06-17 23:36:18 +08:00
Stephen Chung
b592ac1599 Export locked_read. 2022-06-17 23:36:09 +08:00
Stephen Chung
6ea5ed17f4 Use rhai for ignore. 2022-06-12 15:04:06 +08:00
Stephen Chung
2b44778a5c Add elvis operator for indexing. 2022-06-12 00:32:12 +08:00
Stephen Chung
b9cbeb65d6 Use Option instead of once/empty. 2022-06-11 16:01:15 +08:00
Stephen Chung
8999872d62 Add null coalescing operator. 2022-06-10 11:22:33 +08:00
Stephen Chung
0f1e51b1c9 Support Elvis operator. 2022-06-10 10:26:06 +08:00
Stephen Chung
206318e14c Add new reserved symbols. 2022-06-10 08:47:22 +08:00
Stephen Chung
09e19790fe Fix builds. 2022-06-09 18:22:53 +08:00
Stephen Chung
a31a4e4887 Fix builds. 2022-06-09 18:06:00 +08:00
Stephen Chung
dcaac20eb9 Strict mode in functions check for static modules. 2022-06-09 17:59:28 +08:00
Stephen Chung
285bf23dfa Minor refactor. 2022-06-09 08:41:51 +08:00
Stephen Chung
e5f6b28abd Fix warnings. 2022-06-08 17:06:49 +08:00
Stephen Chung
bbaad8dfcb Speed up method calls. 2022-06-08 16:34:56 +08:00
Stephen Chung
f4ebaa7abf Improve chaining speed. 2022-06-08 09:19:21 +08:00
Stephen Chung
8615960cd6 Fix feature. 2022-06-07 20:52:04 +08:00
Stephen Chung
8501d9d33f Improve speed on common dot/index expressions. 2022-06-07 20:38:05 +08:00
Stephen Chung
84e3296559 Fix bug on chaining function calls returning shared values. 2022-06-07 11:31:46 +08:00
Stephen Chung
005692ef78 Change volatile API message. 2022-06-06 08:54:19 +08:00
Stephen Chung
6467b52761 Fix no_function. 2022-06-05 19:35:18 +08:00
Stephen Chung
6ebe002b18 Check for missing docs. 2022-06-05 18:17:44 +08:00
Stephen Chung
c200a609ea Change FnPtr to struct. 2022-05-26 18:18:09 +08:00
Stephen Chung
493c4a71ff Add lifetime. 2022-05-26 18:17:46 +08:00
Stephen Chung
99bcd8497a Remove lifetime on OpAssignment. 2022-05-26 18:17:08 +08:00
Stephen Chung
0e363bd6b7 Make Caches a struct. 2022-05-24 19:34:47 +08:00
Stephen Chung
52bb6e68e8 Add Scope::get. 2022-05-24 16:05:17 +08:00
Stephen Chung
07d3dd6882 Add lifetime to Caches. 2022-05-24 11:52:03 +08:00
Geoffroy Couprie
f2b5566c0b use smartstring's deserializer to support non borrowed strings
The map visitor for Dynamic was expecting a &str for the key, but the
serde_json deserializer internally uses a Cow string, which can be
Borrowed or Owned. In the case of Owned, the serde_json key deserializer
is calling visit_string on the Visitor, which for &str will result in
the error:
Error("invalid type: string \"a\", expected a borrowed string", line: 0,
column: 0)

smartstring actually has its own Visitor implementation that handles
both cases, so we can use it instead of an explicit conversion.
2022-05-23 16:40:49 +02:00
Stephen Chung
ee886fc719 Fix builds. 2022-05-21 22:13:02 +08:00
Stephen Chung
1abec0a8a8 Allow initialization of EvalState tag and separate debugger state into separate variable. 2022-05-21 21:44:12 +08:00
Stephen Chung
9c1a49da0b Fix AST combine. 2022-05-21 11:31:15 +08:00
Stephen Chung
46c1d86221 Fix merge AST with self-contained AST. 2022-05-20 21:49:27 +08:00
Stephen Chung
8f73796110 Fix builds. 2022-05-19 21:49:19 +08:00
Stephen Chung
130b93d029 Use bit-flags for options. 2022-05-19 21:40:22 +08:00
Stephen Chung
857ae7a64a Comments update. 2022-05-19 14:41:48 +08:00
Stephen Chung
dd8c18369b Use call_native_fn. 2022-05-19 14:36:58 +08:00
Stephen Chung
47d0d014e3 Reduce cloning. 2022-05-19 14:32:43 +08:00
Stephen Chung
a53bcc2e1d Add EvalAltResult::IndexNotFound. 2022-05-19 10:02:12 +08:00
Stephen Chung
7c8c6659ae Better encapsulate EvalContext. 2022-05-17 16:21:17 +08:00
Stephen Chung
04df4d2547 Fix indexing parsing. 2022-05-17 11:06:34 +08:00
Stephen Chung
c7aea45d4b Add to_int for decimal. 2022-05-09 14:20:33 +08:00
Stephen Chung
b4fea634b0 Avoid unnecessary allocations. 2022-05-07 16:29:20 +08:00
Stephen Chung
4194e2c048 Refine data structures. 2022-05-07 15:54:44 +08:00
Stephen Chung
fc64e93b93 Deprecate FnPtr::num_curried. 2022-05-05 22:30:55 +08:00
Stephen Chung
b23d64bec0 Fix bug with using self-contained AST with call_fn. 2022-05-05 21:34:15 +08:00
Stephen Chung
2a57bd9d25 Mark some types as non_exhaustive. 2022-05-03 21:55:08 +08:00
Stephen Chung
516f5a82a0 Use tag for debugger state. 2022-05-03 21:55:01 +08:00
Stephen Chung
4f74d2f96a Minor cleanup. 2022-05-02 12:14:53 +08:00
Stephen Chung
c69f98c2c4 Add custom state. 2022-05-02 00:03:45 +08:00
Stephen Chung
98e0042214 Fix build. 2022-04-26 18:32:43 +08:00
Stephen Chung
2889ca0988 Add Start/End to DebuggerEvent. 2022-04-26 16:36:24 +08:00
Stephen Chung
34dfe841cd Add commands to rhai-dbg. 2022-04-24 16:06:11 +08:00
Stephen Chung
5a756e0899 Remove generics for call_fn_raw_raw. 2022-04-23 15:25:00 +08:00
Stephen Chung
1d904f4758 Add Engine::eval_statements_raw. 2022-04-23 13:37:08 +08:00
Stephen Chung
0ef5c0ec54 Change to call_fn_raw_raw. 2022-04-23 13:28:26 +08:00
Stephen Chung
d61f7fa7c2 Add call_fn_with_global_raw. 2022-04-23 13:15:27 +08:00
Stephen Chung
63592ed648 Remove Clone from FileModuleResolver. 2022-04-23 12:49:03 +08:00
Stephen Chung
c2a796f9c2 Replace Scope display code. 2022-04-23 11:53:34 +08:00
Stephen Chung
5a75479119 Fix bug in Scope cloning. 2022-04-23 11:53:17 +08:00
Stephen Chung
71bc605fe6 Add scope to FileModuleResolver. 2022-04-22 13:39:51 +08:00
Stephen Chung
2755d39cdf Return early if no type casting for call_fn. 2022-04-22 12:12:55 +08:00
Stephen Chung
a6c2c00479 Allow variables in scope for strict vars. 2022-04-22 12:12:36 +08:00
Stephen Chung
6f4cc91451 Fix builds. 2022-04-21 16:01:20 +08:00
Stephen Chung
6b8ddd925b Allow scope constants in strict variables mode. 2022-04-21 13:21:53 +08:00
Stephen Chung
c3d013bddc Add to_json for maps. 2022-04-21 12:15:21 +08:00
Stephen Chung
4f2764d233 Revise parse_json. 2022-04-21 10:04:57 +08:00
Stephen Chung
5e4f27ae25 Add Token::Unit. 2022-04-21 10:04:46 +08:00
Stephen Chung
299d6ef308 Type checking in switch case condition. 2022-04-19 21:45:11 +08:00
Stephen Chung
770b2e04cc Simplify switch condition. 2022-04-19 16:20:43 +08:00
Stephen Chung
40c4906336 Make Module::eval_ast_as_new_raw public. 2022-04-19 08:28:59 +08:00
Stephen Chung
f9ee0c29be Fix builds. 2022-04-18 23:24:08 +08:00
Stephen Chung
60a933862e Streamline op-assignments. 2022-04-18 23:12:47 +08:00
Stephen Chung
3f74e5e674 Use &Path as source path. 2022-04-18 17:34:53 +08:00
Stephen Chung
daf73d5341 Make caches optional for EvalContext. 2022-04-16 23:32:14 +08:00
Stephen Chung
855cb76246 Rename EvalState to Caches. 2022-04-16 16:36:53 +08:00
Stephen Chung
b696390c13 Fix no-std build. 2022-04-14 23:11:36 +08:00
Stephen Chung
3ff1ce0a19 Fix compound assignments with indexers. 2022-04-14 22:55:39 +08:00
Stephen Chung
7788e1058a Merge use. 2022-04-13 10:35:10 +08:00
Stephen Chung
a33e3ba5ff Fix build. 2022-04-11 16:34:56 +08:00
Stephen Chung
06608affc5 Fix rustyline patch. 2022-04-11 16:32:23 +08:00
Stephen Chung
63359f3f81 Unused parameters naming. 2022-04-11 16:29:16 +08:00
Stephen Chung
1777ee7f6f Allow strings to be iterable. 2022-04-09 13:37:43 +08:00
Stephen Chung
6422fddd6d Better names for iterators. 2022-04-09 13:11:32 +08:00
Stephen Chung
8bd33d7b34 Change string splitting. 2022-04-09 13:07:42 +08:00
Stephen Chung
42f977862f Add Dynamic parameters to qualified function calls. 2022-04-08 16:42:53 +08:00
Stephen Chung
89ed531363 Fix doc tests. 2022-04-06 17:25:04 +08:00
Stephen Chung
6f4240ed5a Add examples to Module custom type API. 2022-03-30 10:33:43 +08:00
Stephen Chung
56f6b181db Move optimization_level into Options. 2022-03-29 08:26:42 +08:00
Stephen Chung
1b6de25007 Remove Engine::custom_types. 2022-03-29 08:18:20 +08:00
Stephen Chung
95753bb9c3 Use global module constants in optimization. 2022-03-28 12:53:52 +08:00
Stephen Chung
42b6796200 Fix no-std build. 2022-03-28 12:53:49 +08:00
Stephen Chung
6369fa5c65 Minor refactor. 2022-03-27 21:53:50 +08:00
Stephen Chung
5caf20d26b Search for global variables in global modules. 2022-03-27 21:49:34 +08:00
Stephen Chung
2b10c33b81 Write JSON metadata to file for repl. 2022-03-26 18:19:42 +08:00
Stephen Chung
77c06b94a2 Use SmartString for comments. 2022-03-25 08:52:53 +08:00
Stephen Chung
cad4c7a942 Add starts_with and ends_with for strings. 2022-03-23 14:28:45 +08:00
Stephen Chung
99118fe2c3 Minor refactors. 2022-03-20 21:58:43 +08:00
Stephen Chung
1b3d5aeb53 fix no_module. 2022-03-19 10:29:21 +08:00
Stephen Chung
fefa633cf0 Add type alias support for plugin modules. 2022-03-19 09:43:18 +08:00
Stephen Chung
dc8c4ed8f4 Improve string functions. 2022-03-17 17:00:48 +08:00
Stephen Chung
63716759be Fix typo. 2022-03-14 11:28:52 +08:00
Stephen Chung
672cda63ab Simplify formatting. 2022-03-14 08:50:17 +08:00
Stephen Chung
a704d26986 Fixup ArgBackup. 2022-03-14 08:26:27 +08:00
Stephen Chung
963af0653e Fix sleep function. 2022-03-09 09:41:53 +08:00
Stephen Chung
1e4abd012c Minor refactor. 2022-03-09 09:25:55 +08:00
Stephen Chung
89426f8b3a Add Scope::set_alias. 2022-03-09 09:25:32 +08:00
Stephen Chung
cbb1c5c6a0 Add sleep. 2022-03-08 18:26:32 +08:00
Stephen Chung
b35d965e55 Reverse Box<[...]> to Vec. 2022-03-06 16:37:27 +08:00
Stephen Chung
165fbbc855 Fix no_module builds. 2022-03-05 18:32:50 +08:00
Stephen Chung
8bda8c64df Refine data structures 2022-03-05 17:57:23 +08:00
Stephen Chung
e06c2b2abb Remove constants in function call expressions. 2022-03-05 12:06:47 +08:00
Stephen Chung
0335035b0f Fix bug with eager optimization of method calls. 2022-03-04 12:22:44 +08:00
Stephen Chung
14e23ed74c Fix sync build. 2022-03-03 13:14:35 +08:00
Stephen Chung
0e9a16e437 Add checks for is_empty. 2022-03-03 13:02:57 +08:00
Stephen Chung
83755bf936 Refine doc comments. 2022-03-01 15:34:15 +08:00
Stephen Chung
99ca6de822 Respect barrier when reusing shadowed variable. 2022-02-28 22:13:03 +08:00
Stephen Chung
d41d36c8bb Simplify ParseState. 2022-02-28 16:32:08 +08:00
Stephen Chung
aee92f3b7b Move parser into Engine. 2022-02-28 14:37:46 +08:00
Stephen Chung
54a61bfe00 Pack Scope data more tightly. 2022-02-28 14:00:55 +08:00
Stephen Chung
15448bf660 Forbid shadowing of state variable. 2022-02-27 22:47:13 +08:00
Stephen Chung
b17e891b63 Reduce size of Token. 2022-02-26 23:18:47 +08:00
Stephen Chung
61e6403ac6 Fix bug. 2022-02-26 17:44:39 +08:00
Stephen Chung
e767731953 Fix no_function feature. 2022-02-26 17:41:27 +08:00
Stephen Chung
9ef522b699 Use SmartString in parsing. 2022-02-26 17:28:58 +08:00
Stephen Chung
8205547d8a Use bitflags. 2022-02-25 11:42:59 +08:00
Stephen Chung
f47b911681 Remove warning. 2022-02-25 10:03:34 +08:00
Stephen Chung
07a61a9562 Fix build. 2022-02-25 09:00:15 +08:00
Stephen Chung
23c74cac61 Use boxed slices. 2022-02-25 08:38:03 +08:00
Stephen Chung
5931f43d4d Implement Ord and PartialOrd. 2022-02-25 08:37:57 +08:00
Stephen Chung
d2ad56e279 Improve string parameters. 2022-02-24 13:39:10 +08:00
Stephen Chung
39ef766bf1 Raise error when exporting local anonymous function. 2022-02-24 11:24:31 +08:00
Stephen Chung
73f10b8adc Minor housekeeping. 2022-02-24 10:36:20 +08:00
Stephen Chung
2f5ce2fe5b Deprecate Position::new_const. 2022-02-24 09:08:10 +08:00
Stephen Chung
fa8e2e638b Fix bug. 2022-02-23 15:43:27 +08:00
Stephen Chung
dd566ed1e1 Fix builds. 2022-02-19 12:26:17 +08:00
Stephen Chung
67a6638818 Allow variable to overwrite constant when shadowing. 2022-02-18 19:14:42 +08:00
Stephen Chung
78b5c9fd4e Fix bug in Scope::is_constant. 2022-02-18 19:13:09 +08:00
Stephen Chung
ef87ae48c1 Fix doc-test. 2022-02-18 16:21:20 +08:00
Stephen Chung
bb04fab011 Optimize variable shadowing. 2022-02-18 15:04:46 +08:00
Stephen Chung
83786c992b Fix parser bug. 2022-02-18 11:05:58 +08:00
Stephen Chung
1011602cf6 Fix no-std build. 2022-02-16 18:05:09 +08:00
Stephen Chung
0d2e3d82f3 Reduce size of Stmt. 2022-02-16 17:51:14 +08:00
Stephen Chung
cf0660e36b Expand StmtBlock inline size. 2022-02-16 12:57:26 +08:00
Stephen Chung
3db918e89a Doc fixup. 2022-02-15 19:56:42 +08:00
Stephen Chung
84face341a Fix doc comments. 2022-02-15 15:49:03 +08:00
Stephen Chung
fb9964e1a3 Revise on_def_var API. 2022-02-15 10:56:05 +08:00
Stephen Chung
5bb6ce835f Run var def filter during parsing. 2022-02-13 18:46:25 +08:00
Stephen Chung
664e3d31e5 BLOB's and strings. 2022-02-12 23:39:07 +08:00
Stephen Chung
83e1e88531 Add specific implementations for to_string. 2022-02-12 16:23:36 +08:00
Stephen Chung
fda94c1cb6 Better printing. 2022-02-11 22:43:09 +08:00
Stephen Chung
41caa233bb Fix string parsing. 2022-02-10 18:24:04 +08:00
Stephen Chung
d23d1159ab Fix positions. 2022-02-10 17:55:32 +08:00
Stephen Chung
3050e38c5e Fix interpolated string position. 2022-02-10 14:51:31 +08:00
Stephen Chung
d1a97be9e3 New syntax for package definition. 2022-02-10 12:33:48 +08:00
Stephen Chung
1c89c6be4f Doc fixes. 2022-02-10 08:31:41 +08:00
Stephen Chung
8c5de09446 Fix doc links. 2022-02-09 22:40:13 +08:00
Stephen Chung
e5a673b3ae Add position info for closures. 2022-02-09 13:40:51 +08:00
Stephen Chung
340a047369 Add fail on invalid property for maps. 2022-02-09 13:12:43 +08:00
Stephen Chung
6acc486e00 Revise keys for Windows vs Unix 2022-02-09 08:39:33 +08:00
Stephen Chung
ddc66e7fb8 Print this. 2022-02-09 08:11:26 +08:00
Stephen Chung
1b4184ef16 Run debugger with no optimization. 2022-02-09 08:00:05 +08:00
Stephen Chung
3b9dbd5fce Add Span. 2022-02-08 23:01:47 +08:00
Stephen Chung
c64fc6f523 No astu under no_optimize. 2022-02-08 22:30:48 +08:00
Stephen Chung
0cf2cd5cfc Do not trim script lines. 2022-02-08 22:29:38 +08:00
Stephen Chung
5e7db6e105 Use new version of rustyline. 2022-02-08 22:16:12 +08:00
Stephen Chung
8cf6f424a5 Use turbofish notation. 2022-02-08 21:28:15 +08:00
Stephen Chung
83b213b086 Unwrap error when caught. 2022-02-08 19:02:40 +08:00
Stephen Chung
7686ca619a Use .. for (_). 2022-02-08 09:46:14 +08:00
Stephen Chung
97a8fd3d5b Improve reify syntax. 2022-02-08 09:25:53 +08:00
Stephen Chung
f8cee0fe4e Simplify using .. 2022-02-08 09:02:15 +08:00
Stephen Chung
187a20fd8b Refactor OptimizationLevel. 2022-02-07 21:03:39 +08:00
Stephen Chung
556b2393f5 Fix position of function calls. 2022-02-07 16:02:49 +08:00
Stephen Chung
bd9519e96b Remove reify_dynamic. 2022-02-07 12:02:00 +08:00
Stephen Chung
becbfa8930 Fix errors. 2022-02-06 23:02:59 +08:00
Stephen Chung
1ccbda1050 Merge branch 'master' of https://github.com/schungx/rhai 2022-02-06 21:24:55 +08:00
Stephen Chung
cfbf0397a6 Better position of assignment errors. 2022-02-06 21:24:02 +08:00
Nathan Kent
86d86a85e4 Remove unsound casting functions
The casting functions in `unsafe.rs` were unsound (i.e., they allowed
safe code to cause undefined behavior). While they did appear to be used
in a way that wouldn't cause UB the fact that there exists unsound
functions is unsettling.

This commit removes those functions and replaces it with a macro that
performs the same reification - the difference is that the macro call
will also include the checks which are required to prevent UB. A macro
was chosen instead of a function for two reasons:

1. A macro can keep the same code generation whereas a function would
   require going through an `Option` which has negative impacts on code
   generation (niche values cause poor DCE).
2. There exist other `unsafe` code blocks in the crate and an attempt to
   make Rhai 100% safe is completely out-of-scope for this merge
   request, so we may as well use `unsafe` in the macro.

Regarding (2) above, I may come back at a later date with a 100% safe
`reify` function but only once the other `unsafe` blocks are removed.
For posterity, said function would look something like:

```rust
fn reify<A: Any, C>(value: A) -> Option<C> {
    let mut v = Some(value);
    let v: &mut dyn Any = &mut v;
    v.downcast_mut::<Option<C>>().map(Option::take)
}
```
2022-02-05 16:29:05 -08:00
Stephen Chung
6a740a9fa1 Fix no_module build. 2022-02-04 23:08:09 +08:00
Stephen Chung
be9356727f Add variable definition filter. 2022-02-04 22:59:41 +08:00
Stephen Chung
936dc01e39 Pass level to var resolver. 2022-02-04 22:16:12 +08:00
Stephen Chung
5aee06674f Fix no-std build. 2022-02-04 16:38:01 +08:00
Stephen Chung
f09abd7ab3 Fix builds. 2022-02-04 13:31:33 +08:00
Stephen Chung
3be27746e0 Add allow_shadowing. 2022-02-04 13:20:47 +08:00
Stephen Chung
6c1c8bc538 Improve position display. 2022-02-04 12:04:33 +08:00
Stephen Chung
345a060672 Fix type name display. 2022-02-03 23:54:53 +08:00
Stephen Chung
419ee45043 Add bin-features to pull in all features for bin tools. 2022-02-03 21:17:47 +08:00
Stephen Chung
9fa6839380 Simplify debugger calls. 2022-02-03 11:56:08 +08:00
Stephen Chung
8322e62c18 Fix function exit trigger and add function enter trigger. 2022-02-02 22:42:33 +08:00
Stephen Chung
db2f1a601c Make call stack available also under no_function. 2022-02-02 15:07:22 +08:00
Stephen Chung
e0ed713bb6 Fix builds. 2022-02-02 14:57:30 +08:00