Commit Graph

484 Commits

Author SHA1 Message Date
Bob Nystrom
8963a870ff Abort all fibers along a call chain when one aborts. 2017-10-06 07:39:00 -07:00
Bob Nystrom
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
Kyle Charters
84f2252c68 Add Num .round 2017-09-20 20:27:02 -04:00
Bob Nystrom
d390e16a99 Kill duplicate test.
Fix #438.
2017-04-08 12:53:33 -07:00
Andew Jones
7d631276cb Catch errors in the first try() 2017-03-30 21:57:29 -04:00
Bob Nystrom
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
Bob Nystrom
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
Bob Nystrom
8d313be3ce Make it an error to skip or take a negative count. 2017-03-15 07:22:44 -07:00
Bob Nystrom
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
Bob Nystrom
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
Andew Jones
32aa43d1df Split and replace in wren. 2017-03-07 21:15:06 -05:00
Bob Nystrom
860e596b8a Test wrenSetSlotNull(). 2017-03-03 07:57:50 -08:00
Thorbjørn Lindeijer
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
Bob Nystrom
3faec25c4c Merge branch 'num-features' of https://github.com/underscorediscovery/wren into underscorediscovery-num-features 2017-01-20 07:20:55 -08:00
Bob Nystrom
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
Bob Nystrom
5ddd783ff5 Use strtoll() for hex literals to handle 64-bit ones even on 32-bit. 2017-01-12 21:53:21 -08:00
Bob Nystrom
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
Will Speak
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
Bob Nystrom
b9f53f71fb Reset API stack a fiber is aborted from wrenCall(). 2016-11-01 08:40:16 -07:00
underscorediscovery
a2868913c5 Add .log to Num 2016-10-31 17:22:32 -02:30
underscorediscovery
955e92761d Add .pow(_) to Num 2016-10-31 17:22:13 -02:30
Bob Nystrom
57f34fab95 Fix assignment test. 2016-10-08 10:51:19 -07:00
Bob Nystrom
e7cabbb5e4 Reset the API stack after a foreign constructor returns. 2016-08-28 08:23:27 -07:00
Bob Nystrom
09ef904d32 Use DBL_MIN instead of DBL_EPSILON for Num.smallest. 2016-08-27 17:25:32 -07:00
Bob Nystrom
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
Bob Nystrom
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
Bob Nystrom
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
Bob Nystrom
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
Bob Nystrom
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
Bob Nystrom
60a0353a27 Tweak list C API:
- Rename "size" -> "count" to be consistent with other usage.
- Remove "Slot" from the function names, since that's implicit.
- Make the getListElement() just move the element to another slot. This
  matches other APIs where we distinguish accessing a value and
  converting it to some specific type.
2016-07-28 08:06:36 -07:00
Bob Nystrom
b8675e2d91 Merge branch 'get_slot_list_values' of https://github.com/dradtke/wren into dradtke-get_slot_list_values 2016-07-28 07:53:19 -07:00
root
244faa5700 renamed filler constructor in list to match issue 2016-07-17 12:24:19 +10:00
root
45d9794476 added extra arguments to list constructors for default size/ value 2016-07-17 12:01:50 +10:00
underscorediscovery
1f84a10f44 Implement String indexOf(needle, startIndex) 2016-07-14 01:23:01 -02:30
Bob Nystrom
5418e4f8f3 Add MapEntry to core to let maps be directly iterated.
Fix #372.
2016-07-06 07:17:07 -07:00
Bob Nystrom
4e94195f26 Properly handle tombstones when inserting items into a map.
Previously, you could get into a state where a key was present in the
map, but after a tombstone in the probe sequence. If they key was added
again, it stopped at the first tombstone and added it there, resulting
in the key being in the map multiple times.

