* 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>
* 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>
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`
* Optimize Random.sample(_, _) for performance
* Make tests treat random samples as unordered
* Test all sample sizes possible
* Tweak random sampling algorithm for performance
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.
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.
The VM used to not detect this case. It meant you could get into a
situation where another fiber's caller had completed. Then, when it
tried to resume that fiber, the VM would crash because there was nothing
to resume to.
This is part of thinking through all the cases around re-entrancy. Added
some notes for that too.