Commit Graph
185 Commits
Author SHA1 Message Date
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 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 6f3077d582 Fix off by one error in initial stack capacity. 2015-12-16 20:55:18 -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 55beda3ea9 Simplify the foreign call preamble a bit.
We don't need to store the number of arguments since we can calculate
it from the start and top of the stack.
2015-12-15 17:10:02 -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 bcc40ab66a Clean up a few little things:
- Fix the instruction output when debug dumping code.
- Don't pass around the classCompiler since Compiler stores it.
2015-12-14 17:10:10 -08:00
Bob Nystrom e7d10218db Grow the stack as needed.
This is untuned for performance, but seems to be doing the right thing.
2015-12-14 08:00:22 -08:00
Bob Nystrom c7cd1fb1ac Track the maximum number of slots each function may use.
This is the first step towards dynamically grown stacks. We don't want
to check for stack overflow on every single push, so we store the max
number of slots a function might need and (in later patches) ensure
at function call time that that many slots are available.
2015-12-13 22:57:40 -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 0f9e2a49ce Fix "%" in error message. 2015-12-05 10:15:18 -08:00
Bob Nystrom 5bde04db4c Eagerly evaluate interpolated expressions.
If we ever support custom string templates, we'll need to go back to
compiling them to functions. But, for now, they can be evaluated
eagerly, leading to simpler code.
2015-11-23 07:08:14 -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 bbd6b827b5 Fix C++ compile errors. 2015-11-04 07:07:33 -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 25bd182c58 Fix some typos and rename some functions.
Makes the tri-color abstraction more explicit throughout the code.
2015-10-28 07:55:04 -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 720c03cf49 Add System.gc(). 2015-10-24 10:56:27 -07:00
Bob Nystrom f145662158 "Auxiliary" -> "optional".
Fixes #309.
2015-10-24 09:23:25 -07:00
Bob Nystrom 30e7d9e508 Move core.wren to be next to wren_core.wren.inc. 2015-10-17 22:17:10 -07:00
Bob Nystrom e5176607d9 Move meta and random to "aux" modules.
Wren now has three classes of modules:

- The one magic "core" module that's built in and always needed.
- Auxiliary libraries like "meta" and "random". These do not have any
  dependencies, so can be used even when you embed Wren inside an
  application. But they're also optional and can be disabled if you
  don't need them.
- CLI modules. These ones need libuv and are tied to the CLI wrapper
  around the VM.
2015-10-17 22:09:48 -07:00
Will Speak d45c0d7f82 Add Support for \U Style Unicode Escapes
This allows fuky things such as 🚀 and 😀 to be Direclty encoded in
Wren strings.
2015-10-17 10:35:46 +01:00
Bob Nystrom 49601e67c5 Don't require nonstandard __builtin_unreachable() in UNREACHABLE().
Fix #304 (I hope).
2015-10-16 21:51:30 -07:00
Bob Nystrom c714c53c83 "Library" -> "module". 2015-10-15 19:38:25 -07:00
Bob Nystrom 3b09b35b59 Get rid of source path in module.
It wasn't useful anyway since it always had the module name for all but
the main script.
2015-10-15 18:17:42 -07:00
Bob Nystrom d5b9f0096c Move Meta to a separate module.
Also cleaned up some of the code around loading the core module.
2015-10-15 18:08:56 -07:00
Bob Nystrom 06a4e00f31 Store the module debug path in the ObjModule.
Thanks, Michel!
2015-10-14 07:37:13 -07:00
Bob Nystrom 8980d34ee5 Only close an upvalue for a local if there actually is one for it. 2015-10-08 08:06:29 -07:00
Bob Nystrom 24cbb7f399 Fix closures in methods.
A local name inside a method should always resolve to a self send even
if there is a local variable with that name outside of the method.
2015-10-05 07:44:51 -07:00
Bob Nystrom 76d188e018 Get rid of PrimitiveResult.
Primitives still have a return value to indicate normal value returning
versus runtime errors or fiber switching since it minimizes branches
in the common case of a normal value result.
2015-10-03 20:43:12 -07:00
Bob Nystrom 812bc15380 Get rid of the special "call" primitive result type.
Instead, Fn.call(...) is a special *method* type that has the same
special sauce. The goal is eventually to get rid of the primitive
result type entirely.
2015-10-03 19:04:11 -07:00
Bob Nystrom d61d7fd5b4 Don't pass fiber explicitly to primitives.
Thanks, Michel!
2015-10-02 07:51:12 -07:00
Bob Nystrom bacbd85543 Add .isInfinity and .isInteger to Num. 2015-09-30 08:41:43 -07:00
Bob Nystrom 5129597c63 Unify PRIM_ERROR and PRIM_RUN_FIBER. 2015-09-30 07:32:39 -07:00
Bob Nystrom b05a74da19 Revamp how runtime errors and fiber switching is handled.
- Add Fiber.transferError(_).
- Primitives place runtime errors directly in the fiber instead of on
  the stack.
- Primitives that change fibers set it directly in the VM.
- Allow a fiber's error to be any object (except null).
2015-09-29 22:57:03 -07:00
Bob Nystrom 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
Bob Nystrom 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
Bob Nystrom 8ef4ea6186 Allow super calls in static methods. 2015-09-19 15:19:41 -07:00
Bob Nystrom 19f70b4035 Simplify and optimize how keywords are lexed. 2015-09-17 20:51:24 -07:00
Bob Nystrom 251752fcfb Make join() require parentheses without a separator. 2015-09-16 07:15:48 -07:00
Bob Nystrom efceee4320 Let the host application control how System prints text. 2015-09-15 23:01:43 -07:00
Bob Nystrom 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
Bob Nystrom f36a795534 Automatically update the string constants when a builtin module changes. 2015-09-13 10:03:02 -07:00
Bob Nystrom 1a27593993 Error if a class tries to inherit from null.
Fix #246.
2015-09-12 10:14:04 -07:00