Fix #373.
2016-06-27 07:14:52 -07:00
Bob Nystrom
f47e128978 Tab-completion in REPL based on module variables. 2016-06-09 19:16:41 -07:00
Bob Nystrom
bc7f1de758 Execute input in the REPL.
Guesses whether the input is an expression or statement and handles it
appropriately. Finally, after over a year, the Wren REPL automatically
prints "3" if you type in "1 + 2". \o/
2016-06-09 19:16:41 -07:00
Bob Nystrom
59e9eb127e Add wrenAbortFiber().
Thanks, @underscorediscovery!
2016-06-09 19:14:21 -07:00
Bob Nystrom
2b0878ec6d Platform.isWindows. 2016-05-21 12:53:21 -07:00
Bob Nystrom
6002cc4d65 Add Stdin.isTerminal. 2016-05-21 12:51:11 -07:00
Bob Nystrom
06731f66d4 Add a Platform class.
- Rename the "process" module to "os".
- Add Platform to it.
- Static "name" method.
- Static "isPosix" method.
- Docs and tests!
2016-05-21 12:44:17 -07:00
Bob Nystrom
0a060a9678 WrenValue -> WrenHandle. 2016-05-20 20:55:28 -07:00
Bob Nystrom
5d98d20175 Add Stdin.isRaw. 2016-05-20 15:19:18 -07:00
Bob Nystrom
500dd41ccd Add Stdin.readByte(). 2016-05-20 11:50:14 -07:00
Damien Radtke
cf258b9074 Add support for retrieving list values from a slot
This PR adds support for retrieving list information from a slot. Rather
than take the whole list, two different methods are provided for
retrieving a) the length of the list, and b) a specific value in the
list.
2016-05-19 14:11:48 -05:00
Bob Nystrom
2ce5913501 Correctly count subscript parameters in wrenMakeCallHandle().
Fixes #351.
2016-05-04 06:29:44 -07:00
Bob Nystrom
694186810b Test that multiple closures of the same code are unequal. 2016-03-26 14:22:38 -07:00
Bob Nystrom
a6739819b2 Report undefined variable errors on the line where they are used.
This also more importantly ensures the error message for one has a
bounded length even if the variable name is pathologically long.
2016-03-16 08:00:28 -07:00
Bob Nystrom
38699e3a81 Rearrange the code a bit for duplicate method detections. 2016-03-15 07:15:55 -07:00
Stephen Belanger
6dfbea1ea4 Don't use generic function for finding method duplicates and add tests 2016-03-12 19:14:19 -08:00
Bob Nystrom
9fda7cb526 Unify Fiber.try() with the other methods to execute fibers. 2016-03-03 17:00:33 -08:00
Bob Nystrom
84bcb5801c Add a test for creating a VM without a config. 2016-03-03 14:31:47 -08:00
Bob Nystrom
1e4b9e5175 File.realPath().
Not tested yet, because we can't create symlinks from Wren and I don't
want to check symlinks into the repo, but it seems to do the right
thing.
2016-02-27 15:53:02 -08:00
Bob Nystrom
d46dfc9500 Allow "*" on lists and strings to repeat them.
This is not implemented on Sequence because, at least for lists and
strings, I think users expect an eager result. Multiplying a string
should give you back a string, not a lazy sequence of repeated
characters.

This also mirrors "+" on strings and lists, which is eager. I like the
idea of having a general guideline that operators are eager.

