Commit Graph
100 Commits
Author SHA1 Message Date
Bob Nystrom 22a95265f2 Simplify the formatting used to print compile errors.
Avoids using multiple calls to fprintf() to print a single compile
error. This should make it easier to allow the host to provide a
callback function to print errors.
2016-03-11 21:30:54 -08:00
Bob Nystrom 5be9377d93 Simplify shebang parsing. 2016-03-11 17:23:31 -08:00
Bob Nystrom 485e91ab05 Redo metrics script. 2016-03-07 07:56:44 -08:00
Bob Nystrom fb0e01bfe9 Fix some nits in the FAQ. 2016-03-07 07:41:00 -08:00
Bob Nystrom 139b447898 Compile functions in place instead of copying when done.
The compiler used to maintain all of the data that defines a function,
which it incrementally built up. Then, when it was done, it copied all
of that to a new ObjFn. In theory, that was to trim down some memory
and avoid unneeded fields in ObjFn.

In practice, the performance benefit is negligible and the memory saving
is nullified by the fact that it copies anyway.

This moves all of that mutable state directly into ObjFn. The compiler
creates a new empty ObjFn at the beginning and then just fills it in
in place.

This shaves off about 40 lines of code, is simpler, and doesn't seem to
impact perf.
2016-03-04 07:49:34 -08:00
Bob Nystrom f2f779d3b8 Fix bug with the compiler root not being popped. 2016-03-03 17:48:47 -08:00
Bob Nystrom a3505fa060 Simplify runtime error reporting. 2016-03-03 17:11:52 -08:00
Bob Nystrom 9fda7cb526 Unify Fiber.try() with the other methods to execute fibers. 2016-03-03 17:00:33 -08:00
Bob Nystrom d717ddf817 Simplify how assignment expressions are compiled. 2016-03-03 16:30:48 -08:00
Bob Nystrom 84bcb5801c Add a test for creating a VM without a config. 2016-03-03 14:31:47 -08:00
Bob Nystrom 223d66a01c I can spell gooder. 2016-02-27 16:23:48 -08:00
Bob Nystrom 0a83697bd4 Minor janitorial work. 2016-02-27 16:05:50 -08:00
Bob Nystrom 1e4b9e5175 File.realPath().
Not tested yet, because we can't create symlinks from Wren and I don't
want to check symlinks into the repo, but it seems to do the right
thing.
2016-02-27 15:53:02 -08:00
Bob Nystrom e6b48de598 Fix precedence table in docs.
It was out of sync with the actual implemented precedence in a few
places.
2016-02-27 10:14:09 -08:00
Bob Nystrom fa2598c601 Upgrade to libuv 1.8.0. 2016-02-27 09:19:56 -08:00
Bob Nystrom b7e189fe11 Desugar import statements to core library calls.
This is simpler than having special opcodes for them. It's also a bit
faster, and gets some non-critical code out of the interpreter loop.

Also, this is good prep work for being able to write some of the module
loading process in Wren to make things more flexible for embedders and
the CLI.
2016-02-26 22:43:54 -08:00
Bob Nystrom edca85827a Combine block() and statement().
The separation between the two didn't really do anything useful.
2016-02-25 07:04:48 -08:00
Bob Nystrom d46dfc9500 Allow "*" on lists and strings to repeat them.
This is not implemented on Sequence because, at least for lists and
strings, I think users expect an eager result. Multiplying a string
should give you back a string, not a lazy sequence of repeated
characters.

This also mirrors "+" on strings and lists, which is eager. I like the
idea of having a general guideline that operators are eager.

Repetition is useful for arbitrary sequences, but for that maybe we
should add a "repeat()" method.
2016-02-24 07:48:03 -08:00
Bob Nystrom 919605b7ba Couple of tiny tweaks. 2016-02-24 06:52:12 -08:00
Bob Nystrom 2c4e497c54 Fix a couple of doc bugs. 2016-02-22 07:48:53 -08:00
Bob Nystrom 60162575ee More file system checking functions:
- Stat#isFile
- Stat#isDirectory
- Directory.exists()
- File.exists()
2016-02-21 12:23:33 -08:00
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 b331915259 Add stat instance method to File. 2016-02-21 10:18:45 -08:00
Bob Nystrom 3101d9c499 Fix file flags to be OS-independent. 2016-02-20 17:25:41 -08:00
Bob Nystrom ff96a179ac Include stdio.h when debugging is enabled. 2016-02-20 13:36:22 -08:00
Bob Nystrom 8e90e3577b More file IO!
Can now create, delete, and write to files.
2016-02-20 09:23:42 -08:00
Bob Nystrom bec5181bdb Add separate targets for building just the shared or static library.
make static
make shared

Running "make vm" will build both, as usual.

