1
0
forked from Mirror/wren
Commit Graph

505 Commits

Author SHA1 Message Date
e47f17567e Fix a couple more casts needed in C++. 2018-07-24 07:27:18 -07:00
c237a44b88 Add file to test directory so Git creates directory. 2018-07-24 07:15:04 -07:00
f23c82071a Don't allow calling the root fiber.
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.
2018-07-21 10:02:29 -07:00
7a42a20b98 Merge branch 'master' into smarter-imports
# Conflicts:
#	src/module/io.c
#	src/vm/wren_vm.c
2018-07-15 21:01:14 -07:00
c367fc3bfc Get logical imports in "wren_modules" working.
There's a lot of changes here and surely some rough edges to iron out.
Also, I need to update the docs. But I want to get closer to landing
this so I can build on it.
2018-07-15 20:09:41 -07:00
09f4beff4a Add trim methods on String:
- trim()
- trim(chars)
- trimEnd()
- trimEnd(chars)
- trimStart()
- trimStart(chars)
2018-07-15 10:48:56 -07:00
e7b1bade1a Check that there is space in local variable array
Otherwise it can overflow due to for loop's hidden
variables.

Fix #561
2018-06-13 00:59:55 +03:00
d03ef9e8b0 Move test and tweak code a bit. 2018-04-28 10:08:42 -07:00
4d056b6ec3 Merge branch 'master' of https://github.com/jclc/wren into jclc-master 2018-04-28 10:00:59 -07:00
8fae8e4f1e Don't overflow signature string if there are too many parameters.
Fix #494.
2018-04-27 09:13:40 -07:00
c5ce6fac46 Fix local variable declarations in the REPL.
A statement like:

  for (i in 1..2)

When run in the REPL declares a local variable ("i"), but not inside
a function or method body. This hit a corner case in the compiler
where it didn't have the correct slot indexes set up.

That corner case is because sometimes when you compile a chunk, local
slot zero is pre-allocated -- either to refer to "this" or to hold the
closure for a function so that it doesn't get GCed while running. But
if you're compiling top-level code, that slot isn't allocated. But top
level code for the REPL *should* be, because that gets invoked like a
function.

To simplify things, *every* compiled chunk now pre-allocates slot zero.
That way, there are fewer cases to keep in mind.

Also fixed an issue where a GC during an import could collected the
imported module body's closure.

Fix #456.
2018-04-27 08:20:49 -07:00
e66115c9fc add regression test for #520 2018-04-10 18:53:56 +03:00
8210452970 Relative imports!
This is a breaking change because existing imports in user Wren code
that assume the path is relative to the entrypoint file will now likely
fail.

Also, stack trace output and host API calls that take a module string
now need the resolved module string, not the short name that appears in
the import.
2018-03-24 11:10:36 -07:00
5539c59750 Add a minimal path manipulation C module.
This is just for the VM's own internal use, for resolving relative
imports.

Also added a tiny unit test framework for writing tests of low-level
C functionality that isn't exposed directly by the language or VM.
2018-03-24 10:58:07 -07:00
8a71735e0f Expose an API to let the host resolve relative import strings.
This is a breaking API change: wrenInterpret() now takes an additional
parameter for the module name to interpret the code in.
2018-03-23 07:54:09 -07:00
c5befa72cf Don't use module import string when loading imported variables.
This is an interim step towards supporting relative imports. Previously,
the IMPORT_VARIABLE instruction had a constant string operand for the
import string of the module to import the variable from. However, with
relative imports, the import string needs to be resolved by the host
all into a canonical import string. At that point, the original import
string in the source is no longer useful.

This changes that to have IMPORT_VARIABLE access the imported ObjModule
directly. It works in two pieces:

1. When a module is compiled, it ends with an END_MODULE instruction.
   That instruction stores the current ObjModule in vm->lastModule.

2. The IMPORT_VARIABLE instruction uses vm->lastModule as the module to
   load the variable from. Since no interesting code can execute between
   when a module body completes and the subsequent IMPORT_VARIABLE
   statements, we know vm->lastModule will be the one we imported.
2018-03-20 06:54:51 -07:00
2c88e19497 Compile imports to closures, not fibers.
This is simpler and marginally faster. We don't need the overhead of
fibers since you can't have long or recursive import chains anyway.

