Commit Graph
202 Commits
Author SHA1 Message Date
Bob Nystrom c6148f8941 Make Stat a foreign class.
Instead of copying the uv_fs_stat struct to a list of Wren numbers, we
store it directly in the Stat object. This is important because we'll
need to implement later methods like isDirectory() in C so we can use
S_ISDIR(). For that, we need to have access to the original stat data.
2016-02-21 11:34:10 -08:00
Bob Nystrom ff96a179ac Include stdio.h when debugging is enabled. 2016-02-20 13:36:22 -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 edbffc9a95 Simplify method() and defineMethod().
Passing along a Variable lets us get rid of some duplicate code around
loading the class.
2016-02-12 07:43:44 -08:00
Bob Nystrom 68f801a525 Unnecessary strncmp -> memcmp. 2016-02-12 07:27:42 -08:00
Bob Nystrom 5b5c258f55 Make a little Variable struct.
Gets rid of the slightly ugly loadInstruction output parameter that
gets passed around. Now a reference to a variable is a first-class
concept in the compiler.
2016-02-12 07:16:41 -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 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 a09892de32 Use a fiber for a finalizer's foreign stack. 2015-12-27 21:43:08 -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 5b90896fa8 Print object type for unknown object error.
Thanks, Michel!
2015-12-26 20:15:00 -08:00
Bob Nystrom a5dc5e8390 Sort cases alphabetically.
Thanks, Michel!
2015-12-26 20:13:39 -08:00
Bob Nystrom 4ad4953196 Fix typo.
Thanks, Michel!
2015-12-26 20:12:35 -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 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