Fixes #322.
2016-02-19 07:22:10 -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 5b7cd12e76 Don't run the skynet example from the tests.
It's too slow on the Travis bots and times out.
2016-02-14 22:28:14 -08:00
Bob Nystrom b8e85c83a8 Fix test and add skynet example. 2016-02-14 22:21:50 -08:00
Bob Nystrom d823896136 Merge branch 'master' of https://github.com/munificent/wren 2016-02-14 22:18:53 -08:00
Bob Nystrom 1a6d3703d2 Merge pull request #320 from 4d47/small-doc-update
Fix two small code samples in doc
2016-02-12 10:35:40 -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 68ab4e88c0 Merge branch 'master' of https://github.com/munificent/wren 2016-02-09 07:24:55 -08:00
Bob Nystrom 8b36e2f00b Add sample(_) and sample(_,_) to Random. 2016-02-09 07:24:45 -08:00
Bob Nystrom 895136b78c Merge pull request #319 from 4d47/small-doc-update
Update wrenInterpret doc/site/embedding-api
2016-02-08 17:43:05 -08:00
Bob Nystrom d4a4b26203 Add Random.shuffle(). 2016-02-07 10:38:39 -08:00
Bob Nystrom 79558d95e5 Move File.stat() -> Stat.path().
Thanks, Michel!
2016-02-07 09:56:16 -08:00
Bob Nystrom ffb5ada9fb Move the community docs to the wiki. 2016-01-24 15:39:35 -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 71e2458a6c Add API for accessing command-line arguments.
- Add process module with Process class.
- Add "arguments" and "allArguments" methods.
- Docs for same.
- Support passing additional arguments to command line.
- Add "--help" support to command line.
2016-01-22 07:57:26 -08:00
Bob Nystrom 860220869a Oops. Completely disable lto. 2016-01-22 07:01:56 -08:00
Bob Nystrom f19888d328 Merge branch 'master' of https://github.com/munificent/wren 2016-01-22 06:42:16 -08:00
Bob Nystrom 7e8bc2a89a Disable link-time-optimization for now.
It's failing when building with clang on Travis. The underlying problem
seems to be something broken with how LLVM is looking for the gold
linker, and working around that is outside of my skillset.

To learn more, Google: "LLVMgold.so: error loading plugin" lto
2016-01-22 06:42:01 -08:00
Bob Nystrom 056ae61493 Tweak some docs. 2016-01-21 21:38:27 -08:00
Bob Nystrom 46a03e3a2d Merge pull request #318 from pra85/patch-1
Update license year range to 2016
2016-01-21 15:20:58 -08:00
Bob Nystrom 39b29ee07a Enable link time optimization in the CLI.
One little compiler flag makes a surprisingly large difference:

api_call - wren            0.05s 0.0017 130.52% relative to baseline
api_foreign_method - wren  0.24s 0.0017 144.54% relative to baseline
binary_trees - wren        0.21s 0.0032 112.27% relative to baseline
binary_trees_gc - wren     0.75s 0.0288 115.02% relative to baseline
delta_blue - wren          0.13s 0.0031 103.24% relative to baseline
fib - wren                 0.20s 0.0036 120.56% relative to baseline
fibers - wren              0.04s 0.0007 108.52% relative to baseline
for - wren                 0.07s 0.0009 124.45% relative to baseline
method_call - wren         0.12s 0.0010  95.58% relative to baseline
map_numeric - wren         0.30s 0.0031 110.11% relative to baseline
map_string - wren          0.11s 0.0098 111.38% relative to baseline
string_equals - wren       0.19s 0.0064 115.49% relative to baseline
2016-01-20 07:47:00 -08:00
Bob Nystrom f9d1e9954a Make File.stat() directory test less file system sensitive. 2016-01-05 07:32:51 -08:00
Bob Nystrom 94208647ab Test File.stat() on a directory. 2016-01-01 10:05:31 -08:00
Bob Nystrom 5cd8a06fa0 File.stat(). 2016-01-01 09:58:44 -08:00
Bob Nystrom b054526df8 Add an optional offset to File.readBytes(). 2015-12-30 08:13:19 -08:00
Bob Nystrom 6e2ec92e0d Fix parameter format in docs. 2015-12-29 22:35:14 -08:00
Bob Nystrom 452cc88082 Fix a few typos in the docs. 2015-12-29 22:29:13 -08:00
Bob Nystrom 8854dfb07e Docs for the io module! 2015-12-29 21:56:44 -08:00
Bob Nystrom 678251a00c Fix type for fileFinalizer(). 2015-12-29 21:07:26 -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 fbc76cdc05 Fix C++ compile error in Directory.list(). 2015-12-26 20:26:05 -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 8ab329ff91 Make wren.mk log wren_to_c_string.
Thanks, Michel!
2015-12-26 20:11:48 -08:00
Bob Nystrom 8203baf7bd Initialize match in the test script.
Thanks, Michel!
2015-12-26 20:08:20 -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 0ac793d4f8 Add Directory.list() to io. 2015-12-24 10:12:12 -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 910049cd19 Update the docs around slots. 2015-12-16 16:39:27 -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 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
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 8d9feb4bc9 Fix typo in benchmark. 2015-12-15 10:37:53 -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 10ece995f7 Add some Dart benchmarks running on fletch. 2015-12-05 11:09:30 -08:00
Bob Nystrom 0f9e2a49ce Fix "%" in error message. 2015-12-05 10:15:18 -08:00
Bob Nystrom 37b70db1b0 Make delta_blue more idiomatic Wren. 2015-11-30 20:58:08 -08:00
Bob Nystrom a38753d1d6 Add an animals guessing game example. 2015-11-29 09:43:47 -08:00
Bob Nystrom c46507d937 Fix .gitignore (and add incorrectly ignored file!) 2015-11-27 11:22:09 -08:00
Bob Nystrom 5454152dff Merge pull request #313 from acook/patch-1
Fixing a couple of typos in the classes docs.
2015-11-25 08:59:16 -08:00
Bob Nystrom 69a5c1d017 Avoid empty array initializer which seems to be problematic on VC++. 2015-11-25 08:36:42 -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 fb72e0fff7 Document method scope. 2015-11-21 14:00:21 -08:00
Bob Nystrom 03163a760f Document interpolation. 2015-11-21 09:20:50 -08:00