More importantly, this makes the behavior more well-defined when you do
things like yield from an imported module. (Not that you should do that,
but if you do, it shouldn't do weird things.)
2018-03-17 09:33:33 -07:00
1661f5368f Allow passing a value when first starting a fiber.
If the function the fiber is created from takes a parameter, the value
passed to the first call() or transfer() gets bound to that parameter.

Also, this now correctly handles fibers with functions that take
parameters. It used to leave the stack in a busted state. Now, it's a
runtime error to create a fiber with a function that takes any more
than one parameter.
2017-10-19 20:45:13 -07:00
c7087652ee Add regression tests from wren-fuzz.
These are all non-crashing now, so it looks like the underlying issue
is fixed. (It was probably #429.)

Fix #442.
2017-10-08 10:15:15 -07:00
c38d97b973 Properly detect a missing "}" in a block.
Fix #429.
2017-10-08 10:03:42 -07:00
eba0b97aa2 Merge pull request #472 from KyleCharters/master
Add Num .round
2017-10-06 07:51:55 -07:00
8963a870ff Abort all fibers along a call chain when one aborts. 2017-10-06 07:39:00 -07:00
0f19984017 Merge branch '201703_bubble_exceptions' of https://github.com/JonesAndrew/wren into JonesAndrew-201703_bubble_exceptions 2017-10-06 06:58:27 -07:00
84f2252c68 Add Num .round 2017-09-20 20:27:02 -04:00
d390e16a99 Kill duplicate test.
Fix #438.
2017-04-08 12:53:33 -07:00
7d631276cb Catch errors in the first try() 2017-03-30 21:57:29 -04:00
44a95e65c6 Set the token type after an invalid character error.
Otherwise, it still has the previous token's type. This can cause it
to get stuck in a loop in some places in the compiler.

Fix #428.
2017-03-23 21:19:20 -07:00
02bcefcbe4 Add test for user data.
Also moved the VM parameter in the error callback to be first like it
is in other callbacks.
2017-03-22 07:26:19 -07:00
8d313be3ce Make it an error to skip or take a negative count. 2017-03-15 07:22:44 -07:00
9f93119377 Merge branch 'take_and_skip' of https://github.com/bjorn/wren into bjorn-take_and_skip 2017-03-15 07:15:00 -07:00
9fcdf3dc0a Merge branch '201703_split_replace' of https://github.com/JonesAndrew/wren into JonesAndrew-201703_split_replace 2017-03-15 07:04:56 -07:00
32aa43d1df Split and replace in wren. 2017-03-07 21:15:06 -05:00
860e596b8a Test wrenSetSlotNull(). 2017-03-03 07:57:50 -08:00
f5d9443d0a Added Sequence.take and Sequence.skip
These lazy iterator producing methods are useful when working with
arbitrary sequences and you need to skip or take some number of elements
at the start.
2017-02-10 21:43:59 +01:00
3faec25c4c Merge branch 'num-features' of https://github.com/underscorediscovery/wren into underscorediscovery-num-features 2017-01-20 07:20:55 -08:00
c6eb0be990 Remove the negative number tests for bitwise not.
They were inadvertently relying on undefined behavior in C and we get
different results on some compilers.

Until we decide how we want the operation to behave, for now, just
leave it unspecified.
2017-01-12 22:17:33 -08:00
5ddd783ff5 Use strtoll() for hex literals to handle 64-bit ones even on 32-bit. 2017-01-12 21:53:21 -08:00
e8dfb1bf10 Don't test bitwise operations on operands that don't fit in u32.
The current behavior is undefined in C when converting the double to a
u32, so the tests fail on some compilers. For now, I'm just removing
those parts of the tests because I'm not sure what I want the behavior
to be. Modulo? Truncate? Runtime error?
2017-01-12 21:32:50 -08:00
04a7c9b5c8 Improve Travis Build & Test Coverage
Build Wren for more targets, and run the test suite on both 32 and 64
bit builds.

 * Update the build config to test both with and without NAN_TAGGING
   defined.

 * Updatest `util/test.py` to take the executable suffix as a
   parameter. This allows the makefile to control which binaries will be
   tested.

   Adds a new target to the makefile to be run by travis, this runs the
   test suite against all of the configurations it builds.

 * Gcc on some 32 bit platforms was complaining about numeric overflows
   when -INFINITY was used. Update the logic for converting a double to
   a string to not explicitly check against the literal values.

 * Make CI builds run the tests on both 64 _and_ 32 bit builds.

 * If I limit the number of CPUs on my MBP I can get some of the tests
   to time out, I'm imagining that the specs of the Travis Macs means
   that the same is happening there too. Updated the test script to
   allow an extra few seconds for the test to complete successfully
   before killing it.

 * Due to slight differences in accuracy in some computations tests were
   failing on 32 bit builds. Stop comparing things quite as exactly in
   the cases where it is causing issues.

   For some reason 12.34 was refusing to compare equal to itself. Bad
   show 12.34 :-/. I've also updated the test so it doesn't leak handles
   even if the assertions fail.

 * Double-cast from `double` to `uint32_t` to prevent undefined
   behaviour on overflow of basic integers. This should hopefully
   prevent 32 bit test failures on Linux.

 * Move to a version of LibUV with a fix for the 32 bit build error on
   Travis.
2016-12-29 17:52:38 +00:00
b9f53f71fb Reset API stack a fiber is aborted from wrenCall(). 2016-11-01 08:40:16 -07:00
a2868913c5 Add .log to Num 2016-10-31 17:22:32 -02:30
955e92761d Add .pow(_) to Num 2016-10-31 17:22:13 -02:30
57f34fab95 Fix assignment test. 2016-10-08 10:51:19 -07:00
e7cabbb5e4 Reset the API stack after a foreign constructor returns. 2016-08-28 08:23:27 -07:00
09ef904d32 Use DBL_MIN instead of DBL_EPSILON for Num.smallest. 2016-08-27 17:25:32 -07:00
febb1b0437 Use a map to check for constant collisions.
Doing an O(n) lookup was too slow.
2016-08-16 07:43:34 -07:00
3666eae013 Tweak new list constructors.
- Remove List.new(_). I was convinced by the issue discussion that
  using it is probably a bad idea. We don't want to encourage more nulls
  in the world than there are already are. So let's see if we can live
  without it and just have List.filled(). That way users think about
  what they're creating a list *of*.
- Added some more tests.
- Correctly handle being given a negative size.
2016-08-03 22:42:31 -07:00
3de394e8a1 Merge branch 'new-list-constructors' of https://github.com/mooxen/wren into mooxen-new-list-constructors 2016-08-03 22:34:08 -07:00
6845328661 Tweak String.indexOf(_,_) a bit.
- Simplify the arithmetic a little in wrenStringFind().
- Allow the start to be negative.
- Even more tests.
- Docs.
2016-08-03 22:19:34 -07:00
e5dce527ac Merge branch 'string-indexof-startindex' of https://github.com/underscorediscovery/wren into underscorediscovery-string-indexof-startindex 2016-08-03 21:51:46 -07:00