1
0
forked from Mirror/wren
Commit Graph

56 Commits

Author SHA1 Message Date
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
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
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
6bd2f810e2 [0.4.0] Introduce WrenLoadModuleResult, fix unfreed strings from host. (#778) 2020-12-03 09:27:54 -08: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
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
d585a080e8 Merge pull request #751 from wren-lang/0.3.0-refactor
0.3.0 refactor
2020-06-05 14:57:20 -07:00
f91586a71a Fix wrenAbortFiber does not work inside of foreign class allocator 2019-09-17 19:43:53 +02: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
e47f17567e Fix a couple more casts needed in C++. 2018-07-24 07:27:18 -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
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
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
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
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
860e596b8a Test wrenSetSlotNull(). 2017-03-03 07:57: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
e7cabbb5e4 Reset the API stack after a foreign constructor returns. 2016-08-28 08:23:27 -07:00
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
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
59e9eb127e Add wrenAbortFiber().
Thanks, @underscorediscovery!
2016-06-09 19:14:21 -07:00
0a060a9678 WrenValue -> WrenHandle. 2016-05-20 20:55:28 -07:00
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
2ce5913501 Correctly count subscript parameters in wrenMakeCallHandle().
Fixes #351.
2016-05-04 06:29:44 -07:00
84bcb5801c Add a test for creating a VM without a config. 2016-03-03 14:31:47 -08:00
ef3aa07d84 Add API to get the type of object in a slot. 2016-02-19 07:18:00 -08:00
fde6cfc142 Generate wrenAllocateForeign() to match the other setSlot methods.
Thanks, Michel!
2016-01-24 09:25:04 -08:00
2c31985e54 Make Directory.list() create and return a list from C. 2015-12-29 08:37:47 -08:00
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
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
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
1d16e85a85 Add an API to load a top-level variable into a slot. 2015-12-26 10:53:14 -08:00
15043b897f Add a benchmark for wrenCall(). 2015-12-23 17:29:53 -08:00
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
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
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
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
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
720c03cf49 Add System.gc(). 2015-10-24 10:56:27 -07:00
79354f5a97 Do some work on wrenCall().
- Add an explicit va_list version. That lets variadic functions
  forward to it.
- Fix a GC bug in wrenCall() with return values.
- Make the call API test not re-enter the VM.
2015-09-29 19:29:10 -07:00
f757c9efac Better embedding API support (and tests!) for strings with null bytes.
- Test that a foreign method can return strings.
- Test that a foreign method can return a string with null bytes.
- Test wrenCall().
- Allow passing NULL for "v" to wrenCall().
- Allow "a" for passing an explicit length byte array to wrenCall().
2015-09-24 08:02:31 -07:00
58e4d26648 "IO" -> "System".
Get rid of the separate opt-in IO class and replace it with a core
System class.

- Remove wren_io.c, wren_io.h, and io.wren.
- Remove the flags that disable it.
- Remove the overloads for print() with different arity. (It was an
  experiment, but I don't think it's that useful.)
- Remove IO.read(). That will reappear using libuv in the CLI at some
  point.
- Remove IO.time. Doesn't seem to have been used.
- Update all of the tests, docs, etc.

I'm sorry for all the breakage this causes, but I think "System" is a
better name for this class (it makes it natural to add things like
"System.gc()") and frees up "IO" for referring to the CLI's IO module.
2015-09-15 07:46:09 -07:00
66b89a493f Combine io.c and vm.c.
(This is mainly to free up io.c as a built in module.)
2015-09-13 22:29:47 -07:00
2e83f056c1 No more default constructors.
Fixes #296.
2015-09-01 08:16:04 -07:00