Commit Graph

735 Commits

Author SHA1 Message Date
10f149f359 Add "def" syntax sugar for named function definitions.
This is technically redundant but it makes functional/procedural code
look a *lot* more natural.
2015-12-01 08:05:46 -08:00
c3e2f17758 Allow infix () and {} to call "call" on the left-hand side.
- Allow this for both argument lists and block arguments.

- Tweak precedence to make "." higher than infix "{}" to avoid a
  class body being parsed as the superclass clause's block argument.

- Convert all uses of ".call" to use this. (There was not a single
  case in the repo that ran into the getter ambiguity.)
2015-12-01 07:49:04 -08:00
9df6aa2f8a Remove support for implicit self sends and convert everything to '@'.
This fixes the nasty case where "foo(bar)" is context-sensitive, and
generally simplifies the compiler a lot since there is a clear
distinction between lexical and dynamic scope.

Also:

- Remove the special handling of capitalized names since all names are
  lexical now.
- Allow methods to close over local variables in enclosing functions.
- Allow implicit definition of all lexical names.
2015-11-30 22:46:11 -08:00
2e425ae840 Allow "@method()" syntax for explicit self sends, like CoffeeScript. 2015-11-30 21:44:12 -08:00
2125471132 Addressing feedback
* Always include fcntl.h in io.c
* FileReqData -> FileRequestData
* Don't combine allocations
* Make output paths more consistent with the docs
2015-11-25 19:47:13 -05:00
2708b0c7ae Fix handleRequestError casting uv_fs_t::data to the wrong type 2015-11-25 12:43:50 -05:00
8d63667ce2 Store buffer info in uv_fs_t::data so we don't depend on a private libuv field for it 2015-11-25 12:43:50 -05:00
f09e75c6e8 Update Visual Studio projects so we can build again 2015-11-25 12:43:19 -05:00
69a5c1d017 Avoid empty array initializer which seems to be problematic on VC++. 2015-11-25 08:36:42 -08:00
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
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
aaab14959f Get rid of extraneous "," in module macros.
Thanks, Michel!
2015-11-10 07:13:19 -08:00
902289d7dd Document the "random" module. 2015-11-09 07:37:06 -08:00
bbd6b827b5 Fix C++ compile errors. 2015-11-04 07:07:33 -08:00
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
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
720c03cf49 Add System.gc(). 2015-10-24 10:56:27 -07:00
f145662158 "Auxiliary" -> "optional".
Fixes #309.
2015-10-24 09:23:25 -07:00
30e7d9e508 Move core.wren to be next to wren_core.wren.inc. 2015-10-17 22:17:10 -07:00
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
3ca480cbf4 Merge branch 'master' of https://github.com/iwillspeak/wren into iwillspeak-master 2015-10-17 20:07:52 -07:00
5d6ed0958c Use explicit constant for 2**53. 2015-10-17 11:07:13 -07:00
8436ce1934 Add a random module. 2015-10-17 11:03:15 -07:00
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
49601e67c5 Don't require nonstandard __builtin_unreachable() in UNREACHABLE().
Fix #304 (I hope).
2015-10-16 21:51:30 -07:00
d431c2eaa8 Start sketching in support for reading from stdin. 2015-10-16 21:05:24 -07:00
c714c53c83 "Library" -> "module". 2015-10-15 19:38:25 -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
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
06a4e00f31 Store the module debug path in the ObjModule.
Thanks, Michel!
2015-10-14 07:37:13 -07:00
8980d34ee5 Only close an upvalue for a local if there actually is one for it. 2015-10-08 08:06:29 -07:00
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
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
b7ed774da3 Reading files!
- File.close()
- File.open()
- File.read()
- file.readBytes()

And a few other little methods. Still lots more work to do, but it's a
start.
2015-09-30 21:13:36 -07:00
bacbd85543 Add .isInfinity and .isInteger to Num. 2015-09-30 08:41:43 -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
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
f6083b1756 Simplify how built-in foreign methods and classes are wired up. 2015-09-21 07:58:39 -07:00
8ef4ea6186 Allow super calls in static methods. 2015-09-19 15:19:41 -07:00
19f70b4035 Simplify and optimize how keywords are lexed. 2015-09-17 20:51:24 -07:00
dc527c8d86 Add "io" module with beginnings of a File class. 2015-09-16 07:34:49 -07:00
251752fcfb Make join() require parentheses without a separator. 2015-09-16 07:15:48 -07:00
efceee4320 Let the host application control how System prints text. 2015-09-15 23:01:43 -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