Repetition is useful for arbitrary sequences, but for that maybe we
should add a "repeat()" method.
2016-02-24 07:48:03 -08:00
Bob Nystrom
60162575ee More file system checking functions:
- Stat#isFile
- Stat#isDirectory
- Directory.exists()
- File.exists()
2016-02-21 12:23:33 -08:00
Bob Nystrom
b331915259 Add stat instance method to File. 2016-02-21 10:18:45 -08:00
Bob Nystrom
8e90e3577b More file IO!
Can now create, delete, and write to files.
2016-02-20 09:23:42 -08:00
Bob Nystrom
ef3aa07d84 Add API to get the type of object in a slot. 2016-02-19 07:18:00 -08:00
Bob Nystrom
fa0a507b48 Error on jump distance overflow. 2016-02-19 06:57:38 -08:00
Bob Nystrom
b8e85c83a8 Fix test and add skynet example. 2016-02-14 22:21:50 -08:00
Bob Nystrom
8b36e2f00b Add sample(_) and sample(_,_) to Random. 2016-02-09 07:24:45 -08:00
Bob Nystrom
d4a4b26203 Add Random.shuffle(). 2016-02-07 10:38:39 -08:00
Bob Nystrom
79558d95e5 Move File.stat() -> Stat.path().
Thanks, Michel!
2016-02-07 09:56:16 -08:00
Bob Nystrom
fde6cfc142 Generate wrenAllocateForeign() to match the other setSlot methods.
Thanks, Michel!
2016-01-24 09:25:04 -08:00
Bob Nystrom
71e2458a6c Add API for accessing command-line arguments.
- Add process module with Process class.
- Add "arguments" and "allArguments" methods.
- Docs for same.
- Support passing additional arguments to command line.
- Add "--help" support to command line.
2016-01-22 07:57:26 -08:00
Bob Nystrom
f9d1e9954a Make File.stat() directory test less file system sensitive. 2016-01-05 07:32:51 -08:00
Bob Nystrom
94208647ab Test File.stat() on a directory. 2016-01-01 10:05:31 -08:00
Bob Nystrom
5cd8a06fa0 File.stat(). 2016-01-01 09:58:44 -08:00
Bob Nystrom
b054526df8 Add an optional offset to File.readBytes(). 2015-12-30 08:13:19 -08:00
Bob Nystrom
2c31985e54 Make Directory.list() create and return a list from C. 2015-12-29 08:37:47 -08:00
Bob Nystrom
e0ac88c22a Revamp wrenCall to work with slots.
Now, you call wrenEnsureSlots() and then wrenSetSlot___() to set up the
receiver and arguments before the call. Then wrenCall() is passed a
handle to the stub function that makes the call. After that, you can
get the result using wrenGetSlot___().

This is a little more verbose to use, but it's more flexible, simpler,
and much faster in the VM. The call benchmark is 185% of the previous
speed.
2015-12-29 07:58:47 -08:00
Bob Nystrom
ed6fad6153 Get rid of fiber for finalizers.
Instead, finalizers just get access to the foreign object's raw bytes.
This is deliberately limiting, since it discourages the user from
interacting with the VM in the middle of a GC.
2015-12-28 08:06:29 -08:00
Bob Nystrom
a447b66380 Make slots available to the API outside of foreign methods.
At any point in time, the user can call wrenEnsureSlots() which will
implicitly create a fiber and point to its stack if needed.
2015-12-28 07:49:47 -08:00
Bob Nystrom
9512ce74c3 Merge branch 'master' into api
# Conflicts:
#	src/module/io.c
2015-12-26 20:42:53 -08:00
Bob Nystrom
1d16e85a85 Add an API to load a top-level variable into a slot. 2015-12-26 10:53:14 -08:00
Bob Nystrom
0ac793d4f8 Add Directory.list() to io. 2015-12-24 10:12:12 -08:00
Bob Nystrom
15043b897f Add a benchmark for wrenCall(). 2015-12-23 17:29:53 -08:00
Bob Nystrom
b7e62926ab Merge branch 'master' into api 2015-12-23 09:22:49 -08:00
Bob Nystrom
1ebc711c30 Allow call and unary expressions as map keys. 2015-12-22 16:00:50 -08:00
Bob Nystrom
6f37d379f4 Add C API functions for working with lists:
- wrenEnsureSlots()
  Lets you go the foreign slot stack to make room for a temporary work
  area.

- wrenSetSlotNewList()
  Creates a new empty list and stores it in a slot.

- wrenInsertInList()
  Takes a value from one slot and inserts it into the list in another.

Still need more functions like getting elements from a list, removing,
etc. but this at least lets you create, populate, and return lists from
foreign methods.
2015-12-16 16:28:26 -08:00
Bob Nystrom
7fcdcf2f1a wrenReturn___() -> wrenSlotSet___().
This turns those functions into general-purpose functions for writing
raw C values into slots on the foreign call stack.

