Commit Graph

40 Commits

Author SHA1 Message Date
37800d441c Merge branch 'master' into unify-modules-and-classes
# Conflicts:
#	src/module/io.wren
#	src/module/io.wren.inc
#	test/api/call.wren
#	test/api/returns.wren
2016-01-01 11:49:00 -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
c472a61bff Inherit methods from enclosing classes.
Like NewtonScript, the inner classes superclasses take precedence, but
if not found there then the enclosing classes are searched.

This code is still a bit hacky in some corners, but it's a step in the
right direction.
2015-12-21 17:05:46 -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
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
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
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
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
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
49601e67c5 Don't require nonstandard __builtin_unreachable() in UNREACHABLE().
Fix #304 (I hope).
2015-10-16 21:51:30 -07:00
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
06a4e00f31 Store the module debug path in the ObjModule.
Thanks, Michel!
2015-10-14 07:37:13 -07:00
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
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
d61d7fd5b4 Don't pass fiber explicitly to primitives.
Thanks, Michel!
2015-10-02 07:51:12 -07:00
5129597c63 Unify PRIM_ERROR and PRIM_RUN_FIBER. 2015-09-30 07:32:39 -07:00
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
783a5b750a Get ranges working in string subscripts (again).
Now with UTF-8 hotness!
2015-09-01 22:14:55 -07:00
48bdbc7745 First pass at implementing foreign classes.
Most of the pieces are there:

- You can declare a foreign class.
- It will call your C function to provide an allocator function.
- Whenever a foreign object is created, it calls the allocator.
- Foreign methods can access the foreign bytes of an object.
- Most of the runtime checking is in place for things like subclassing
  foreign classes.

There is still some loose ends to tie up:

- Finalizers are not called.
- Some of the error-handling could be better.
- The GC doesn't track how much memory a marked foreign object uses.
2015-08-15 12:07:53 -07:00
71eda0e427 Make an inline function for getting the fn for a call frame.
Thanks, Michel!
2015-07-19 10:16:54 -07:00
e42893fe4c Clean up macros and fix non-nan-tagged and non-computed-goto modes. 2015-07-19 10:16:27 -07:00
2387d4dc31 Grow the call frame array dynamically.
Previously, fibers had a hard-coded limit to how big their stack size
is. This limit exists in two forms: the number of distinct call frames
(basically the maximum call depth), and the number of unique stack
slots.

This fixes the first half of this by dynamically allocating the call
frame array and growing it as needed. This makes new fibers smallers
since they can start with a very small array. Checking and growing as
needed doesn't noticeably regress the perf on the other benchmarks, and
it makes a new fiber benchmark about 45% faster.

The stack array is still hardcoded, but that will be in another commit.
2015-07-01 00:00:25 -07:00
7baef81a4e Clean up a bit. 2015-06-26 23:01:07 -07:00
08f0937f89 Fix NaN tagging diagrams. 2015-06-02 07:14:19 -07:00
3f06553f7f Allow fibers as map keys. 2015-05-03 11:12:17 -07:00
7d45dda383 String.fromCodePoint(). Fix #219. 2015-03-27 07:43:36 -07:00
0bd19da392 Bind C methods to Wren using foreign declarations. 2015-03-24 07:58:15 -07:00
d168eafeb6 Upvalue -> ObjUpvalue.
This is consistent with ObjModule which also is an Obj
even though it isn't first class in the language.
2015-03-22 22:31:03 -07:00
a4df577903 Get rid of some unused parameters. 2015-03-22 22:17:40 -07:00
dd4691649a Convert Compiler and ObjList to both use ValueBuffer for their arrays. 2015-03-22 12:22:47 -07:00
3445c6a2cb Finish making code for working with lists use unsigned ints. 2015-03-21 12:22:04 -07:00
98dbde5b1b Merge branch 'int-types' of git://github.com/verpeteren/wren into verpeteren-int-types 2015-03-21 08:46:01 -07:00
1b6a2684e2 Do a little clean-up/reorganization on wren_value.h. 2015-03-19 07:28:53 -07:00
be11d09bd8 Store hash code in strings.
Makes string equality and string map keys much faster.
Also did some other general string clean-up.
2015-03-18 07:09:03 -07:00
bc52292b6d Changed int-fields in ObjList to match the uint32_t-types in ObjMap
Both ObjList and ObjMap have the same fields (capacity and count). Therefor it makes sense to make them the same type.
2015-03-17 07:29:19 +01:00
cd0a0da36f Add some missing arguments. 2015-03-15 23:17:08 -07:00
9764b165b4 Try different expansion for CONST_STRING macro. 2015-03-15 23:07:20 -07:00
034ab3c2af Clean up code for creating strings in the VM. 2015-03-15 22:32:20 -07:00
287c611260 Clean up debug dump code. 2015-03-15 10:09:43 -07:00
92c17e81f6 Reorganize source files.
This makes it clear which files are part of the VM (i.e. the Wren library)
and which are part of the CLI. Makes a directory for the latter so it has
some room to grow.

This probably totally broke the VS project. If you can fix that, send me
a PR!
2015-03-14 15:00:50 -07:00