505 Commits

Author SHA1 Message Date
a346494922 Documents 'return from module'. (#976)
Fixes #974.
2021-04-16 11:09:28 -07:00
4a18fc489f tests; maps; remove test that now asserts in debug
for now, as there doesn't seem to be a way to test for that , it fails CI
2021-04-08 21:46:31 -07:00
a4ae905384 Introduce Attributes (#962)
* introduce Attributes for classes and methods
2021-04-08 21:30:09 -07:00
059e407ed3 wren/compiler: Allow multiline empty parameter lists and calls. (#925) 2021-04-07 22:58:46 -07:00
041f1bab8d Fix returning from constructors (#845)
* Fix returning from constructors

 1. Do not allow returning with a value
 2. Return the instance, correctly, even when the user returned explicitly

* revise error message for consistency, revise implementation details a bit, fix extra args to finishBody

* clarify tests a bit

* document constructor return

Co-authored-by: ruby0x1 <ruby0x1@pm.me>
2021-04-07 22:53:05 -07:00
68f5c096d8 Disallow non-Num arguments in Num for min(_), max(_), clamp(_,_), pow(_) and atan(_) (#859)
* Disallow non-Num arguments in `Num.min(_)`, `Num.max(_)`, `Num.clamp(_,_)`

Previously this was an Undefined Behavior

* also validate args for pow, atan2, add tests, fix error messages

Co-authored-by: ruby0x1 <ruby0x1@pm.me>
2021-04-07 22:04:58 -07:00
28da4b449c Add Num.[max/min]SafeInteger (#874) 2021-04-07 21:45:00 -07:00
e3c76a3e76 Raw strings now ignore whitespace on both ends for consistency and clarity
added more tests, updated documentation
2021-04-04 22:28:57 -07:00
981ea4adf1 Add raw string literals
Also document + test multi line literals.
2021-04-04 13:52:32 -07:00
615a6aa208 try; fix random and meta properly 2021-04-03 22:09:19 -07:00
ecce1f6be9 List; add remove(value)
Having to encode this behaviour at every call site is tedious. It makes a lot of sense to just have the method available on list itself.
2021-04-03 19:55:42 -07:00
4d1d0d972e rename some test functions that clash with libc (#936)
* rename some test functions that clash with cosmopolitan libc
2021-03-07 16:38:29 -08:00
0fa16a20ec Fix deprecated Python timing in benchmark & give more error info. (#844)
- Note: process_time gives CPU time used and perf_counter is absolute time used.
- Looks to have noise of about 1-2%.
2021-01-30 21:40:20 -08:00
ce599259bc wren/core: Add Num::cbrt. (#905) 2021-01-30 21:13:58 -08:00
7d3f063e87 Merge branch 'next-token' into main 2020-12-03 13:43:40 -08:00
8361217369 Num; add min, max and clamp 2020-12-03 13:18:13 -08:00
38f50fe091 List; add swap(index0, index1) 2020-12-03 13:17:53 -08:00
62009870a8 List; add indexOf(value) 2020-12-03 13:17:26 -08:00
3d5e68fc01 Added List.sort(comp) to List module (#802) 2020-12-03 11:59:07 -08:00
08d2fa3821 fix paste issues from https://github.com/wren-lang/wren/pull/798/ 2020-12-03 11:55:31 -08:00
76fb4f311b Test static operators (#798)
In #797 it was stated that static operators are valid in Wren, and proposed to check this behavior
2020-12-03 11:47:42 -08:00
84b29e6995 Add userData pointer to reallocateFn (#788)
* Add userData ptr to all reallocateFn calls
* Check that userData is correctly passed
* Update AUTHORS
2020-12-03 11:46:22 -08:00
182ca90b8c add wrenHasVariable and wrenHasModule 2020-12-03 11:13:04 -08:00
97ebcc72c3 Add wrenSetListElement, correctly allow negative indices on wrenGetListElement 2020-12-03 10:30:47 -08:00
3e0f71b742 [0.4.0] Import as (#775)
* Add import "..." for Variable as OtherName
2020-12-03 09:34:36 -08:00
6bd2f810e2 [0.4.0] Introduce WrenLoadModuleResult, fix unfreed strings from host. (#778) 2020-12-03 09:27:54 -08:00
55b926410d Add continue statement (#822)
Note that documentation is still required.
2020-12-03 08:30:36 -08:00
f5339993ce Add support for Fiber.try(_) (#835)
* Add support for Fiber.try(_)
* Add documentation for Fiber.try(_)
* Add another test for Fiber.try(_)
2020-12-03 08:21:37 -08:00
44d6d20586 Do not allow inheriting built-in classes Num, Bool and Null (#831)
* Do not allow inheriting `Num`, `Bool` and `Null`. fixes #830
2020-10-26 08:39:36 -07:00
3c475f01ee allow newline before dot for subscript as well, and add to tests 2020-09-19 22:03:16 -07:00
4c496c56a6 allow a newline before dot usage, for chained/fluent interfaces 2020-09-19 20:40:24 -07:00
45c67fae0c Fn call: move arity check into interpret loop, which avoid the expensive if after the call, since runtime errors originating inside the call itself will still be handled, we only have the one emitted from call itself.
This brings the benchmark back up to where it was.
2020-09-18 15:42:37 -07:00
5b0f8740f2 Revert "Extended test for Random.sample to cover both branches (#715)"
This reverts commit f81cb5d23c.
2020-07-18 20:10:22 -07:00
f81cb5d23c Extended test for Random.sample to cover both branches (#715)
I've verified that this test fails without the fix in change
186a8c7c13.

See issue #713
2020-07-14 20:15:12 -07:00
54b4c233b9 test: Fix some tests so they fail on expected error, not on syntax error. (#779) 2020-07-14 20:14:08 -07:00
58611240e7 Remove magic values as exit codes in test application (#777) 2020-07-11 13:30:43 -07:00
a3f5b3d98f wren/vm: Allow wrenInterpret to call foreign function (complement 344d343 at fixing #730). (#764) 2020-07-11 13:05:22 -07:00
433fbc4019 core; num; add exp & log2
I've had a couple use cases in time that the code is significantly clearer with these, and makes porting less error prone
2020-07-10 19:38:45 -07:00
8be40ec14e runFile: Free file source before exiting the function (#774)
This prevents a memleak, noticeable when running `wren_test` under
`valgrind`. For example, the following command would leak

`./bin/wren_test_d any_example.wren`
2020-07-09 11:54:21 -07:00
de6a312868 Functions for operating on Maps from C (#725)
new API functions for maps:
wrenSetSlotNewMap
wrenGetMapCount
wrenGetMapContainsKey
wrenGetMapValue
wrenSetMapValue
wrenRemoveMapValue
2020-06-14 14:45:23 -07:00
344d3432b3 Fix slot array corrupted by wrenInterpret() (#730) 2020-06-13 21:42:06 -07:00
7983082b71 Support positive sign in scientific notation (#706)
* Support positive sign in scientific notation
* Add exponent with positive sign to docs
2020-06-13 21:37:30 -07:00
f3493d0499 Optimize Random.sample(_, _) for performance (#716)
* Optimize Random.sample(_, _) for performance
* Make tests treat random samples as unordered
* Test all sample sizes possible
* Tweak random sampling algorithm for performance
2020-06-13 21:31:23 -07:00
d585a080e8 Merge pull request #751 from wren-lang/0.3.0-refactor
0.3.0 refactor
2020-06-05 14:57:20 -07:00
3eb4ac1419 Add a clearer error message for forward declared lowercase variables (#699)
* Add better error messaging for forward referenced top level variables, see #467
* add test case
2019-09-30 20:30:27 -07:00
898e5356c7 Merge pull request #562 from Salmela/locals-array-overflow-fix
Check that there is space in local variable array
2019-09-18 00:20:03 -07:00
f91586a71a Fix wrenAbortFiber does not work inside of foreign class allocator 2019-09-17 19:43:53 +02:00
2a1499b04b Fix horrendously bad bit hashing function.
hashBits() is used to generate a hash code from the same 64 bits used
to represent a Wren number as a double. When building a map containing
a large number of integer keys, it's important for this to do a good
job scattering the bits across the 32-bit key space.

Alas, it does not. Worse, the benchmark to test this happens to stop
just before the performance falls off a cliff, so this was easy to
overlook.

This replaces it with the hash function V8 uses, which has much better
performance across the numeric range.
2019-07-27 13:34:07 -07:00
a437e804ba Added String.fromByte with docs and unit test 2019-02-27 08:10:54 -05:00
a5147aa2d9 Add a limited form of re-entrant calls.
This doesn't let you arbitrarily call back into the VM from within
foreign methods. I'm still not sure if that's even a good idea since
God knows what that would mean if you switch fibers while doing that.

But this does allow the very important use case of being able to call
a foreign method from within a call to wrenCall(). In other words,
foreign methods need to always be leaf calls on the call stack, but the
root of that stack can now come from runInterpreter() or wrenCall().

Fix #510.
2019-02-08 17:09:39 -08:00