Writing a return just means writing a value to slot 0.
2015-12-16 13:00:13 -08:00
Bob Nystrom
4b3c818ec5 Start moving embedding API towards "slot" register-API.
- wrenGetArgumentCount() -> wrenGetSlotCount()
- wrenGetArgument___() -> wrenGetSlot___()

Also, the get functions assert that the value is the right type instead
of checking at runtime. This puts the onus on the caller to be safe,
but maximizes performance.
2015-12-16 10:22:42 -08:00
Bob Nystrom
01e8f9053e Add a benchmark to test the Wren C API.
I've got some ideas on how to tweak the embedding API, but I want to
see what performance impact they have first, so this adds a little
benchmark that just calls a foreign method a ton of times.
2015-12-15 16:02:13 -08:00
Bob Nystrom
873926915f Don't allow fibers as map keys.
I hacked in support for it for a misguided reason (trying to fake
"thread-local storage") and ended up not using it for that anyway.
2015-12-15 10:42:21 -08:00
Bob Nystrom
8d9feb4bc9 Fix typo in benchmark. 2015-12-15 10:37:53 -08:00
Bob Nystrom
2df5362ab2 Handle compile errors in imported modules. 2015-12-08 07:49:37 -08:00
Bob Nystrom
bfa86b259a Ignore newlines in imports. 2015-12-07 19:41:10 -08:00
Bob Nystrom
6ff5fb9ff2 Allow empty ranges at the end of a sequence. 2015-12-06 10:37:58 -08:00
Bob Nystrom
10ece995f7 Add some Dart benchmarks running on fletch. 2015-12-05 11:09:30 -08:00
Bob Nystrom
37b70db1b0 Make delta_blue more idiomatic Wren. 2015-11-30 20:58:08 -08:00
Bob Nystrom
78655c68b0 Simple string interpolation.
This allows "%(...)" inside a string literal to interpolate the
stringified result of an expression.

It doesn't support custom interpolators or format strings, but we can
consider extending that later.
2015-11-11 07:55:48 -08:00
Bob Nystrom
7ae9888c4f It turns out "is" is just a normal overridable operator. Who knew? 2015-11-07 13:00:24 -08:00
Bob Nystrom
2ff8acbe1a Tweak a few things in the new GC.
- Make sure it handles an empty gray set.
- Make sure growing the gray stack doesn't itself trigger a GC.
- Make sure it works when stress testing is enabled.
- Ensure the tests kick off a GC.
2015-10-29 07:38:09 -07:00
Bob Nystrom
e3c9324dd9 Merge branch 'master' into iwillspeak-iterative-gc 2015-10-28 07:46:06 -07:00
Bob Nystrom
e985e6fe07 Make sure binary_trees_gc actually stresses GC. 2015-10-28 07:45:52 -07:00
Will Speak
cea71c2fe4 Remove Recursive Mark from GC
The previous GC implementation used a recursive mark method. This can
result in stack overflows when attempting to mark deeply nested objects.

This commit replaces the recursive approach with an iteritive one,
moving the state stack from the C call stack to the `WrenVM` structure.

As objects are 'grayed' they are pushed onto the VM's gray stack. When
we have grayed all of the root objects we iterate until the stack is
empty graying any obejcts which haven't been marked as dark before. At
the end of the process we clean up all unmarked objects as before.

This commit also adds a few new tests which check garbage collection by
allocating some new deeply nested objects and triggering the GC a few
times in the process.
2015-10-25 09:02:57 +00:00
Bob Nystrom
b365c07d7a Add a benchmark that explicitly invokes the GC. 2015-10-24 11:00:17 -07:00
Bob Nystrom
720c03cf49 Add System.gc(). 2015-10-24 10:56:27 -07:00
Bob Nystrom
3ca480cbf4 Merge branch 'master' of https://github.com/iwillspeak/wren into iwillspeak-master 2015-10-17 20:07:52 -07:00